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
SupportedArchitecture
SupportedArchitecture
class max.pipelines.lib.arch_lookup.SupportedArchitecture(name, example_repo_ids, default_encoding, supported_encodings, task, tokenizer, default_weights_format, context_type, config, weight_adapters=<factory>, weight_rules=None, tokenizer_artifacts=None, use_weight_rules=False, weight_rules_for_artifacts_only=False, multi_gpu_supported=False, input_modalities=<factory>, required_arguments=<factory>, checkpoints_recurrent_state=False, prefix_caching_under_spec=True, context_validators=<factory>, supports_empty_batches=False, requires_max_batch_context_length=False, tool_parser=None, format_spec=None, mach_only=False, tokenizer_family=None, batching=None, reasoning_parser=None, default_structured_output_backend=None, default_structured_output_any_whitespace=None, denoising_cache_defaults=None, checkpoint_draft_width=None, draft_architectures=<factory>, checkpoint_drafts=<factory>, spec_decode_graph_names=<factory>, supports_overlap_scheduler=True, supports_nvfp4_kv_cache=False, supports_device_graph_capture=True, supports_spec_decode_mixed_batches=False, cascade_pipeline_factory=None, pipeline_cls=None, *, pipeline_model=None, modules=<factory>, draft=None)
Bases: object
Represents a model architecture configuration for MAX pipelines.
Defines the components and settings required to support a specific model architecture within the MAX pipeline system. Each SupportedArchitecture instance encapsulates the model implementation, tokenizer, supported encodings, and other architecture-specific configuration.
New architectures should be registered into the PipelineRegistry
using the register() method.
For example, define the components of a custom architecture:
from max.graph.weights import WeightsFormat
from max.pipelines.context import TextContext
from max.pipelines.lib.interfaces.pipeline_model import (
ModelOutputs,
PipelineModel,
)
from max.pipelines.lib.registry import SupportedArchitecture
from max.pipelines.lib.tokenizer import TextTokenizer
from max.pipelines.modeling.types import PipelineTask
# itself, so it is never instantiated here.
class MyModel(PipelineModel[TextContext]):
def execute(self, model_inputs) -> ModelOutputs:
raise NotImplementedError
class MyModelConfig:
pass
my_architecture = SupportedArchitecture(
name="MyModelForCausalLM", # Must match your Hugging Face model class name
example_repo_ids=[
"your-org/your-model-name", # Add example model repository IDs
],
default_encoding="q4_k",
supported_encodings={
"q4_k",
"bfloat16",
# Add other encodings your model supports
},
pipeline_model=MyModel,
tokenizer=TextTokenizer,
context_type=TextContext,
config=MyModelConfig, # Architecture-specific config class
default_weights_format=WeightsFormat.safetensors,
multi_gpu_supported=True, # Set based on your implementation capabilities
required_arguments={"some_arg": True},
task=PipelineTask.TEXT_GENERATION,
)-
Parameters:
-
- name (str)
- example_repo_ids (list[str])
- default_encoding (SupportedEncoding)
- supported_encodings (set[SupportedEncoding])
- task (PipelineTask)
- tokenizer (Callable[..., PipelineTokenizer[Any, Any, Any]])
- default_weights_format (WeightsFormat)
- context_type (type[TextContext | EmbeddingsContext | PixelContext | AudioContext])
- config (type[ArchConfig])
- weight_adapters (dict[WeightsFormat, WeightsAdapter])
- weight_rules (Callable[[PretrainedConfig], Sequence[WeightRule]] | None)
- tokenizer_artifacts (Callable[[], tuple[str, str | None]] | None)
- use_weight_rules (bool)
- weight_rules_for_artifacts_only (bool)
- multi_gpu_supported (bool)
- input_modalities (set[InputModality])
- required_arguments (dict[str, bool | int | float])
- checkpoints_recurrent_state (bool)
- prefix_caching_under_spec (bool)
- context_validators (list[Callable[[TextContext | TextAndVisionContext | PixelContext], None]])
- supports_empty_batches (bool)
- requires_max_batch_context_length (bool)
- tool_parser (str | Callable[[HuggingFaceRepo], str] | None)
- format_spec (Path | Callable[[HuggingFaceRepo], Path | None] | None)
- mach_only (bool)
- tokenizer_family (tuple[str, str | None] | Callable[[HuggingFaceRepo], tuple[str, str | None] | None] | None)
- batching (type[Any] | None)
- reasoning_parser (str | None)
- default_structured_output_backend (str | None)
- default_structured_output_any_whitespace (bool | None)
- denoising_cache_defaults (TaylorSeerDefaults | None)
- checkpoint_draft_width (Callable[[SpeculativeConfig, Any, Any], int] | None)
- draft_architectures (Mapping[str, Mapping[str, str]])
- checkpoint_drafts (Mapping[str, str])
- spec_decode_graph_names (Mapping[str, str])
- supports_overlap_scheduler (bool)
- supports_nvfp4_kv_cache (bool)
- supports_device_graph_capture (bool)
- supports_spec_decode_mixed_batches (bool)
- cascade_pipeline_factory (Callable[[PipelineConfig], object] | None)
- pipeline_cls (type | None)
- pipeline_model (PipelineModelType | None)
- modules (Mapping[str, type[Module[..., Any] | GraphApiModule]])
- draft (DraftRegistration[Any, Any] | None)
batching
Optional batch processor for input/output handling.
When set, must be a BatchProcessor
subclass. The processor class is applied to pipeline_model at
registration time via batch_processor_cls.
Ragged text models should subclass
RaggedBatchProcessor.
Every token-generation model needs a batch processor. It’s easiest to
use or subclass an existing one (for example,
batching=Llama3BatchProcessor).
from max.pipelines.lib.interfaces.batch_processor import (
SingleReplicaRaggedBatchProcessor,
)
class MyBatchProcessor(SingleReplicaRaggedBatchProcessor):
def _make_inputs(
self,
*,
tokens,
input_row_offsets,
return_n_logits,
kv_cache_inputs,
signal_buffers,
):
... # Build the ModelInputs.
# Pass ``batching=MyBatchProcessor`` to ``SupportedArchitecture``
# when registering the architecture.cascade_pipeline_factory
cascade_pipeline_factory: Callable[[PipelineConfig], object] | None = None
Optional cascade pipeline factory for this architecture.
A CascadePipeline subclass (from max.experimental.cascade) that
accepts a PipelineConfig in its constructor. The experimental
cascade server resolves the architecture and constructs
cascade_pipeline_factory(config), so cascade pipeline selection is
driven entirely by the architecture rather than by PipelineTask.
The return is annotated object rather than CascadePipeline because
the cascade layer sits above max.pipelines; importing the base
class here to tighten the annotation would invert that dependency (the
cascade server narrows the constructed value back to CascadePipeline).
None means the architecture has no cascade pipeline yet.
checkpoint_adapters()
checkpoint_adapters(huggingface_config, *, artifact_export)
Returns the adapters a pipeline loads the checkpoint through.
-
Parameters:
-
- huggingface_config (PretrainedConfig) – The checkpoint’s config, which
weight_rulesreads. - artifact_export (bool) – Whether the pipeline is built for a pipeline
artifact (
PipelineConfig.artifact_export), whichweight_rules_for_artifacts_onlyreads.
- huggingface_config (PretrainedConfig) – The checkpoint’s config, which
-
Raises:
-
ValueError – If
use_weight_rulesis set withoutweight_rules. -
Return type:
checkpoint_draft_width
checkpoint_draft_width: Callable[[SpeculativeConfig, Any, Any], int] | None = None
Returns the draft width this checkpoint was trained for.
Set it when the checkpoint fixes the width rather than the user.
checkpoint_drafts
The draft architecture this target’s own checkpoint ships, by
speculative method, as vLLM’s hf_config_override names an MTP draft
from its target’s model type.
checkpoints_recurrent_state
checkpoints_recurrent_state: bool = False
Whether this architecture carries recurrent state a prefix hit must resume.
A prefix hit is safe only where the state that consumed exactly that prefix is restored with it.
config
config: type[ArchConfig]
The architecture-specific configuration class for the model.
This class must implement the ArchConfig protocol, providing an
initialize method that creates a configuration instance from a
PipelineConfig. For models with KV cache, this should be a class
implementing ArchConfigWithKVCache to enable KV cache memory estimation.
context_type
context_type: type[TextContext | EmbeddingsContext | PixelContext | AudioContext]
The context class type that this architecture uses for managing request state and inputs.
This should be a class (not an instance) carrying the state and inputs of one request, in whichever form the architecture’s task calls for: a TextContext or EmbeddingsContext protocol implementation for token and embedding models, or a PixelContext or AudioContext subclass for the media tasks.
context_validators
context_validators: list[Callable[[TextContext | TextAndVisionContext | PixelContext], None]]
A list of callable validators that verify context inputs before model execution.
These validators are called during context creation to ensure inputs meet model-specific requirements. Validators should raise InputError for invalid inputs, providing early error detection before expensive model operations.
from max.pipelines.context import TextAndVisionContext, TextContext
from max.pipelines.context.exceptions import InputError
def validate_single_image(context: TextContext | TextAndVisionContext) -> None:
if isinstance(context, TextAndVisionContext):
if context.pixel_values and len(context.pixel_values) > 1:
raise InputError(f"Model supports only 1 image, got {len(context.pixel_values)}")
# Pass ``context_validators=[validate_single_image]`` to
# ``SupportedArchitecture`` when registering the architecture.
validators = [validate_single_image]default_encoding
default_encoding: SupportedEncoding
The default quantization encoding to use when no specific encoding is requested.
default_structured_output_any_whitespace
default_structured_output_any_whitespace: bool | None = None
Optional default for whitespace-tolerant structured-output grammars.
When set, the pipeline config will use this value for
sampling.structured_output_any_whitespace if the user did not
explicitly configure one. False constrains response_format
generation to compact JSON (the runaway-generation mitigation);
True lets the grammar accept whitespace between JSON tokens, which
some models need at structural boundaries.
If None, the global default (compact JSON) is used.
default_structured_output_backend
Optional default structured output backend for this architecture.
When set to "xgrammar", the pipeline config
will use this value for sampling.structured_output_backend if the
user did not explicitly configure one. This allows architectures that
work better with a specific backend to override the global default.
If None, the global default from SamplingConfig is used.
default_weights_format
default_weights_format: WeightsFormat
The weights format expected by the pipeline_model.
denoising_cache_defaults
denoising_cache_defaults: TaylorSeerDefaults | None = None
TaylorSeer tuning for this architecture. User-set fields always win.
draft
draft: DraftRegistration[Any, Any] | None = None
The registered draft’s construction and proposer contract.
A draft-only architecture has no standalone pipeline model. An architecture with both roles serves its decoder normally until speculation is requested.
draft_architecture()
draft_architecture(method, checkpoint_name)
Returns the registered draft architecture of a draft checkpoint.
draft_architectures
The draft architecture registered for a draft checkpoint served beside this target, by speculative method and then by the architecture name the checkpoint declares.
A checkpoint may declare a name several drafts share, so the target picks the draft whose module it can call. A name not listed stands for itself.
example_repo_ids
A list of Hugging Face repository IDs that use this architecture for testing and validation purposes.
format_spec
format_spec: Path | Callable[[HuggingFaceRepo], Path | None] | None = None
Optional FormatSpec document for this architecture’s checkpoints.
The path of the JSON document describing the tool-call and reasoning
format a checkpoint was trained with, or a callable that takes the
model’s HuggingFaceRepo handle and returns that path, or
None when the checkpoint has none. Use the callable form when one
architecture serves checkpoints with different formats. max export
copies the document into the pipeline artifact.
If None, the artifact carries no FormatSpec and tool calls are served unconstrained.
input_modalities
input_modalities: set[InputModality]
The set of input modalities this architecture accepts.
Defaults to text-only. Multimodal architectures should declare all
supported input types explicitly, such as
{InputModality.TEXT, InputModality.IMAGE} for vision-language models.
mach_only
mach_only: bool = False
Whether only Mach serves this architecture.
max export builds its pipeline artifact for Mach, and max serve
refuses the architecture with an error that points to Mach.
modules
modules: Mapping[str, type[Module[..., Any] | GraphApiModule]]
The module class of each role the architecture fills, keyed by
GraphRole.
The framework constructs each as module_cls(config) from the
finalized config, and its forward (__call__ for a
graph-API Module) takes and returns the role’s
contract from max.pipelines.lib.role_contracts. A DRAFT is a
component of a speculative pairing, constructed through draft,
and has no standalone serving pipeline.
multi_gpu_supported
multi_gpu_supported: bool = False
Whether the architecture supports multi-GPU execution.
name
name: str
The name of the model architecture that must match the Hugging Face model class name.
pipeline_cls
Optional pipeline class overriding the task-based default from
get_pipeline_for_task().
Most architectures leave this None and are driven by the standard
task pipelines. Set it when an architecture needs a bespoke generation
loop that the stock one-token-per-step
TextGenerationPipeline
cannot express — for example block-diffusion text generation, which runs
an encoder pass plus an inner denoising loop and emits a whole token
block per scheduler step. The value must be a
TextGenerationPipeline
subclass (or compatible) selected in retrieve_factory.
pipeline_model
pipeline_model: PipelineModelType | None = None
The model class that defines the graph structure and execution logic.
Accepts either a PipelineModel subclass (for LLM and other
token-generation architectures) or a PipelineExecutor subclass
(for newer executor-based architectures such as diffusion pipelines).
None for a draft architecture that only runs beside a target, inside
a unified spec-decode graph: it registers for config resolution, and
builds its module through its config class.
An architecture that registers modules leaves this unset, and
the framework builds it from the registration.
prefix_caching_under_spec
prefix_caching_under_spec: bool = True
Whether a ModuleV3 pairing that speculates over this recurrent target keeps prefix caching on.
Read only when checkpoints_recurrent_state is set: a graph-API
recurrent target always turns it off under speculation.
reasoning_parser
Optional default reasoning parser name for this architecture.
The name must correspond to a parser registered via
max.pipelines.lib.reasoning.register(). When set, the pipeline
config will fall back to this value for runtime.reasoning_parser if
the user did not explicitly configure one. Different model architectures
emit reasoning content in different formats (for example, Kimi K2.5 wraps
reasoning in <think>...</think>), so the appropriate default is
architecture-specific.
If None, no reasoning parser is enabled by default and the user must
opt in by setting runtime.reasoning_parser explicitly.
required_arguments
A dictionary specifying required values for PipelineConfig options.
requires_max_batch_context_length
requires_max_batch_context_length: bool = False
Whether the architecture requires a max batch context length to be specified.
If True and max_batch_context_length is not specified, we will default to the max sequence length of the model.
spec_decode_graph_names
The names an engine looks the fused graph up by, under the draft’s
architecture name or the speculative method. A pairing not listed is named
unified_{method}.
supported_encodings
supported_encodings: set[SupportedEncoding]
A dictionary of supported quantization encodings.
supports_device_graph_capture
supports_device_graph_capture: bool = True
Whether this architecture supports auto-enabling device graph capture.
When False, device graph capture is not auto-enabled for this
architecture even when otherwise eligible. Users can still force-enable
via --device-graph-capture --force.
supports_empty_batches
supports_empty_batches: bool = False
Whether the architecture can handle empty batches during inference.
When set to True, the pipeline can process requests with zero-sized batches without errors. This is useful for certain execution modes and expert parallelism. Most architectures do not require empty batch support and should leave this as False.
supports_nvfp4_kv_cache
supports_nvfp4_kv_cache: bool = False
Whether this architecture implements kv_cache_format="float4_e2m1fn".
An NVFP4 cache stores packed values with scales that only an architecture’s own writer and attention ops know how to handle, so the format is rejected at config time for every architecture that does not opt in.
supports_overlap_scheduler
supports_overlap_scheduler: bool = True
Whether this architecture supports auto-enabling the overlap scheduler.
When False, the overlap scheduler is not auto-enabled for this
architecture even when otherwise eligible. Users can still enable it
via --enable-overlap-scheduler.
supports_spec_decode_mixed_batches
supports_spec_decode_mixed_batches: bool = False
Whether this architecture’s speculative graph is per-row correct on mixed prefill+decode verify batches.
When False, --enable-spec-decode-mixed-batches falls back to
plain in-flight batching for this architecture.
task
task: PipelineTask
The pipeline task type that this architecture supports.
tokenizer
tokenizer: Callable[..., PipelineTokenizer[Any, Any, Any]]
A callable that returns a PipelineTokenizer instance for preprocessing model inputs.
tokenizer_artifacts
tokenizer_artifacts: Callable[[], tuple[str, str | None]] | None = None
The repo and revision this architecture’s tokenizer files load from.
None, the default, loads them from the checkpoint’s own repo at the
configured revision. A release that ships weights and metadata only names
the sibling repo its tokenizer.json, tokenizer_config.json and chat
template come from, at the revision they are pinned to: the returned
revision, or the configured one when it is empty, so a deployment boots
one tokenizer whatever the checkpoint’s main moves to.
tokenizer_cls
property tokenizer_cls: type[PipelineTokenizer[Any, Any, Any]]
Returns the tokenizer class for this architecture.
tokenizer_family
tokenizer_family: tuple[str, str | None] | Callable[[HuggingFaceRepo], tuple[str, str | None] | None] | None = None
Optional orchestrator tokenizer family for this architecture’s checkpoints.
The family and flavor the orchestrator builds its fast-path tokenizer
from, such as ("gemma4", "thinking") or ("llama3", None) for a
family with one flavor, or a callable that takes the model’s
HuggingFaceRepo handle and returns them, or None for a
checkpoint with no family code. max export records them in the
pipeline artifact’s tokenizer section.
If None, the artifact names no family, and the orchestrator picks it by model name as it does without an artifact.
tokenizer_source()
tokenizer_source(model_config)
The (repo_id, revision) this architecture’s tokenizer loads from.
tool_parser
tool_parser: str | Callable[[HuggingFaceRepo], str] | None = None
Optional default tool parser for this architecture.
Either a registered parser name (str), or a callable that takes the
model’s HuggingFaceRepo handle (carrying repo_id,
revision, subfolder, and trust_remote_code) and returns a
registered parser name. Use the callable form when one architecture
name covers multiple checkpoint revisions with different tool-call
grammars (for example, DeepSeek V3 vs V3.1). The callable is invoked
once during pipeline config resolution and the resulting string is
stored on runtime.tool_parser.
The returned name must correspond to a parser registered via
max.pipelines.lib.tool_parsing.register(). When set, the
pipeline config falls back to this value for runtime.tool_parser
if the user did not explicitly configure one.
If None, no tool parser is enabled by default and the serving layer falls back to its baseline parser.
use_weight_rules
use_weight_rules: bool = False
Whether the pipeline loads the checkpoint through weight_rules
rather than weight_adapters.
weight_adapters
weight_adapters: dict[WeightsFormat, WeightsAdapter]
A dictionary of weight format adapters for converting checkpoints from different formats to the default format.
weight_rules
weight_rules: Callable[[PretrainedConfig], Sequence[WeightRule]] | None = None
Returns the rules that map a checkpoint in default_weights_format
onto the graph’s weights, given the checkpoint’s Hugging Face config.
The pipeline builds one WeightTransform from the
rules, loads the checkpoint through it, and exports it with the pipeline.
Checkpoints in other formats keep their weight_adapters.
weight_rules_for_artifacts_only
weight_rules_for_artifacts_only: bool = False
Whether use_weight_rules applies only to a pipeline artifact
export (PipelineConfig.artifact_export). Every other load, serving
and bare MEF exports included, keeps weight_adapters and the
weight and graph contract they produce, while an architecture migrates
to its artifact.