Skip to main content
SamplingParams is a Python dataclass that bundles the generation hyperparameters for a single inference request. One SamplingParams instance is attached to every Sequence and consulted by the Scheduler to determine when to stop generation.

Definition

Fields

float
default:"1.0"
Softmax temperature applied before multinomial sampling. Higher values increase randomness; lower values make the distribution more peaked.
Greedy decoding (temperature = 0) is not supported. Setting temperature to any value <= 1e-10 raises an AssertionError in __post_init__.
int
default:"64"
Maximum number of completion tokens to generate. The prompt tokens are not counted. Generation stops as soon as num_completion_tokens >= max_tokens, regardless of whether EOS has been sampled.
bool
default:"false"
When False (default), generation stops as soon as the EOS token ID configured in LLMEngine is sampled. When True, EOS tokens are treated as ordinary tokens and generation continues until max_tokens or max_model_length is reached.
int | None
default:"None"
Maximum total sequence length, counting both prompt and completion tokens. When set, generation stops as soon as num_tokens >= max_model_length. None means no total-length limit (only max_tokens applies).

Stopping conditions

The Scheduler checks three independent stopping conditions after each decode step. Generation halts as soon as any condition is satisfied:

Validation

SamplingParams validates its fields in __post_init__, which runs automatically on construction:
Greedy decoding is explicitly unsupported. Passing temperature=0 raises:
Use a small positive temperature such as 0.01 instead if near-deterministic output is needed.

Usage examples