Repository navigation
Conversation
Refs: open-mmlab#1081 `Visualizer.add_image` was decorated with `@master_only`, so during distributed training only the master process wrote images to the vis backends. Removing the decorator alone is not enough, because every rank would then write to the same file name: `LocalVisBackend` derives it from `name` and `step` only. This commit: - adds a `master_only` argument to `Visualizer` (defaults to True, so the behaviour of previous versions is preserved) and gates `add_image` on it instead of using the decorator, following the suggestion in open-mmlab#1081 - appends the rank to the file name in `LocalVisBackend.add_image` for non-main processes, so the images of different ranks no longer overwrite each other - adds unit tests covering both the switch and the rank suffix
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Fixes #1081.
Visualizer.add_imagewas decorated with@master_only, so during distributedtraining only the master process wrote images to the vis backends and the
predictions of the other ranks were lost. Simply deleting the decorator is not
enough, because every rank would then write to the same file:
LocalVisBackendderives the file name from
nameandsteponly, so the ranks would overwriteeach other.
This PR makes recording images from every rank an explicit, opt-in behaviour and
makes
LocalVisBackendable to store the images of different ranks side by side.Modification
mmengine/visualization/visualizer.pymaster_onlyargument toVisualizer(defaults toTrue, so thebehaviour of previous versions is unchanged);
add_imageis gated on that argument instead of the@master_onlydecorator, following the suggestion of @HAOCHENYE in [Feature]
Visualizerdo not needmaster_onlywhen saving image #1081 and in the reviewof [CodeCamp2023-327]Control whether methods of the Visualizer are executed only in the main process through a parameter #1353 ("avoid using the
master_onlydecorator inside theVisualizerand instead opt for adding a
master_onlyparameter").mmengine/visualization/vis_backend.pyLocalVisBackend.add_imageappends the rank to the file name for thenon-main processes (
{name}_{step}_rank{rank}.png). The file name of themain process is untouched, so single-process users see no change.
Usage:
BC-breaking
No.
master_onlydefaults toTrueand rank-0 file names are unchanged.Limitation
Only
LocalVisBackendgets rank-aware file names in this PR. Remote backends(TensorBoard, WandB, MLflow, ...) still share one experiment between ranks, so
master_only=Falseis only recommended together withLocalVisBackendfor now.I can extend this in a follow-up if that is preferable.
Tests
Added unit tests:
tests/test_visualizer/test_visualizer.py::TestVisualizer::test_master_onlyasserts that
add_imageis skipped on a non-main process by default andreaches every backend once
master_only=False.tests/test_visualizer/test_vis_backend.py::TestLocalVisBackend::test_add_image_non_main_processasserts the
_ranksuffix of the saved file.Results on Windows 11 / Python 3.13 / torch 2.11:
flake8andisort --check-onlyare clean on the touched files.yapfcouldnot be verified locally because the pinned
v0.32.0does not run on Python 3.13(
lib2to3was removed); the added code follows the formatting of thesurrounding code.
Checklist
unchanged, so MMDetection/MMClassification are not affected unless they opt in.
Visualizer).