fix(tracking): default step=None on tracker.log and accept extra kwargs in MLflowTracker#4039
Open
1fanwang wants to merge 2 commits into
Open
Conversation
…ker.log
Several tracker `log` / `log_images` methods declared `step: Optional[int]`
without a default, even though their docstrings said the parameter was
optional. Calling `tracker.log(values)` therefore raised
`TypeError: log() missing 1 required positional argument: 'step'` on
`GeneralTracker`, `TensorBoardTracker.log_images`, `AimTracker.log`, and
`MLflowTracker.log`.
`MLflowTracker.log` also did not accept `**kwargs`, so passing per-tracker
arguments via `Accelerator.log(log_kwargs={"mlflow": {...}})` raised
`TypeError: log() got an unexpected keyword argument`. The forwarded kwargs
are now passed through to `mlflow.log_metrics`.
Added two regression tests on `MLflowTracker` covering both paths.
2 tasks
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.
Closes #4041.
What does this PR do?
Two related bugs in
src/accelerate/tracking.py:1.
tracker.log()raisesTypeErrorwhenstepis omitted.Every tracker subclass declares
step: Optional[int]with no default value:The docstrings all describe
stepas optional. Users following the docstring hit:Fix: set
step: Optional[int] = NoneonGeneralTracker.log,TensorBoardTracker.log_images,AimTracker.log,MLflowTracker.log, and theMyCustomTrackertest fixture (which was propagating the broken signature into test scaffolding).2.
MLflowTracker.logswallowslog_kwargs.Accelerator.log(values, log_kwargs={"mlflow": {"synchronous": True}})is documented to forward provider-specific kwargs through to each tracker.MLflowTracker.logdoesn't accept**kwargs, so the call raises:Fix: accept
**kwargsinMLflowTracker.logand forward tomlflow.log_metrics.How was this tested?
Two regression tests under
MLflowTrackingTest:test_log_without_step—tracker.log({"loss": 0.1})with nostep.test_log_accepts_extra_kwargs—accelerator.log({"loss": 0.1}, step=1, log_kwargs={"mlflow": {"synchronous": True}})and assertmlflow.log_metricswas called withsynchronous=True.Before (against
upstream/main):After (this PR):
Before submitting
stepoptional, the code now matches.