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

AutoProcessor

AutoProcessor​

class max.pipelines.AutoProcessor(model_path, *, revision=None, trust_remote_code=False)

source

Bases: object

Prepares chat conversations with images for AutoModel.

Calling it returns the messages and images that AutoModel.generate() takes, not Hugging Face’s input_ids and pixel_values. The model’s own tokenizer applies the chat template and expands each image at generate time, as serve does. Decoding uses the model’s Hugging Face tokenizer.

from PIL import Image

processor = AutoProcessor("google/gemma-3-4b-it")
model = AutoModel("google/gemma-3-4b-it", max_batch_size=2)
conversations = [
    [{"role": "user", "content": [
        {"type": "image", "image": Image.open("cat.png")},
        {"type": "text", "text": "Describe this image."},
    ]}],
    [{"role": "user", "content": "What is 2 + 2?"}],
]
outputs = model.generate(**processor(conversations), max_new_tokens=32)
new_tokens = [
    sequence[length:]
    for sequence, length in zip(
        outputs.sequences, outputs.prompt_lengths
    )
]
print(processor.batch_decode(new_tokens, skip_special_tokens=True))

Parameters:

  • model_path (str) – A Hugging Face repo ID or a local model directory.
  • revision (str | None) – The repo revision to load.
  • trust_remote_code (bool) – Whether to run tokenizer code from the repo.

batch_decode()​

batch_decode(sequences, *, skip_special_tokens=False)

source

Returns the text for each token-id list in sequences.

Parameters:

Return type:

list[str]

decode()​

decode(token_ids, *, skip_special_tokens=False)

source

Returns the text for token_ids.

Parameters:

Return type:

str