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 function

token_sampler

token_sampler()​

max.pipelines.sampling.token_sampler(sampling_config, device, return_logits=False, needs_bitmask_input=None, custom_extensions=(), unpadded_vocab_size=None)

source

Builds a sampling graph that samples tokens from logits.

Parameters:

  • sampling_config (SamplingConfig) – Sampling configuration (top-k, temperature and so on).
  • 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 bitmask input into the graph. See TopKSampler.
  • custom_extensions (Iterable[Path]) – Custom-op extension paths to compile the graph with. Empty by default.
  • unpadded_vocab_size (int | None) – The tokenizer’s token count. See TopKSampler.

Returns:

A graph that takes logits (and optional penalty inputs) and outputs tokens.

Return type:

Graph