You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When you load in a saved state dict to a freshly built model, you cannot do inference with that model because the inference code itself relies on Trainer which is only available if model.fit() has been called.
To Reproduce
Steps to reproduce the behavior:
Run any training example
Replace the code in the example that trains the model, with the line
model.load_state_dict(state_dict_path)
where state_dict_path is the path of a saved state dict.
5. Proceed to run the part of the example code that does inference with this model.
6. See error
Expected behavior
A clear and concise description of what you expected to happen.
Full traceback
Please include the full error message to allow for debugging
AttributeError Traceback (most recent call last)
/tmp/ipykernel_931/847469493.py in <module>
1 # Inference
----> 2 results = inference(model, config)
3
4 # Read predictions from disk (fastest)
5 #results = pd.read_csv('')
/tmp/ipykernel_931/157537399.py in inference(model, config)
156 test_dataloader,
157 prediction_columns=model.prediction_columns,
--> 158 additional_attributes=model.additional_attributes,
159 )
160 # Save predictions and model to file
/kaggle/working/software/graphnet/src/graphnet/models/model.py in predict_as_dataframe(self, dataloader, prediction_columns, node_level, additional_attributes, index_column)
138 )
139
--> 140 predictions_torch = self.predict(dataloader)
141 predictions = (
142 torch.cat(predictions_torch, dim=1).detach().cpu().numpy()
/kaggle/working/software/graphnet/src/graphnet/models/standard_model.py in predict(self, dataloader)
166 """Return predictions for `dataloader`."""
167 self.inference()
--> 168 return super().predict(dataloader)
/kaggle/working/software/graphnet/src/graphnet/models/model.py in predict(self, dataloader)
93 self.train(mode=False)
94
---> 95 predictions_list = self._inference_trainer.predict(self, dataloader)
96 assert len(predictions_list), "Got no predictions"
97
/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py in __getattr__(self, name)
1184 return modules[name]
1185 raise AttributeError("'{}' object has no attribute '{}'".format(
-> 1186 type(self).__name__, name))
1187
1188 def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:
AttributeError: 'StandardModel' object has no attribute '_inference_trainer'
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
Describe the bug
When you load in a saved state dict to a freshly built model, you cannot do inference with that model because the inference code itself relies on
Trainer
which is only available ifmodel.fit()
has been called.To Reproduce
Steps to reproduce the behavior:
where state_dict_path is the path of a saved state dict.
5. Proceed to run the part of the example code that does inference with this model.
6. See error
Expected behavior
A clear and concise description of what you expected to happen.
Full traceback
Please include the full error message to allow for debugging
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: