AStarNet icon indicating copy to clipboard operation
AStarNet copied to clipboard

AttributeError: 'Graph' object has no attribute 'is_meta'

Open anilakash opened this issue 2 years ago • 3 comments

Hi, Thanks for sharing the codes for ANet. The ANet is trained and validated successfully but an error occurred in loading the checkpoint. Here are the details:

10:02:04 Load checkpoint from model_epoch_1.pth Traceback (most recent call last): File "/home/my_project_dir/script/run.py", line 62, in train_and_validate(cfg, solver) File "/home/my_project_dir/script/run.py", line 35, in train_and_validate solver.load("model_epoch_%d.pth" % best_epoch) File "/home/akash/anaconda3/envs/astarnet_conda/lib/python3.9/site-packages/torchdrug-0.2.1-py3.9.egg/torchdrug/core/engine.py", line 242, in load self.model.load_state_dict(state["model"], strict=strict) File "/home/akash/anaconda3/envs/astarnet_conda/lib/python3.9/site-packages/torch/nn/modules/module.py", line 2138, in load_state_dict load(self, state_dict) File "/home/akash/anaconda3/envs/astarnet_conda/lib/python3.9/site-packages/torch/nn/modules/module.py", line 2120, in load module._load_from_state_dict( File "/home/akash/anaconda3/envs/astarnet_conda/lib/python3.9/site-packages/torch/nn/modules/module.py", line 2024, in _load_from_state_dict if param.is_meta and not input_param.is_meta and not assign_to_params_buffers: AttributeError: 'Graph' object has no attribute 'is_meta'

anilakash avatar Oct 19 '23 04:10 anilakash

Hi, we are so sorry for our late response.

Could you please provide the package version that you are currently using right now, especially for torch and torchdrug?

As I checked in Torch's commit history, there is at least no such constraint if param.is_meta and not input_param.is_meta and not assign_to_params_buffers: for torch==1.13.1 (which is the one I'm using right now).

The update for this constraint takes place in the following commit: https://github.com/pytorch/pytorch/commit/ca7ece9b508822defc6eaa97fc9d5adafa201f69

I guess it's worth a try to pass assign=True as torch suggested in the warning to bypass this constraint.

KatarinaYuan avatar Nov 09 '23 02:11 KatarinaYuan

Hi! Does anyone know how to resolve this issue? I am using torch=2.3.0, torchdrug=0.2.1. I tried to set assign=True as @KatarinaYuan mentioned but it didn't help.

benjaminnNgo avatar Sep 25 '24 19:09 benjaminnNgo

I tried to print out all keys and values pairs of the model state dictionary and I found these: "graph" : Graph(num_node=40943, num_edge=93003, num_relation=11, device='cuda:0') "fact_graph": Graph(num_node=40943, num_edge=86835, num_relation=11, device='cuda:0'). I am not sure if they are registered as parameters or buffers of the model intentionally and must be kept in the model state. I am not sure if I could pop this out of the model state dictionary. @KatarinaYuan @KiddoZhu

benjaminnNgo avatar Sep 25 '24 20:09 benjaminnNgo