For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
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:
Build a parser from a config instance and parse a list of arguments, restricting a field to a set of valid choices:
from dataclasses import dataclass
from max.config import MAXConfig
@dataclass
class MyServerConfig(MAXConfig):
backend: str = "modular"
@staticmethod
def help() -> dict[str, str]:
return {"backend": "Serving backend to use."}
config = MyServerConfig()
parser = config.cli_arg_parsers(
choices_provider={"backend": ["modular", "vllm"]},
)
args = parser.parse_args(["--backend", "vllm"])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
Define a config subclass, then load its values from a YAML file:
from dataclasses import dataclass
from pathlib import Path
from tempfile import TemporaryDirectory
from max.config import MAXConfig
@dataclass
class MyCacheConfig(MAXConfig):
page_size: int = 128
@staticmethod
def help() -> dict[str, str]:
return {"page_size": "Number of tokens per KV cache page."}
with TemporaryDirectory() as tmp_dir:
config_path = Path(tmp_dir) / "my_cache.yaml"
config_path.write_text("page_size: 256")
config = MyCacheConfig.from_config_file(config_path)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.