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 a YAML config and resolve all |
- load_config(config_path: str | Path | Traversable, *, schema_type: type[_SchemaT]) _SchemaT
- load_config(config_path: str | Path | Traversable, *, schema_type: type[list[_SchemaT]]) list[_SchemaT]
- load_config(config_path: str | Path | Traversable, *, schema_type: None = None) Any
Load a YAML config and resolve all
$importreferences.This is the primary config loading entry point. It loads the YAML file, resolves any
imports/$importdirectives, and returns either a validated instance of the schema (when one is known) or the raw resolved payload.The effective schema is selected as follows:
If
schema_typeis provided, it is used.Otherwise, the schema declared by the file’s
# modelopt-schema:comment (if any) is used.
When an effective schema is selected, the resolved payload is validated and returned as an instance of that schema — e.g., a Pydantic model instance for
BaseModelschemas, or a validated dict / list forTypedDict/list[TypedDict]schemas. If neither source supplies a schema, the raw resolved dict or list is returned unchanged.Imported snippets are stricter and must always declare
modelopt-schema; they are validated during import resolution regardless of the top-level selection above.