Skip to content

Fix MLflowTracker.store_init_configuration mutating the caller's config dict#4046

Open
ATOM00blue wants to merge 1 commit into
huggingface:mainfrom
ATOM00blue:fix-mlflow-store-init-config-mutation
Open

Fix MLflowTracker.store_init_configuration mutating the caller's config dict#4046
ATOM00blue wants to merge 1 commit into
huggingface:mainfrom
ATOM00blue:fix-mlflow-store-init-config-mutation

Conversation

@ATOM00blue
Copy link
Copy Markdown

What does this PR do?

MLflowTracker.store_init_configuration drops config values that exceed MLflow's
MAX_PARAM_VAL_LENGTH, but it did so by deleting them from the input dict in place:

for name, value in list(values.items()):
    if len(str(value)) > mlflow.utils.validation.MAX_PARAM_VAL_LENGTH:
        logger.warning_once(...)
        del values[name]   # mutates the caller's dict

Accelerator.init_trackers passes the same config object to every tracker:

if config is not None:
    for tracker in self.trackers:
        tracker.store_init_configuration(config)

So when MLflow drops an over-long value, that key is permanently removed from the
user's config dict and is therefore missing from every other tracker (TensorBoard,
WandB, etc.) that runs after MLflow, as well as from any later use of the dict by the
user. This is silent, order-dependent data loss.

Fix

Build a filtered list of in-range items instead of mutating the input, which is the
same approach already used in MLflowTracker.log (it builds a separate metrics dict).
The warning and the dropping of over-long values from what gets logged to MLflow are
both preserved; only the in-place mutation of the caller's dict is removed.

Reproduction (before this PR)

import tempfile, mlflow
from accelerate.tracking import MLflowTracker

tracker = MLflowTracker(experiment_name="repro", logging_dir=tempfile.mkdtemp())
tracker.start()
config = {"learning_rate": 0.001, "long_note": "x" * (mlflow.utils.validation.MAX_PARAM_VAL_LENGTH + 1)}
tracker.store_init_configuration(config)
print(config)  # -> {'learning_rate': 0.001}  ("long_note" was deleted from the caller's dict)

After this PR, config still contains long_note; only the value sent to MLflow is dropped.

Before submitting

  • Did you write any new necessary tests?

A regression test (MLflowTrackingTest::test_store_init_configuration_does_not_mutate_input)
is added; it fails on main and passes with this change.

Who can review?

@BenjaminBossan @SunMarc


Developed with AI coding assistance; reviewed and submitted by the author.

`store_init_configuration` deleted over-long values from the `values`
dict in place via `del values[name]`. Since `Accelerator.init_trackers`
passes the same `config` object to every tracker, this removed the key
from the user's dict and from all other trackers as well.

Build a filtered list of in-range items instead of mutating the input,
matching the approach already used in `MLflowTracker.log`. The warning
and the dropping of over-long values are preserved. Adds a regression
test that fails before this change.
Copilot AI review requested due to automatic review settings May 22, 2026 02:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds regression coverage and adjusts MLflow init-config logging to avoid mutating caller-provided configuration dictionaries.

Changes:

  • Update MLflowTracker.store_init_configuration() to filter over-long values without deleting keys from the input dict.
  • Add a regression test asserting the caller’s dict is not mutated while ensuring MLflow still drops over-long params.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/test_tracking.py Adds regression test for non-mutating init configuration logging to MLflow.
src/accelerate/tracking.py Avoids in-place deletion from values when filtering MLflow params.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_tracking.py
Comment on lines +328 to +332
"""`store_init_configuration` must not mutate the caller's dict when dropping over-long values.

The same `config` object is shared across all trackers in `Accelerator.init_trackers`, so deleting
keys in place removed them from the user's dict and from every other tracker too.
"""
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.

2 participants