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
MAXModelConfig
MAXModelConfig
class max.pipelines.MAXModelConfig(*, config_file=None, section_name=None, use_subgraphs=True, data_parallel_degree=1, pool_embeddings=True, max_length=None, model_path='', served_model_name=None, weight_path=<factory>, quantization_encoding=None, huggingface_model_revision='main', huggingface_weight_revision='main', trust_remote_code=False, subfolder=None, device_specs=<factory>, force_download=False, header_only_weights=False, vision_config_overrides=<factory>, rope_type=None, sliding_window=None, enable_echo=False, chat_template=None, kv_cache=<factory>)
Bases: MAXModelConfigBase
Configuration for a pipeline model.
-
Parameters:
-
- config_file (str | None)
- section_name (str | None)
- use_subgraphs (bool)
- data_parallel_degree (int)
- pool_embeddings (bool)
- max_length (int | None)
- model_path (str)
- served_model_name (str | None)
- weight_path (list[Path])
- quantization_encoding (Literal['float32', 'float16', 'bfloat16', 'q4_k', 'q4_0', 'q6_k', 'float8_e4m3fn', 'float4_e2m1fnx2', 'float6_e2m3fn', 'gptq'] | None)
- huggingface_model_revision (str)
- huggingface_weight_revision (str)
- trust_remote_code (bool)
- subfolder (str | None)
- device_specs (list[DeviceSpec])
- force_download (bool)
- header_only_weights (bool)
- vision_config_overrides (dict[str, Any])
- rope_type (Literal['none', 'normal', 'neox', 'longrope', 'yarn'] | None)
- sliding_window (int | None)
- enable_echo (bool)
- chat_template (Path | None)
- kv_cache (KVCacheConfig)
architecture_name
Returns the architecture class name from the HuggingFace config.
For transformers models, returns architectures[0] from the
HuggingFace config.
chat_template
chat_template: Path | None
An optional custom chat template to override the one shipped with the model.
data_parallel_degree
data_parallel_degree: int
The degree of data parallelism for replicating the model.
default_device_spec
property default_device_spec: DeviceSpec
Returns the default device spec for the model.
This is the first device spec in the list, used for device spec checks throughout config validation.
-
Returns:
-
The default device spec for the model.
device_specs
device_specs: list[DeviceSpec]
The devices to run inference on.
enable_echo
enable_echo: bool
Whether the model should be built with echo capabilities.
force_download
force_download: bool
Whether to force download a file even if it’s already in the local cache.
from_pipeline_args()
classmethod from_pipeline_args(args)
Builds a MAXModelConfig from a PipelineArgs’s flat fields.
Returns a new object on every call – args holds no live handle
back to it, so mutating the returned object (such as
MAXModelConfig.from_pipeline_args(args).foo = x) has no effect on
a subsequent call with the same args. Set the corresponding field
on args itself instead.
-
Parameters:
-
args (PipelineArgs)
-
Return type:
-
Self
generation_config
property generation_config: GenerationConfig
Returns the Hugging Face GenerationConfig for this model.
Loaded once at construction (see _populate_generation_config())
and stored in a PrivateAttr; this getter returns it, falling back to
loading on demand for a never-populated config (such as a placeholder).
Loading failures yield a default GenerationConfig.
header_only_weights
header_only_weights: bool
Whether to stand in header-only stubs for the checkpoint (compile-only).
huggingface_config
property huggingface_config: PreTrainedConfig
Returns the Hugging Face model config.
Loaded once at construction (see _populate_hf_config()) and
stored in a PrivateAttr; this getter returns it. Falls back to loading
on demand – without caching – for a never-populated config (such as a
placeholder with no model_path).
For transformers models this is the AutoConfig subclass; for
non-transformers models (such as diffusers components) it is the raw
config.json wrapped in a PretrainedConfig.
-
Raises:
-
FileNotFoundError – If no
config.jsoncan be found for the model repo/subfolder.
huggingface_model_repo
property huggingface_model_repo: HuggingFaceRepo
Returns the Hugging Face repo handle for the model.
Built once at construction (see _populate_repo_handles()) and
stored in a PrivateAttr; this getter returns it. Falls back to
building a fresh handle only for a never-populated config and never
writes back.
huggingface_model_revision
huggingface_model_revision: str
The branch or Git revision of the Hugging Face model repository.
huggingface_weight_repo
property huggingface_weight_repo: HuggingFaceRepo
Returns the Hugging Face repo handle for weight files.
Built once at construction (see _populate_repo_handles()) and
stored in a PrivateAttr; this getter returns it. Falls back to
building a fresh handle only for a never-populated config (such as a
placeholder with no model_path) and never writes back.
huggingface_weight_repo_id
property huggingface_weight_repo_id: str
Returns the Hugging Face repo ID used for weight files.
huggingface_weight_revision
huggingface_weight_revision: str
The branch or Git revision of the Hugging Face weights repository.
kv_cache
kv_cache: KVCacheConfig
The KV cache configuration.
loader()
loader()
Returns a WeightLoader over this config’s weights.
The loader’s namespace is the raw parameter names from the source
files (un-prefixed). Pass this directly to a single-model
pipeline’s Module tree; for multi-component pipelines, use
loader()
which exposes the role-prefixed union across configs.
Resolution is lazy: the safetensors mmap stays cold for
parameters the Module never asks for. Inherits the HuggingFace
download side-effect from resolved_weight_paths() for
online repos.
Resolves quantization_encoding/weight_path on demand (see
_resolve_component_encoding_and_weights()) rather than
assuming resolution already populated them – a no-op when
they’re already set.
Returns an empty loader when there are no weight paths – common for components in a diffusion manifest that are config-only (for example, the scheduler).
-
Returns:
-
A
WeightLoaderover this config’s source namespace. -
Return type:
-
WeightLoader
log_model_info()
log_model_info(role)
Logs model configuration information for this config.
-
Parameters:
-
role (str) – The semantic role of this model (such as
"main","draft","vae"). -
Return type:
-
None
max_length
The maximum sequence length the model can process.
max_length_is_user_provided
property max_length_is_user_provided: bool
Whether the user set max_length, rather than the architecture.
Memory planning may shrink a resolved default to fit device memory, but never a length the user asked for.
model_config
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True, 'strict': False}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
model_name
property model_name: str
Returns the served model name or model path.
model_path
model_path: str
The repository ID of a Hugging Face model to use.
model_post_init()
model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
-
Parameters:
-
- self (BaseModel) – The BaseModel instance.
- context (Any) – The context.
-
Return type:
-
None
pool_embeddings
pool_embeddings: bool
Whether to pool embedding outputs.
quantization_encoding
quantization_encoding: SupportedEncoding | None
The weight encoding type.
resolved_weight_paths()
resolved_weight_paths(weight_path=None)
Resolve weight paths to absolute local paths, downloading if needed.
For online repos, downloads weight files from HuggingFace Hub.
For local repos, constructs absolute paths from the repo root. Under
header_only_weights the download is replaced by header-only stubs
(see _header_only_weight_paths()).
-
Parameters:
-
weight_path (list[Path] | None) – Weight files to resolve, relative to the repo. Defaults to
self.weight_path. Pass an explicit, already-resolved list for a config whoseweight_pathwas never populated during resolution (such as a diffusion component resolved on demand at consumption time – see_resolve_component_encoding_and_weights()). -
Returns:
-
Absolute paths to weight files on disk.
-
Return type:
-
list[Path]
rope_type
The RoPE type to use, forced regardless of model defaults.
sampling_params_defaults
property sampling_params_defaults: SamplingParamsGenerationConfigDefaults
Returns sampling defaults derived from the generation config.
served_model_name
An optional override for the client-facing model name.
sliding_window
Override the attention sliding-window size in tokens.
subfolder
Subdirectory within the HuggingFace repo to load config and weights from.
trust_remote_code
trust_remote_code: bool
Whether to allow custom modeling files from Hugging Face.
use_subgraphs
use_subgraphs: bool
Whether to use subgraphs for the model.
validate_max_length()
classmethod validate_max_length(v)
Validate that max_length is non-negative if provided.
validate_multi_gpu_supported()
validate_multi_gpu_supported(multi_gpu_supported)
Validates that the model architecture supports multi-GPU inference.
-
Parameters:
-
multi_gpu_supported (bool) – Whether the model architecture supports multi-GPU inference.
-
Return type:
-
None
validate_repo_access()
validate_repo_access()
Validates that the model’s Hugging Face repo is accessible.
Deferred out of __init__ so a MAXModelConfig can be constructed
offline; invoked from PipelineConfig construction. A no-op when
weights are given explicitly (weight_path), when no model is
specified (a placeholder config), or when model_path is a local
path – there is no remote repo to check in those cases. Requiring a
model to actually run is enforced later, during architecture
resolution.
-
Raises:
-
ValueError – If the specified Hugging Face repo is inaccessible.
-
Return type:
-
None
vision_config_overrides
Model-specific vision configuration overrides.
weight_path
weight_path: list[Path]
The path or URL of the model weights to use.
weights_size()
weights_size()
Calculates the total size in bytes of all weight files in weight_path.
Attempts to find the weights locally first to avoid network calls, checking in the following order:
- If
repo_typeis"local", it checks if the path inweight_pathexists directly as a local file path. - Otherwise, if
repo_typeis"online", it first checks the local Hugging Face cache usinghuggingface_hub.try_to_load_from_cache(). If not found in the cache, it falls back to querying the Hugging Face Hub API viaHuggingFaceRepo.size_of().
Under header_only_weights the stubs are sized like the files they
stand in for, so their sizes are read straight off disk instead.
-
Returns:
-
The total size of all weight files in bytes.
-
Raises:
-
- FileNotFoundError – If
repo_typeis"local"and a file specified inweight_pathis not found within the local repo directory. - ValueError – If
HuggingFaceRepo.size_of()fails to retrieve the file size from the Hugging Face Hub API (for example, file metadata not available or API error). - RuntimeError – If the determined
repo_typeis unexpected.
- FileNotFoundError – If
-
Return type: