From c6f16d3ef6052d3caed2ef93c8df57c10d985757 Mon Sep 17 00:00:00 2001 From: Li Guan Date: Tue, 26 May 2026 03:01:42 +0800 Subject: [PATCH] fix(utils): use default_factory for mutable dataclass fields 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 --- optimum/utils/runs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimum/utils/runs.py b/optimum/utils/runs.py index 0087ac0dea..2ada606b31 100644 --- a/optimum/utils/runs.py +++ b/optimum/utils/runs.py @@ -227,7 +227,7 @@ class _RunDefaults: metadata={"description": "Maximum number of samples to use from the evaluation dataset for evaluation."}, ) time_benchmark_args: Optional[BenchmarkTimeArgs] = field( - default=BenchmarkTimeArgs(), metadata={"description": "Parameters related to time benchmark."} + default_factory=BenchmarkTimeArgs, metadata={"description": "Parameters related to time benchmark."} )