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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling module.log(...) within a callback fails #3813

Closed
ananthsub opened this issue Oct 3, 2020 · 7 comments 路 Fixed by #4552
Closed

Calling module.log(...) within a callback fails #3813

ananthsub opened this issue Oct 3, 2020 · 7 comments 路 Fixed by #4552
Assignees
Labels
bug Something isn't working feature Is an improvement or enhancement
Milestone

Comments

@ananthsub
Copy link
Contributor

馃悰 Bug

Calling pl_module.log(...) within a Callback fails, even though this is recommended by the documentation here: https://pytorch-lightning.readthedocs.io/en/latest/loggers.html#logging-from-a-callback

Error

  File "my_callback_file.py", line XX, in on_validation_epoch_end
    pl_module.log_dict(my_metrics_dict)
  File "/home/local/USHERBROOKE/pain5474/opt/miniconda3/envs/cav/lib/python3.8/site-packages/pytorch_lightning/core/lightning.py", line 287, in log_dict
    self.log(
  File "/home/local/USHERBROOKE/pain5474/opt/miniconda3/envs/cav/lib/python3.8/site-packages/pytorch_lightning/core/lightning.py", line 233, in log
    self._results.log(
  File "/home/local/USHERBROOKE/pain5474/opt/miniconda3/envs/cav/lib/python3.8/site-packages/pytorch_lightning/core/step_result.py", line 171, in log
    self.__set_meta(
  File "/home/local/USHERBROOKE/pain5474/opt/miniconda3/envs/cav/lib/python3.8/site-packages/pytorch_lightning/core/step_result.py", line 217, in __set_meta
    _internal = self['meta']['_internal']
KeyError: '_internal'
python-BaseException

cc @nathanpainchaud

This is happening on master

Expected behavior

We can log from callbacks using the lightning module

Environment

Happening on PyTorch Lightning master

@ananthsub ananthsub added bug Something isn't working help wanted Open to be worked on labels Oct 3, 2020
@awaelchli awaelchli modified the milestones: 0.9.x, 1.0 Oct 4, 2020
@edenlightning edenlightning added the priority: 0 High priority task label Oct 4, 2020
@edenlightning edenlightning added v1.0 allowed and removed help wanted Open to be worked on labels Oct 4, 2020
@SkafteNicki
Copy link
Member

@ananthsub I just tried on master and cannot reproduce (I think it was solved yesterday, as I could reproduce 2 days ago).

@edenlightning edenlightning modified the milestones: 1.0, 1.1 Oct 7, 2020
@nathanpainchaud
Copy link
Contributor

nathanpainchaud commented Oct 7, 2020

@SkafteNicki The issue was created by @ananthsub based on a question/issue I initially raised in the slack. I'll try to see if the bug is now resolved on master for me (it was still present as of yesterday afternoon) and I'll update you here as soon as I can.

Edit: @SkafteNicki The issue persists on my end, after having just pulled the master. I'll try to write a test today that can reliably reproduce this behavior, and I'll open a draft PR and link it here once I do.

@edenlightning edenlightning added the waiting on author Waiting on user action, correction, or update label Oct 13, 2020
@tchaton
Copy link
Contributor

tchaton commented Oct 14, 2020

Hey @nathanpainchaud,

Did you manage to reliably reproduce this behaviour? And if yes, could share the draft PR associated with this issue ?
I will try to try it out too.

Best regards,
Thomas Chaton.

@nathanpainchaud
Copy link
Contributor

Hey @tchaton,

Thanks for the follow up! I opened the draft PR where I added a test that reproduces the behavior I'm getting.

If I can help in any other way to get this sorted, just let me know!

@nathanpainchaud
Copy link
Contributor

@tchaton Any updates on whether this is a feature that's planned to be supported, or on the contrary it's been abandoned? I'm only asking this question because the issue has been labelled priority for a while, but every PR referring to it have been closed without getting merged 馃槅

@williamFalcon
Copy link
Contributor

Yes! thats been worked on these weeks. Starting to be merged now (#4439)

@edenlightning edenlightning added feature Is an improvement or enhancement and removed priority: 0 High priority task labels Nov 11, 2020
@ghost
Copy link

ghost commented Feb 20, 2021

I still have problems logging my validation metrics using pl_module.log() in the on_validation_end() hook. Any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment