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 module

max.pipelines.context

Concrete context classes​

TextContextA base class for model context, specifically for Text model variants.
TextAndVisionContextA base class for model context, specifically for Vision model variants.
PixelContextA model-ready context for image/video generation requests.

Generation status​

GenerationStatusEnum representing the status of a generation process in the MAX API.

Constants​

FUTURE_TOKENint([x]) -> integer int(x, base=10) -> integer

Context protocols​

BaseContextCore interface for request lifecycle management across all of MAX, including serving, scheduling, and pipelines.

Type variables​

BaseContextTypeType variable.
TextGenerationContextTypeType variable.
VLMContextTypeType variable.
PixelGenerationContextTypeType variable.

Sampling​

SamplingParamsRequest specific sampling parameters that are only known at run time.
SamplingParamsInputInput dataclass for creating SamplingParams instances.
SamplingParamsGenerationConfigDefaultsDefault sampling parameter values extracted from a model's GenerationConfig.

Output types​

TextGenerationOutputRepresents the output of a text generation operation.
GenerationOutputOutput container for image generation pipeline operations.
TextGenerationResponseFormatRepresents the response format specification for a text generation request.
LogProbabilitiesLog probabilities for an individual output token.

Token management​

TokenBufferA dynamically resizable container for managing token sequences.
ImageMetadataMetadata about an image in the prompt.
RangeRepresents a range with start and end indices.
TokenSlicendarray(shape, dtype=float, buffer=None, offset=0,

Grammar and structured output​

GrammarEnforcementStateManages grammar enforcement state for constrained decoding.
GrammarEnforcementSnapshotCaptured grammar-enforcement state for rollback.
StructuredOutputRegionDelimitersToken ID sequences that define structured output boundaries.

Speculative decoding​

SpecDecodingStatePer-request state for speculative decoding.

EOS tracking​

EOSTrackerCentralized EOS tracking: single-ID, sequence-ID, and stop-sequence checks.

Logits processors​

LogitsProcessoralias of Callable[[ProcessorInputs], None]
BatchLogitsProcessoralias of Callable[[BatchProcessorInputs], None]
ProcessorInputsInputs passed to a logits processor callback.
BatchProcessorInputsArguments for a batch logits processor.

Exceptions​

InputErrorException raised for input validation errors that should be shown to users.
PromptTooLongErrorRaised when a prompt exceeds the model's maximum input length.

Validation functions​

validate_aspect_ratio_argsValidates that required aspect ratio arguments are present for vision input.
validate_flux2_max_pixel_areaRejects FLUX2 requests whose width * height exceeds the per-arch cap.
validate_image_grid_thw_argsValidates that image_grid_thw is present when vision encoding is needed.
validate_image_shape_5dValidates that images have the expected 5-dimensional shape.
validate_initial_prompt_has_imageValidates that initial prompts contain an image for vision models.
validate_only_one_imageValidates that at most one image is provided in the context.
validate_requires_vision_contextValidates that the context is a TextAndVisionContext.
validate_vision_position_idsValidates that vision_position_ids is present when vision encoding is needed.
validate_wan_max_pixel_areaRejects WAN requests whose width * height exceeds the per-arch cap.