Skip to main content

Overview

Sampling parameters control how the model generates text. They affect randomness, diversity, length, and structure of the output.

Quick Reference

Token Generation

max_new_tokens

int
default:"128"
Maximum number of tokens to generate.

min_new_tokens

int
default:"0"
Minimum number of tokens to generate before allowing stop sequences or EOS.

ignore_eos

bool
default:"false"
Continue generation even after EOS token is generated.

Randomness Control

temperature

float
default:"1.0"
Controls randomness. Lower values (0.0-0.5) make output more focused and deterministic. Higher values (0.8-2.0) make output more creative and diverse.Setting to 0.0 enables greedy decoding (always pick most likely token).
Best Practices:
  • 0.0: Math, factual QA, code generation
  • 0.3-0.5: General assistant, summaries
  • 0.7-0.9: Creative writing, brainstorming
  • 1.0+: Experimental, high diversity needed

top_p (Nucleus Sampling)

float
default:"1.0"
Cumulative probability threshold for nucleus sampling. Only tokens with cumulative probability up to top_p are considered. Range: (0.0, 1.0]Lower values (0.1-0.5) produce more focused output. Higher values (0.9-1.0) allow more diversity.

top_k

int
default:"-1"
Only sample from the top K most likely tokens. Set to -1 to disable (consider all tokens).

min_p

float
default:"0.0"
Minimum probability threshold. Tokens with probability below min_p are filtered out. Range: [0.0, 1.0]

Repetition Control

frequency_penalty

float
default:"0.0"
Penalize tokens based on their frequency in the generated text. Higher values reduce repetition. Range: [-2.0, 2.0]Positive values: Discourage repetition Negative values: Encourage repetition

presence_penalty

float
default:"0.0"
Penalize tokens that have already appeared (regardless of frequency). Range: [-2.0, 2.0]Positive values: Encourage new topics Negative values: Stay on topic

repetition_penalty

float
default:"1.0"
Apply a penalty to tokens that have been generated. Range: [0.0, 2.0]Values > 1.0: Discourage repetition Value = 1.0: No penalty (default) Values < 1.0: Encourage repetition
Penalty Comparison:
  • frequency_penalty: Linear scaling based on token frequency
  • presence_penalty: Binary (appeared or not)
  • repetition_penalty: Multiplicative penalty on logits

Stop Conditions

stop

string | array
default:"null"
Stop generation when any of these strings are generated.

stop_token_ids

array[int]
default:"null"
Stop generation when any of these token IDs are generated.

stop_regex

string | array
default:"null"
Stop generation when output matches any of these regex patterns.

no_stop_trim

bool
default:"false"
If true, don’t remove the stop string from the output.

Structured Output

json_schema

string
default:"null"
JSON schema to constrain output. Ensures generated text is valid JSON matching the schema.

regex

string
default:"null"
Regular expression pattern to constrain output format.

ebnf

string
default:"null"
EBNF (Extended Backus-Naur Form) grammar to constrain output.

Advanced Parameters

n (Number of Completions)

int
default:"1"
Generate N independent completions for each prompt.

logit_bias

dict
default:"null"
Modify the likelihood of specific tokens. Keys are token IDs, values are bias adjustments. Range: Typically [-100, 100]

sampling_seed

int
default:"null"
Random seed for reproducible sampling. Set this for deterministic outputs.

skip_special_tokens

bool
default:"true"
Remove special tokens (BOS, EOS, PAD) from decoded output.

spaces_between_special_tokens

bool
default:"true"
Add spaces between special tokens when decoding.

Parameter Combinations

Creative Writing

Code Generation

Factual Q&A

JSON Generation

Diverse Brainstorming

Parameter Validation

SGLang validates parameters and raises errors for invalid values:
Validation Rules:
  • temperature >= 0.0
  • 0.0 < top_p <= 1.0
  • 0.0 <= min_p <= 1.0
  • top_k >= 1 or top_k == -1
  • -2.0 <= frequency_penalty <= 2.0
  • -2.0 <= presence_penalty <= 2.0
  • 0.0 <= repetition_penalty <= 2.0
  • 0 <= min_new_tokens <= max_new_tokens
  • Only one of json_schema, regex, ebnf can be set

See Also