IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/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. /max/get-started.md).

Mojo function

min_p_sampling

def min_p_sampling[dtype: DType, out_idx_type: DType, //, _test_sort: Bool = False](min_ps: TileTensor[dtype, Storage=min_ps.Storage, address_space=min_ps.address_space, linear_idx_type=min_ps.linear_idx_type], input_logits: TileTensor[dtype, Storage=input_logits.Storage, address_space=input_logits.address_space, linear_idx_type=input_logits.linear_idx_type], out_token_ids: TileTensor[out_idx_type, Storage=out_token_ids.Storage, address_space=out_token_ids.address_space, linear_idx_type=out_token_ids.linear_idx_type], temperature: Scalar[dtype] = 1)

Naive CPU implementation of Min-P sampling for token selection. This function applies temperature scaling, softmax, a merge sort, and then samples tokens based on the calculated probability threshold (Min-P).

Parameters:

  • โ€‹dtype (DType): Element type of input_logits, min_ps, and temperature (inferred).
  • โ€‹out_idx_type (DType): Element type of the out_token_ids tensor (inferred).
  • โ€‹_test_sort (Bool): When true, copies the sorted probabilities back into input_logits to verify descending order (defaults to false).

Was this page helpful?