IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Python class

MAXConfig

MAXConfig​

class max.pipelines.lib.MAXConfig

source

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 KVCacheConfig for 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)

source

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.ArgumentParser constructor. Defaults to None.
  • 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.

Returns:

A configured ArgumentParser with an enhanced parse_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 argparse usage.

Return type:

ArgumentParser

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)

source

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:

  • config_path (str | Path) – The path to the YAML configuration file.
  • section_name (str | None) – The section name for comprehensive configs. Auto-detected if None. Defaults to None.

Returns:

A config instance with parameters loaded from the file.

Raises:

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()

source

Get default valid choices for fields that have constrained values.

Returns:

Dictionary mapping field names to their valid choices.

Return type:

dict[str, list[str]]

get_default_required_fields()​

classmethod get_default_required_fields()

source

Get default required fields for the config.

Return type:

set[str]

help()​

abstract static help()

source

Returns a dictionary of config options and their descriptions.

Return type:

dict[str, str]