You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix mutable default error in MetricsConfig dataclasses (#3137)
Summary:
# Context
Found a dataclass validation error: "mutable default ... is not allowed: use default_factory". The issue was that `DefaultMetricsConfig` and `EmptyMetricsConfig` were created as static instances with mutable objects (lists/dicts), but then used as defaults in dataclass fields. This violates Python's dataclass rules since all instances would share the same mutable objects.
Check out this for more info on python dataclasses:
https://docs.python.org/3/library/dataclasses.html#mutable-default-values
# Changes
Converted the static config instances to factory functions that return fresh objects each time:
* `DefaultMetricsConfig` → `_create_default_metrics_config()`
* `EmptyMetricsConfig` → `_create_empty_metrics_config()`
Updated the dataclass field in `TrainingAppConfig` to use `field(default_factory=_create_empty_metrics_config)` instead of the static instance.
Now each dataclass gets its own separate config object, fixing the mutable default error.
Reviewed By: TroyGarden
Differential Revision: D77263018
0 commit comments