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
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, 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.
Initialize, seeding private attrs and resolving the weight path.
Private attributes (PrivateAttr) arenβt accepted as constructor
kwargs by default, so we pop the seeded ones
(_huggingface_config, _weights_repo_id) here, then resolve
the weight-path identity eagerly.
-
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', 'gptq'] | None)
- huggingface_model_revision (str)
- huggingface_weight_revision (str)
- trust_remote_code (bool)
- subfolder (str | None)
- device_specs (list[DeviceSpec])
- force_download (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 (e.g.
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
Retrieves the Hugging Face GenerationConfig for this model.
Lazily loads the GenerationConfig from the model repository
and caches it to avoid repeated remote fetches.
-
Returns:
-
The
GenerationConfigfor the model, containing generation parameters includingmax_length,temperature, andtop_p. If loading fails, returns a defaultGenerationConfig.
graph_quantization_encodingβ
property graph_quantization_encoding: QuantizationEncoding | None
Converts the CLI encoding to a MAX Graph quantization encoding.
-
Returns:
-
The graph quantization encoding corresponding to the CLI encoding.
-
Raises:
-
ValueError β If no CLI encoding was specified.
huggingface_configβ
property huggingface_config: PreTrainedConfig
Returns the Hugging Face model config (loaded on first access).
For transformers models, returns the AutoConfig subclass. For
non-transformers models (e.g. diffusers components), falls back to
loading the raw config.json and wrapping it 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.
The result is cached in a PrivateAttr to avoid recreating
HuggingFaceRepo instances on every access. The cache is
invalidated when the underlying config fields change.
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.
The result is cached in a PrivateAttr to avoid recreating
HuggingFaceRepo instances (and triggering redundant HF API
calls for file listing, encoding detection, etc.) on every
access. The cache is invalidated when the underlying config
fields change (e.g. after model_copy()).
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 (e.g.
"main","draft","vae"). -
Return type:
-
None
max_lengthβ
The maximum sequence length the model can process.
model_configβ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', '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.
-
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 (e.g. 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_and_resolve_quantization_encoding_weight_path()β
validate_and_resolve_quantization_encoding_weight_path(default_encoding)
Verifies that the quantization encoding and weight path are consistent.
-
Parameters:
-
- weight_path β The path to the weight file.
- default_encoding (max.pipelines.lib.config.SupportedEncoding) β The default encoding to use if no encoding is provided.
-
Return type:
-
None
validate_and_resolve_with_resolved_quantization_encoding()β
validate_and_resolve_with_resolved_quantization_encoding(supported_encodings, default_weights_format)
Validates model path and weight path against resolved quantization encoding.
-
Parameters:
-
- supported_encodings (set[max.pipelines.lib.config.SupportedEncoding]) β A dictionary of supported encodings and their corresponding KV cache strategies.
- default_weights_format (WeightsFormat) β The default weights format to use if no weights format is provided.
-
Return type:
-
None
validate_lora_compatibility()β
validate_lora_compatibility()
Validates that LoRA configuration is compatible with model settings.
-
Raises:
-
ValueError β If LoRA is enabled but incompatible with current model configuration.
-
Return type:
-
None
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().
-
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:
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!