Skip to content

fix(tracking): default step=None on tracker.log and accept extra kwargs in MLflowTracker#4039

Open
1fanwang wants to merge 2 commits into
huggingface:mainfrom
1fanwang:tracker-log-step-default-and-mlflow-kwargs
Open

fix(tracking): default step=None on tracker.log and accept extra kwargs in MLflowTracker#4039
1fanwang wants to merge 2 commits into
huggingface:mainfrom
1fanwang:tracker-log-step-default-and-mlflow-kwargs

Conversation

@1fanwang
Copy link
Copy Markdown

@1fanwang 1fanwang commented May 12, 2026

Closes #4041.

What does this PR do?

Two related bugs in src/accelerate/tracking.py:

1. tracker.log() raises TypeError when step is omitted.

Every tracker subclass declares step: Optional[int] with no default value:

def log(self, values: dict, step: Optional[int]):
    ...

The docstrings all describe step as optional. Users following the docstring hit:

TypeError: log() missing 1 required positional argument: 'step'

Fix: set step: Optional[int] = None on GeneralTracker.log, TensorBoardTracker.log_images, AimTracker.log, MLflowTracker.log, and the MyCustomTracker test fixture (which was propagating the broken signature into test scaffolding).

2. MLflowTracker.log swallows log_kwargs.

Accelerator.log(values, log_kwargs={"mlflow": {"synchronous": True}}) is documented to forward provider-specific kwargs through to each tracker. MLflowTracker.log doesn't accept **kwargs, so the call raises:

TypeError: log() got an unexpected keyword argument 'synchronous'

Fix: accept **kwargs in MLflowTracker.log and forward to mlflow.log_metrics.

How was this tested?

Two regression tests under MLflowTrackingTest:

  • test_log_without_steptracker.log({"loss": 0.1}) with no step.
  • test_log_accepts_extra_kwargsaccelerator.log({"loss": 0.1}, step=1, log_kwargs={"mlflow": {"synchronous": True}}) and assert mlflow.log_metrics was called with synchronous=True.

Before (against upstream/main):

$ pytest tests/test_tracking.py::MLflowTrackingTest::test_log_without_step -v --tb=short
tests/test_tracking.py::MLflowTrackingTest::test_log_without_step FAILED
=================================== FAILURES ===================================
___________________ MLflowTrackingTest.test_log_without_step ___________________
tests/test_tracking.py:331: in test_log_without_step
    tracker.log({"loss": 0.1})
src/accelerate/tracking.py:89: in execute_on_main_process
    return PartialState().on_main_process(function)(self, *args, **kwargs)
E   TypeError: MLflowTracker.log() missing 1 required positional argument: 'step'
1 failed in 3.95s

$ pytest tests/test_tracking.py::MLflowTrackingTest::test_log_accepts_extra_kwargs -v --tb=short
tests/test_tracking.py::MLflowTrackingTest::test_log_accepts_extra_kwargs FAILED
=================================== FAILURES ===================================
_______________ MLflowTrackingTest.test_log_accepts_extra_kwargs _______________
tests/test_tracking.py:346: in test_log_accepts_extra_kwargs
    accelerator.log({"loss": 0.1}, step=1, log_kwargs={"mlflow": {"synchronous": True}})
src/accelerate/accelerator.py:3381: in log
    tracker.log(values, step=step, **log_kwargs.get(tracker.name, {}))
src/accelerate/tracking.py:89: in execute_on_main_process
    return PartialState().on_main_process(function)(self, *args, **kwargs)
E   TypeError: MLflowTracker.log() got an unexpected keyword argument 'synchronous'
1 failed in 3.08s

After (this PR):

$ pytest tests/test_tracking.py::MLflowTrackingTest::test_log_without_step tests/test_tracking.py::MLflowTrackingTest::test_log_accepts_extra_kwargs -v
tests/test_tracking.py::MLflowTrackingTest::test_log_without_step PASSED
tests/test_tracking.py::MLflowTrackingTest::test_log_accepts_extra_kwargs PASSED
2 passed in 4.18s

Before submitting

1fanwang added 2 commits May 12, 2026 01:32
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLflowTracker.log drops log_kwargs; tracker.log requires step despite docstring

1 participant