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
AutoModel
AutoModel
class max.pipelines.AutoModel(model_path, *, max_batch_size=1, devices=None, device_graph_capture=False, **config_overrides)
Bases: object
Loads a text generation model in-process.
Unlike Hugging Face’s base-model AutoModel, this one generates. The
Hugging Face equivalent is AutoModelForCausalLM. Serving features are
tested through max serve.
The config turns off the overlap scheduler, device graph capture, prefix
caching and chunked prefill. On AMD it also turns off the vendor BLAS
fallback, as serve does with capture on, so matmuls compile to serve’s
kernels. As in serve, the architecture’s required_arguments win over
the overrides.
References to the pipeline, its KV cache manager, an open
GenerateIterator, or a live traceback
from inside the pipeline keep device memory alive past close().
-
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, fixed at
construction. With
device_graph_capture=True, warmup captures decode graphs for every batch size up to this value, so a larger value costs more warmup time and device memory. - devices (str | None) – The devices to load on, written as the CLI’s
--devicestakes them, such as"cpu","gpu:0"or"gpu:0,1". Defaults to the first visible device. - device_graph_capture (bool) – Builds the overlap pipeline and runs its
warmup_graph_capture(), so decode steps replay captured graphs. Steps stay synchronous unlessenable_overlap_scheduler=Trueis also passed. - **config_overrides (object) – Flat
PipelineArgsfield names, such asdevice_specsorenable_prefix_caching. They win over the debug defaults.
-
Raises:
-
- TypeError – If both
devicesanddevice_specsare passed, if an override passes aruntime,kv_cacheormodelsection, or aconfig_file, instead of flat fields, or amodel_overrideentry sets one of them whole. - ValueError – If the config needs a feature that only
max serveruns, such as LoRA, if the model takes image inputs or does not generate text, or ifdevice_graph_capture=Truebuilds a pipeline that cannot capture graphs.
- TypeError – If both
close()
close()
Shuts down the KV cache manager and releases the pipeline.
Calling it again does nothing. The pipeline is released even if the shutdown raises.
-
Return type:
-
None
generate()
generate(input_ids, attention_mask=None, *, max_new_tokens, min_new_tokens=None, temperature=None, top_k=None, top_p=None, min_p=None, frequency_penalty=None, presence_penalty=None, repetition_penalty=None, ignore_eos=False, stop_token_ids=None, seed=0, output_logits=False, output_logprobs=0)
Runs generate() on pipeline.
Takes the same arguments, so model.generate(**tokenizer(prompts), max_new_tokens=16) works with an AutoTokenizer.
-
Raises:
-
- TypeError – As described for
generate(). - ValueError – As described for
generate(). - RuntimeError – If the model has been closed, or as described for
generate().
- TypeError – As described for
-
Parameters:
-
- input_ids (Iterable[Sequence[int]])
- attention_mask (Iterable[Sequence[int]] | None)
- max_new_tokens (int)
- min_new_tokens (int | None)
- temperature (float | None)
- top_k (int | None)
- top_p (float | None)
- min_p (float | None)
- frequency_penalty (float | None)
- presence_penalty (float | None)
- repetition_penalty (float | None)
- ignore_eos (bool)
- stop_token_ids (Sequence[int] | None)
- seed (int)
- output_logits (bool)
- output_logprobs (int)
-
Return type:
generate_iter()
generate_iter(input_ids, attention_mask=None, *, max_new_tokens, min_new_tokens=None, temperature=None, top_k=None, top_p=None, min_p=None, frequency_penalty=None, presence_penalty=None, repetition_penalty=None, ignore_eos=False, stop_token_ids=None, seed=0, output_logits=False, output_logprobs=0)
Opens a GenerateIterator on pipeline.
Takes the same keyword arguments. Use it as a context manager so its rows are released.
-
Raises:
-
- TypeError – As described for
GenerateIterator. - ValueError – As described for
GenerateIterator. - RuntimeError – If the model has been closed, or as described for
GenerateIterator.
- TypeError – As described for
-
Parameters:
-
- input_ids (Iterable[Sequence[int]])
- attention_mask (Iterable[Sequence[int]] | None)
- max_new_tokens (int)
- min_new_tokens (int | None)
- temperature (float | None)
- top_k (int | None)
- top_p (float | None)
- min_p (float | None)
- frequency_penalty (float | None)
- presence_penalty (float | None)
- repetition_penalty (float | None)
- ignore_eos (bool)
- stop_token_ids (Sequence[int] | None)
- seed (int)
- output_logits (bool)
- output_logprobs (int)
-
Return type:
pipeline
property pipeline: TextGenerationPipelineInterface[TextContext]
The loaded pipeline.
-
Raises:
-
RuntimeError – If the model has been closed.
pipeline_config
property pipeline_config: PipelineConfig
The resolved config that built the pipeline.