Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyTorch 2.6.0: Weights only load failed #497

Open
hongbo-miao opened this issue Jan 31, 2025 · 3 comments
Open

PyTorch 2.6.0: Weights only load failed #497

hongbo-miao opened this issue Jan 31, 2025 · 3 comments

Comments

@hongbo-miao
Copy link
Contributor

hongbo-miao commented Jan 31, 2025

When upgrade from PyTorch 2.5.1 to 2.6.0, for code like

from ogb.graphproppred import PygGraphPropPredDataset

dataset = PygGraphPropPredDataset(name = 'ogbg-molhiv')

I got error:

Traceback (most recent call last):
  File "/home/runner/work/hongbomiao.com/hongbomiao.com/machine-learning/graph-neural-network/src/main.py", line 103, in main
    dataset, split_idx = fetch_dataset(config)
                         ^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/hongbomiao.com/hongbomiao.com/machine-learning/graph-neural-network/src/model/data_loader.py", line 13, in fetch_dataset
    dataset = PygGraphPropPredDataset(name=config.dataset)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/hongbomiao.com/hongbomiao.com/machine-learning/graph-neural-network/.venv/lib/python3.12/site-packages/ogb/graphproppred/dataset_pyg.py", line 68, in __init__
    self.data, self.slices = torch.load(self.processed_paths[0])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/hongbomiao.com/hongbomiao.com/machine-learning/graph-neural-network/.venv/lib/python3.12/site-packages/torch/serialization.py", line 1470, 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 torch_geometric.data.data.DataEdgeAttr was not an allowed global by default. Please use `torch.serialization.add_safe_globals([DataEdgeAttr])` or the `torch.serialization.safe_globals([DataEdgeAttr])` context manager to allowlist this global if you trust this class/function.

I am wondering if the library should handle this issue in a future version, or if we should add something like (not tested codes):

from ogb.graphproppred import PygGraphPropPredDataset
from torch_geometric.data.data import DataEdgeAttr

torch.serialization.add_safe_globals([DataEdgeAttr])
dataset = PygGraphPropPredDataset(name = 'ogbg-molhiv')

What would be the recommended approach? Thank you! ☺️

@alexbarghi-nv
Copy link

I'm having this problem too.

@EMZEDI
Copy link

EMZEDI commented Feb 16, 2025

Having the same issue. This needs to be fixed, though a workaround for now could be the following:

import torch
from torch_geometric.data.storage import GlobalStorage
from torch_geometric.data.data import DataEdgeAttr, DataTensorAttr

torch.serialization.add_safe_globals([GlobalStorage, DataEdgeAttr, DataTensorAttr])

# the rest of the code
  • It made it work for me.

rapids-bot bot pushed a commit to rapidsai/cugraph-gnn that referenced this issue Mar 5, 2025
Drops the PyTorch constraint added for OGB.  Adds workarounds for snap-stanford/ogb#497.

Merge after #151

Authors:
  - Alex Barghi (https://github.com/alexbarghi-nv)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Tingyu Wang (https://github.com/tingyu66)

URL: #153
@benjaminbuzek
Copy link

Having the same issue. This needs to be fixed, though a workaround for now could be the following:

import torch
from torch_geometric.data.storage import GlobalStorage
from torch_geometric.data.data import DataEdgeAttr, DataTensorAttr

torch.serialization.add_safe_globals([GlobalStorage, DataEdgeAttr, DataTensorAttr])

the rest of the code

  • It made it work for me.

I ran into the same issue with the version >=1.3.6 and can confirm that this resolved the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants