config_loader

General-purpose YAML config loading with $import resolution.

This module provides the config loading infrastructure used by both modelopt.recipe and modelopt.torch.quantization.config. It lives in modelopt.torch.opt (the lowest dependency layer) to avoid circular imports.

Functions

load_config

Load a YAML config and resolve all $import references.

load_config(config_path: str | Path | Traversable, *, schema_type: type[_ModeloptConfigT]) _ModeloptConfigT
load_config(config_path: str | Path | Traversable, *, schema_type: type[list[_ModeloptConfigT]]) list[_ModeloptConfigT]
load_config(config_path: str | Path | Traversable, *, schema_type: None = None) ModeloptBaseConfig | dict[str, Any] | list[Any]

Load a YAML config and resolve all $import references.

This is the primary config loading entry point. It loads the YAML file, resolves any imports / $import directives, and returns the final config.

schema_type supplies a typing context for import resolution when the file itself has no modelopt-schema comment. If either schema_type or a modelopt-schema comment is present, the resolved top-level payload is returned as the Pydantic-normalized value for that schema. Untyped files return the resolved dict or list. Imported snippets are stricter and must always declare modelopt-schema.