Skip to content

Pytorch 2.6 does not allow model loading #149

@mshakirDr

Description

@mshakirDr

Any quick fixes? The version on PyPI works (downloads the model). The version on github does not even download the model (the file structure of both installations is different). Tried to apply this patch, does not work as well.

>>> from supar import Parser
>>> parser = Parser.load('biaffine-dep-en')
Downloading: https://github.com/yzhangcs/parser/releases/download/v1.1.0/ptb.biaffine.dep.lstm.char.zip to .cache/supar\ptb.biaffine.dep.lstm.char.zip
100%|███████████████████████████████████████████████████████████████████████████████| 331M/331M [01:47<00:00, 3.22MB/s]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "\lib\site-packages\supar\parsers\parser.py", line 194, in load
    state = torch.load(path if os.path.exists(path) else download(supar.MODEL[src].get(path, path), reload=reload))
  File "\lib\site-packages\torch\serialization.py", line 1529, in load
    raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.
        (1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
        (2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
        WeightsUnpickler error: Unsupported global: GLOBAL supar.utils.config.Config was not an allowed global by default. Please use `torch.serialization.add_safe_globals([supar.utils.config.Config])` or the `torch.serialization.safe_globals([supar.utils.config.Config])` context manager to allowlist this global if you trust this class/function.

Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.
>>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions