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

Lite: Support self.log from a LightningModule #16311

Merged
merged 23 commits into from
Jan 10, 2023

Conversation

lightningforever
Copy link
Contributor

@lightningforever lightningforever commented Jan 10, 2023

What does this PR do?

Enables LightningModule users to call self.log() and self.log_dict() in any hook when used together with Fabric.

  • We support logging Python scalars and Tensor scalars.
  • There is basic input validation for the right data types and nesting.
  • You can't pass in a torchmetrics.Metric object. You need to call .compute() yourself at the right time. This is not a limitation, this is a feature. Since compute() is expensive, Fabric users need to control themselves when to do it.
  • We don't support ANY of the optional arguments of self.log namely: prog_bar, on_step, on_epoch, reduce_fx, enable_graph, add_dataloader_idx, batch_size, sync_dist, sync_dist_fn, sync_dist_group, metric_attribute, rank_zero_only. Supporting them would require making assumptions about loop structure and features that do not exist, and will never exist in Fabric. We silently ignore them.

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

I made sure I had fun coding 🙃

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Jan 10, 2023
@lightningforever lightningforever marked this pull request as ready for review January 10, 2023 11:50
@awaelchli awaelchli added the fabric lightning.fabric.Fabric label Jan 10, 2023
@awaelchli awaelchli added this to the v1.9 milestone Jan 10, 2023
@awaelchli awaelchli added the feature Is an improvement or enhancement label Jan 10, 2023
Copy link
Member

@justusschock justusschock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general. One thing: should we warn the user the first time they pass in unsupported arguments? Otherwise, this may silently lead to unexpected behavior

src/pytorch_lightning/core/module.py Outdated Show resolved Hide resolved
src/lightning_fabric/fabric.py Outdated Show resolved Hide resolved
src/lightning_fabric/fabric.py Outdated Show resolved Hide resolved
@awaelchli
Copy link
Contributor

One thing: should we warn the user the first time they pass in unsupported arguments? Otherwise, this may silently lead to unexpected behavior

I initially wanted to do that. But it would add quite some code to do this correctly and nicely, with added complexity. As a consequence, all types and default values would change in the signature to Optional[None] = None etc. I didn't want to go down that path without knowing this is actually worth it.

@mergify mergify bot added the ready PRs ready to be merged label Jan 10, 2023
@awaelchli awaelchli enabled auto-merge (squash) January 10, 2023 14:16
auto-merge was automatically disabled January 10, 2023 14:47

Head branch was pushed to by a user without write access

@awaelchli awaelchli enabled auto-merge (squash) January 10, 2023 14:48
auto-merge was automatically disabled January 10, 2023 15:37

Head branch was pushed to by a user without write access

@awaelchli awaelchli enabled auto-merge (squash) January 10, 2023 16:11
@awaelchli awaelchli merged commit 91aaa53 into Lightning-AI:master Jan 10, 2023
@lightningforever lightningforever deleted the lite/logger-lm branch January 10, 2023 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fabric lightning.fabric.Fabric feature Is an improvement or enhancement pl Generic label for PyTorch Lightning package ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants