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 function
token_sampler
token_sampler()β
max.pipelines.sampling.token_sampler(sampling_config, device, return_logits=False, needs_bitmask_input=None)
Builds a sampling graph that samples tokens from logits.
-
Parameters:
-
- sampling_config (SamplingConfig) β Sampling configuration (top-k, temperature, etc.).
- device (DeviceRef) β Device for the graph inputs and ops.
- return_logits (bool) β Whether the graph should expose logits as an output.
- needs_bitmask_input (bool | None) β Whether to wire a
bitmaskinput into the graph. WhenNone, falls back tosampling_config.enable_structured_output. Callers should passTrueexplicitly when tool-call grammars can fire even though--enable-structured-outputis off.
-
Returns:
-
A graph that takes logits (and optional penalty inputs) and outputs tokens.
-
Return type:
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!