struct

Fm::SamplingMode

Inherits Struct < Value < Object

Advanced sampling mode with top-k and top-p (nucleus) parameters.

mode = Fm::SamplingMode.greedy
mode = Fm::SamplingMode.random(top: 40, seed: 42_u64)
mode = Fm::SamplingMode.random(probability_threshold: 0.9)

Constructors

from_sampling(sampling : Sampling) : self

Creates a SamplingMode from a simple Sampling enum (for backward compatibility).

Source
greedy

Greedy (deterministic) sampling: always pick the most likely token.

Source
random(*, top : Int32 | Nil = nil, probability_threshold : Float64 | Nil = nil, seed : UInt64 | Nil = nil) : self

Random sampling with optional top-k, top-p, and seed.

NOTE: top and probability_threshold cannot both be specified. NOTE: seed alone (without top or probability_threshold) is not supported by Apple's FoundationModels API and will be ignored.

Source

Instance methods

probability_threshold

Top-p (nucleus sampling): only consider tokens whose cumulative probability exceeds this threshold (0.0-1.0, Random only). Cannot be combined with top.

Source
seed

Seed for reproducible generation (Random only).

Source
strategy

The base strategy: Random or Greedy.

Source
top

Top-k: only consider the top k most likely tokens (Random only). Cannot be combined with probability_threshold.

Source