IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Python class

AutoPipeline

AutoPipeline​

class max.pipelines.AutoPipeline(model_path, *, max_batch_size=1, devices=None, device_graph_capture=False, prefer_module_v3=True, eager=False, **config_overrides)

source

Bases: object

Generates text or images with an AutoModel.

For a text model, a string prompt goes to the model as is, without a chat template, and its output starts with the prompt exactly as passed. A conversation, in the message format AutoProcessor takes, goes through the chat template with its images, and its output is only the new text. For an image model, each prompt becomes a list of PIL images, through generate() with prompt.

pipe = AutoPipeline("HuggingFaceTB/SmolLM2-135M", max_batch_size=2)
texts = pipe(
    ["The capital of France is", "2 + 2 ="], max_new_tokens=16
)
print(texts)

A conversation can hold images.

from PIL import Image

pipe = AutoPipeline("google/gemma-3-4b-it")
text = pipe(
    [{"role": "user", "content": [
        {"type": "image", "image": Image.open("cat.png")},
        {"type": "text", "text": "Describe this image."},
    ]}],
    max_new_tokens=32,
)
print(text)

An image model takes the image arguments of generate().

pipe = AutoPipeline("black-forest-labs/FLUX.2-klein-4B")
images = pipe("a red fox in snow", height=512, width=512)
images[0].save("fox.png")

Parameters:

  • model_path (str) – A Hugging Face repo ID or a local model directory.
  • max_batch_size (int) – The most prompts per data-parallel replica, as for AutoModel.
  • devices (str | None) – The devices to load on, as for AutoModel.
  • device_graph_capture (bool) – Whether decode steps replay captured graphs, as for AutoModel.
  • prefer_module_v3 (bool) – Whether to load the architecture’s ModuleV3 version, as for AutoModel.
  • eager (bool) – Whether the decoder runs op by op instead of compiled, as for AutoModel.
  • **config_overrides (object) – Flat PipelineArgs field names. A text model’s tokenizer loads with the revision and trust_remote_code of the resolved config.

Raises:

close()​

close()

source

Closes the model, as close() does.

Return type:

None

model​

property model: AutoModel

source

The model that generates the tokens.

tokenizer​

property tokenizer: AutoTokenizer

source

The tokenizer that encodes prompts and decodes outputs.

Raises:

ValueError – If the model generates images, which takes no text tokenizer.