Skip to content

fix: always call WandbLogger.experiment first in _call_setup_hook to ensure tensorboard logs can sync to wandb #20610

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

Conversation

ringohoffman
Copy link
Contributor

@ringohoffman ringohoffman commented Mar 2, 2025

What does this PR do?

In lightning.pytorch.trainer.call._call_setup_hook, sort the logger list when calling experiment on all loggers for the first time so that WandbLogger.experiment is always called before TensorboardLogger.experiment.

This ensures that wandb.init() is called before any tensorboard SummaryWriter are created, thereby guaranteeing that tensorboard logs can be synchronized to Weights and Biases.

See:

Also from the Weights and Biases tensorboard integrations page:

You must call either wandb.init or wandb.tensorboard.patch before calling tf.summary.create_file_writer or constructing a SummaryWriter via torch.utils.tensorboard.

Fixes N/A

Before submitting
  • Was this discussed/agreed 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 list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

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

Reviewer checklist
  • 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

cc: @Borda @awaelchli


📚 Documentation preview 📚: https://pytorch-lightning--20610.org.readthedocs.build/en/20610/

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Mar 2, 2025
@ringohoffman ringohoffman changed the title fix: always call WandbLogger.experiment first in _call_setup_hook to ensure tensorboard logs sync to wandb fix: always call WandbLogger.experiment first in _call_setup_hook to ensure tensorboard logs sync to wandb Mar 2, 2025
@ringohoffman ringohoffman changed the title fix: always call WandbLogger.experiment first in _call_setup_hook to ensure tensorboard logs sync to wandb fix: always call WandbLogger.experiment first in _call_setup_hook to ensure tensorboard logs can sync to wandb Mar 2, 2025
the trainer tests don't run with wandb installed, so we can't put it there
Copy link

codecov bot commented Mar 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79%. Comparing base (1f5add3) to head (2e3dd57).
Report is 1 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (1f5add3) and HEAD (2e3dd57). Click for more details.

HEAD has 2689 uploads less than BASE
Flag BASE (1f5add3) HEAD (2e3dd57)
gpu 2 0
pytest 314 0
lightning 468 18
cpu 623 24
python3.9 156 6
lightning_fabric 79 0
python3.10 78 3
python3.11 155 6
python3.12.7 234 9
pytorch2.1 117 9
pytest-full 311 24
pytorch_lightning 78 6
pytorch2.3 38 3
pytorch2.2.2 39 3
pytorch2.4.1 39 3
pytorch2.5.1 78 6
Additional details and impacted files
@@            Coverage Diff            @@
##           master   #20610     +/-   ##
=========================================
- Coverage      88%      79%     -9%     
=========================================
  Files         267      264      -3     
  Lines       23366    23313     -53     
=========================================
- Hits        20475    18366   -2109     
- Misses       2891     4947   +2056     
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ringohoffman
Copy link
Contributor Author

cc: @Borda

@ringohoffman
Copy link
Contributor Author

Thanks for approving! Is this able to merge?

@Borda Borda merged commit 93d707d into Lightning-AI:master Mar 10, 2025
77 checks passed
@ringohoffman ringohoffman deleted the create-wandb-experiment-before-tensorboard branch March 10, 2025 16:25
Borda pushed a commit that referenced this pull request Mar 12, 2025
… to ensure `tensorboard` logs can sync to `wandb` (#20610)

(cherry picked from commit 93d707d)
lexierule pushed a commit that referenced this pull request Mar 18, 2025
… to ensure `tensorboard` logs can sync to `wandb` (#20610)

(cherry picked from commit 93d707d)
Borda added a commit that referenced this pull request Apr 24, 2025
…up_hook` to ensure `tensorboard` logs can sync to `wandb` (#20610)"

This reverts commit 93d707d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pl Generic label for PyTorch Lightning package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants