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

'StandardModel' object has no attribute '_inference_trainer' #403

Closed
RasmusOrsoe opened this issue Jan 31, 2023 · 0 comments · Fixed by #406
Closed

'StandardModel' object has no attribute '_inference_trainer' #403

RasmusOrsoe opened this issue Jan 31, 2023 · 0 comments · Fixed by #406
Assignees
Labels
bug Something isn't working

Comments

@RasmusOrsoe
Copy link
Collaborator

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:

  1. Run any training example
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants