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)
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:
batch_decode()
batch_decode(sequences, *, skip_special_tokens=False)
Returns the text for each token-id list in sequences.
decode()
decode(token_ids, *, skip_special_tokens=False)
Returns the text for token_ids.