Make WandbLogger run initialization lazy for non-spawn distributed operation #17573
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #17487
Prior to 2.0, when strategy="ddp_spawn" was the default distributed strategy, the wandb logger had to solve the following problem:
These were addressed by enabling the wandb-service feature (#11650), which would re-attach subprocesses to the one run created by the main process. This would avoid creating duplicated runs under different circumstances. However, the drawback to the solution is that the experiment had to be created in the main process for the service to reattach properly. This is inconsistent with other loggers who create their runs lazily, and leads to inconveniences like in #17487.
This PR removes the run initialization in
WandbLogger.__init__
to make it truly lazy. The justification is that today in 2.0, the default strategy is ddp proper, with which the above issues never existed. To not break the usage with ddp_spawn, for users who still use that strategy, I "hacked" the__getstate__
so that whenmp.spawn
is called, the special wandb-service still gets enabled (and the run gets initialized in the main process).cc @Borda @awaelchli @morganmcg1 @borisdayma @scottire @parambharat