diff --git a/vllm/config/utils.py b/vllm/config/utils.py index a953fcb46e..12e0385aeb 100644 --- a/vllm/config/utils.py +++ b/vllm/config/utils.py @@ -279,6 +279,18 @@ def normalize_value(x): except Exception: 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. if is_dataclass(x): 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)): 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 # without a stable JSON/UUID representation. Hard-error to avoid # under-hashing.