-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
When returning value in "training_step" function, one must specify "loss", otherwise results in error #7750
Comments
Hi @justusschock , thanks for the quick reply!
Regarding point 2: For my first working version I just copied some demo code. In that code, the training_step did not return anything. So I was quite surprised that once I added a return statement that the code crashed with what seemed to me an unintuitive exception. I mean I know it now and it definitely is a beginner's mistake. But 2 other people I know recently started with trying ou oytorch lightning and ran into the same issue, that's also why I wanted to raise this issue here. |
@Dehde thanks for the feedback, we really appreciate it :) I think it should be part of every example (either as a tensor or as a key in the dict). I will make sure to get it to a proper warning/error message. When you encounter an example that doesn't have this, please either notify me (or one of the team) or open a pull-request to adjust the example yourself :) |
Cool! Will do! |
@Dehde have you succeed with solving this issue? 🐰 |
@Borda I'll leave this open until I added a PR with a proper error message/warning |
🐛 Bug
I want to let the training step also return the probabilities that were predicted in the step in order to calculate the f1-score for the entire epoch. In order to do so I let the training step return the predictions and the ground truth values. I follow the instructions here: https://pytorch-lightning.readthedocs.io/en/latest/common/lightning_module.html#train-epoch-level-operations.
It mentions the "loss" in the code sample, yet nowhere did I read that you have to specify the loss in there. But you do have to specify that, otherwise an exception will be trown:
The code that produces this bug:
The only change I needed to make is to add the loss in the dictionary that returns the items:
But I only stumbled upon this very randomly. Neither the docs nor the error message made it very clear to me what the problem was.
I hope this information suffices, otherwise please let me know what other information I should provide.
Thanks for this great repository by the way!!
The text was updated successfully, but these errors were encountered: