Not able to Generate Predictions with Trainer.predict() #10897
-
Hi, I'm new to PyTorch Lightning, used it for the first time and kind of liked it. However, I am facing this one problem, Implemented a classification task for which I trained the model with Huggingface pretrained model as base and classification head on top. The model is training successfully and giving decent validation losses. The problem is, I'm not quite able to figure out the inferencing part. can anyone please point out what is it that I'm doing wrong? It's probably something very basic. I'll add the classes of the lightning modules and the Data Modules below.
also the dataset class is :
My goal is to be able to generate predictions for data without any labels present, using the trained model (saved as checkpoint (.ckpt)) This is what I did:
Where model_infer is :
and got :
ALso, I haven't defined a forward function in the lightning module because it is present in the model class:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
since your def predict_step(...):
return self.model(...) or define forward method in your lightning module def forward(...):
return self.model(...) |
Beta Was this translation helpful? Give feedback.
since your
model
is an instance of yourLightningModule
it cannot rely onmodel.forward
to generate the predictions becausepredict_step
by default callsLightningModule.predict
.you need to either override predict_step
or define forward method in your lightning module