by version_five · 3y ago · 0 comments
But ML models generally can execute arbitrary code
Is it the case if we're only talking about weights? I thought the rest is actually "open".The usage boils down to
import safer_unpickle from safer_unpickle
safer_unpickle.patch_torch_load()
This overrides default torch unpickler with a relatively safe one. Hope this helps.
But seriously, why not something more human readable and text-based if it's just weights?
One of the reasons I'm not a huge fan of PyTorch.
It isn't like a multi gigabyte game for example, where knowing if there is any malicious code could easily be a multi-month reverse engineering project to get to the answer of 'probably not, but we don't have time to check every byte with a fine tooth comb'
Some solutions for checking: https://huggingface.co/docs/hub/security-pickle
or run them in an isolated env.
$ fickling --check-safety consolidated.00.pth
File "/usr/lib/python3.10/pickletools.py", line 359, in read_stringnl
data = codecs.escape_decode(data)[0].decode("ascii")
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 63: ordinal not in range(128)