fix: AOT compile cache collision for dataclass-based HF configs (#45059)
Signed-off-by: Angela Yi <yiangela7@gmail.com>
This commit is contained in:
+12
-12
@@ -279,6 +279,18 @@ def normalize_value(x):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return str(x)
|
return str(x)
|
||||||
|
|
||||||
|
# PretrainedConfig (must be before dataclass branch as these are now dataclasses)
|
||||||
|
if hasattr(x, "to_json_string") and callable(x.to_json_string):
|
||||||
|
try:
|
||||||
|
return x.to_json_string()
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
# to_json_string() may fail for trust-remote-code configs
|
||||||
|
# with non-JSON-serializable nested objects. Fall back to
|
||||||
|
# normalizing the dict representation recursively.
|
||||||
|
if hasattr(x, "to_dict") and callable(x.to_dict):
|
||||||
|
return normalize_value(x.to_dict())
|
||||||
|
raise
|
||||||
|
|
||||||
# Dataclasses: represent as (FQN, sorted(field,value) tuple) for stability.
|
# Dataclasses: represent as (FQN, sorted(field,value) tuple) for stability.
|
||||||
if is_dataclass(x):
|
if is_dataclass(x):
|
||||||
type_fqn = f"{x.__class__.__module__}.{x.__class__.__qualname__}"
|
type_fqn = f"{x.__class__.__module__}.{x.__class__.__qualname__}"
|
||||||
@@ -296,18 +308,6 @@ def normalize_value(x):
|
|||||||
if isinstance(x, Sequence) and not isinstance(x, (str, bytes, bytearray)):
|
if isinstance(x, Sequence) and not isinstance(x, (str, bytes, bytearray)):
|
||||||
return tuple(normalize_value(v) for v in x)
|
return tuple(normalize_value(v) for v in x)
|
||||||
|
|
||||||
# PretrainedConfig
|
|
||||||
if hasattr(x, "to_json_string") and callable(x.to_json_string):
|
|
||||||
try:
|
|
||||||
return x.to_json_string()
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
# to_json_string() may fail for trust-remote-code configs
|
|
||||||
# with non-JSON-serializable nested objects. Fall back to
|
|
||||||
# normalizing the dict representation recursively.
|
|
||||||
if hasattr(x, "to_dict") and callable(x.to_dict):
|
|
||||||
return normalize_value(x.to_dict())
|
|
||||||
raise
|
|
||||||
|
|
||||||
# Unsupported type: e.g., modules, generators, open files, or objects
|
# Unsupported type: e.g., modules, generators, open files, or objects
|
||||||
# without a stable JSON/UUID representation. Hard-error to avoid
|
# without a stable JSON/UUID representation. Hard-error to avoid
|
||||||
# under-hashing.
|
# under-hashing.
|
||||||
|
|||||||
Reference in New Issue
Block a user