Skip to content

fix(tracker): guard init_trackers and log against None kwargs#4026

Open
xodn348 wants to merge 1 commit into
huggingface:mainfrom
xodn348:patch/tracker-none-kwargs
Open

fix(tracker): guard init_trackers and log against None kwargs#4026
xodn348 wants to merge 1 commit into
huggingface:mainfrom
xodn348:patch/tracker-none-kwargs

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented May 2, 2026

Summary

Accelerator.init_trackers and Accelerator.log both declare their optional dict arguments as dict | None, but the function bodies call .get() on the value directly without a None guard. Passing init_kwargs=None or log_kwargs=None therefore raises AttributeError: 'NoneType' object has no attribute 'get' at runtime, even though the type annotation marks None as valid. The root cause is that both signatures used = {} as the default (a mutable-default antipattern in Python) while accepting None in the union type; the fix changes the default to None and adds an explicit if … is None: … = {} guard inside each function body.

Issue

No prior issue — found via code review while auditing tracker-related code paths.

Local verification

cd /tmp/accelerate
pip install -e ".[quality]" -q
pytest tests/test_tracking.py::CustomTrackerTestCase -v

Output:

tests/test_tracking.py::CustomTrackerTestCase::test_init_trackers PASSED
tests/test_tracking.py::CustomTrackerTestCase::test_init_trackers_none_kwargs PASSED
tests/test_tracking.py::CustomTrackerTestCase::test_log PASSED
tests/test_tracking.py::CustomTrackerTestCase::test_log_none_kwargs PASSED

4 passed in 1.54s

=== LOCAL_TEST_PASSED ===

Risk

The change is backward-compatible: callers that already pass a real dict (the common case) see no difference. The only behavior change is that None is now tolerated instead of crashing, which matches what the type annotation already promised. No distributed or multi-GPU code paths are touched.

Both Accelerator.init_trackers and Accelerator.log accept
`dict | None` for their kwargs arguments but called `.get()` on
the value directly; passing None raised AttributeError. Change
the default from `{}` to None and add an explicit None-guard in
each function body so the type annotation matches the runtime
behaviour.
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.

1 participant