Skip to content

fix(utils): use default_factory for mutable dataclass fields#2440

Open
Leetfs wants to merge 1 commit into
huggingface:mainfrom
Leetfs:fixValueError
Open

fix(utils): use default_factory for mutable dataclass fields#2440
Leetfs wants to merge 1 commit into
huggingface:mainfrom
Leetfs:fixValueError

Conversation

@Leetfs
Copy link
Copy Markdown

@Leetfs Leetfs commented May 25, 2026

What does this PR do?

Fixes a ValueError that occurs during module initialization in modern Python versions due to the use of a mutable default value in a dataclass.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests? - This is a syntax/initialization fix, existing tests should cover it.

Who can review?

@michaelbenayoun @IlyasMoutawwakil

In modern Python versions, using a mutable object (like a class instance)
as a default value in a dataclass without `default_factory` raises a
ValueError. This strict check prevents unintended shared state across
instances (ghost bugs).

This commit updates `_RunDefaults.time_benchmark_args` in
`optimum.utils.runs` to use `default_factory=BenchmarkTimeArgs`
instead of `default=BenchmarkTimeArgs()`. This perfectly resolves
the ValueError during module initialization and testing.

Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
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