Python class
MAXConfig
MAXConfig
class max.pipelines.lib.MAXConfig
Bases: object
Abstract base class for all MAX configs.
There are some invariants that MAXConfig classes should follow:
- All config classes should be dataclasses.
- All config classes should have a
help()method that returns a dictionary of config options and their descriptions. - All config classes dataclass fields should have default values, and hence
can be trivially initialized via
cls(). - All config classes should be frozen (except
KVCacheConfigfor now), to avoid accidental modification of config objects. - All config classes must have mutually exclusive dataclass fields among themselves.
- All config classes must define a _config_file_section_name class attribute specifying their expected configuration section name.
cli_arg_parsers()
cli_arg_parsers(choices_provider=None, description=None, formatter_class=None, required_params=None)
Creates an ArgumentParser populated with all config fields.
Builds a parser with add_argument() calls for each field, using
the loaded config values as defaults. Arguments are automatically
grouped by their group metadata from field definitions. The
parser’s parse_args() method is wrapped to convert parsed string
values back to their proper types (for example, enum objects) using
MAXConfig type conversion logic.
-
Parameters:
-
- choices_provider (dict[str, list[str]] | None) – A dictionary mapping field names to their valid
choices. Allows external code to specify choices for specific
fields. Defaults to
None. - description (str | None) – A description for the argument parser. Defaults to
None. - formatter_class (type[HelpFormatter] | None) – A formatter class for the argument parser,
forwarded to the
argparse.ArgumentParserconstructor. Defaults toNone. - required_params (set[str] | None) – A set of field names that should be marked as
required in the argument parser, regardless of their default
values. Defaults to
None.
- choices_provider (dict[str, list[str]] | None) – A dictionary mapping field names to their valid
choices. Allows external code to specify choices for specific
fields. Defaults to
-
Returns:
-
A configured
ArgumentParserwith an enhancedparse_args()method that:- Uses loaded config values as argument defaults.
- Converts parsed values to proper types (enums and similar).
- Groups arguments by field metadata for better organization.
- Maintains compatibility with standard
argparseusage.
-
Return type:
config = KVCacheConfig.from_config_file("kv_cache.yaml")
parser = config.cli_arg_parsers()
args = parser.parse_args()
choices = {"backend": ["modular", "vllm"],
"dataset_name": ["sharegpt", "random"]}
parser = config.cli_arg_parsers(choices_provider=choices)
args = parser.parse_args(["--backend", "vllm"])
# With required parameters
required = {"model", "dataset_name"}
parser = config.cli_arg_parsers(required_params=required)
args = parser.parse_args()from_config_file()
classmethod from_config_file(config_path, section_name=None)
Loads configuration from a YAML file.
Supports both individual config files and comprehensive multi-config files. For comprehensive files, automatically detects the appropriate section based on class name.
-
Parameters:
-
Returns:
-
A config instance with parameters loaded from the file.
-
Raises:
-
- FileNotFoundError – If the config file does not exist.
- ValueError – If the configuration is invalid.
-
Return type:
-
T
config = KVCacheConfig.from_config_file("kv_cache.yaml")
# Comprehensive config file (auto-detects section)
kv_config = KVCacheConfig.from_config_file("pipeline.yaml")
sampling_config = SamplingConfig.from_config_file("pipeline.yaml")
# Custom section name
config = KVCacheConfig.from_config_file(
"config.yaml", "my_cache_section"
)get_default_field_choices()
static get_default_field_choices()
Get default valid choices for fields that have constrained values.
get_default_required_fields()
classmethod get_default_required_fields()
Get default required fields for the config.
help()
abstract static help()
Returns a dictionary of config options and their descriptions.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!