-
Notifications
You must be signed in to change notification settings - Fork 408
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
Unable to call metric from any step in Lightning module #102
Comments
Hi! thanks for your contribution!, great first issue! |
Hi @SpirinEgor would it be possible for you to share some reproducible code? |
@SpirinEgor I must be doing something different from you, because if I call your metric inside |
Sure, here what I'm doing.
This is very strange for me too. Because when I wrote tests for metric class it was work just fine... |
Strange, still cannot reproduce your error. Both training and validation seems to run fine :/ |
Oh, it's become really tough... |
I found the reason for all my troubles. In the main train function, I use
This step adds backward hooks to track gradients, their norms, etc. After I disable it metric start working as I expected. Anyway, big thanks for your response! The library is great, hope to see more cool features. |
Thanks for letting me know, and glad that you like the library! |
🐛 Bug
I implemented my own Metric class that returns from the
compute
data class with some aggregated metrics -- precision, recall, and f1-score. But when I try to call metric inside*_step
I got the error from PyTorch internals.The error happened in this line. If I call validation metric (initialized with
compute_on_step=False
) duringvalidation_step
I got:In the case of training metric during
training_step
:ClassificationMetrics
is the name of my data class.I also tried to return float from
compute
, but it also causes the same error. I assume that PyTorch expects to receive tensor and therefore trying to get fromvar
. An obvious solution is to return tensor fromcompute
, but it doesn't fix calling validation metric that doesn't return anything.Environment
conda
,pip
, source): pipThe text was updated successfully, but these errors were encountered: