sgl-project/sglang · error · ValueError

min_p must be in [0, 1], got {self.min_p}.

Error message

min_p must be in [0, 1], got {self.min_p}.

What it means

SamplingParams.verify() requires min_p to lie in [0, 1]. min_p is a minimum-probability threshold (relative to the top token's probability); values outside the unit interval are meaningless and raise this ValueError during normalize()/verify().

Source

Thrown at python/sglang/srt/sampling/sampling_params.py:164

        # Process some special cases
        if 0 <= self.temperature < _SAMPLING_EPS:
            # top_k = 1 means greedy sampling
            self.temperature = 1.0
            self.top_k = 1
        if self.top_k == -1:
            self.top_k = TOP_K_ALL  # whole vocabulary

    def verify(self, vocab_size):
        if self.beam_width is not None and self.beam_width < 1:
            raise ValueError(f"beam_width must be at least 1, got {self.beam_width}.")
        if not math.isfinite(self.temperature) or self.temperature < 0.0:
            raise ValueError(
                f"temperature must be a non-negative finite number, got {self.temperature}."
            )
        if not 0.0 < self.top_p <= 1.0:
            raise ValueError(f"top_p must be in (0, 1], got {self.top_p}.")
        if not 0.0 <= self.min_p <= 1.0:
            raise ValueError(f"min_p must be in [0, 1], got {self.min_p}.")
        if self.top_k < 1 or self.top_k == -1:
            raise ValueError(
                f"top_k must be -1 (disable) or at least 1, got {self.top_k}."
            )
        if not -2.0 <= self.frequency_penalty <= 2.0:
            raise ValueError(
                "frequency_penalty must be in [-2, 2], got "
                f"{self.frequency_penalty}."
            )
        if not -2.0 <= self.presence_penalty <= 2.0:
            raise ValueError(
                "presence_penalty must be in [-2, 2], got " f"{self.presence_penalty}."
            )
        if not 0.0 < self.repetition_penalty <= 2.0:
            raise ValueError(
                "repetition_penalty must be in (0, 2] (1.0 = no penalty), "
                f"got {self.repetition_penalty}."
            )

View on GitHub (pinned to 0132848349)

Solutions

  1. Keep min_p in [0, 1]; typical useful range is 0.0-0.3
  2. If your value is a percentage, divide by 100 before passing
  3. Set min_p=0.0 (or omit) to disable the filter

Example fix

# before
params = SamplingParams(min_p=15)  # percent scale, invalid
# after
params = SamplingParams(min_p=0.15)
Defensive patterns

Strategy: validation

Validate before calling

min_p = min_p if isinstance(min_p,(int,float)) and 0.0 <= min_p <= 1.0 else 0.0
params = SamplingParams(min_p=min_p)

Type guard

def valid_min_p(p):
    return isinstance(p,(int,float)) and 0.0 <= p <= 1.0

Try / catch

try:
    llm.generate(prompts, SamplingParams(min_p=p))
except ValueError as e:
    if 'min_p' in str(e):
        p = 0.0
    else:
        raise

Prevention

When it happens

Trigger: Passing SamplingParams(min_p=-0.1) or min_p=1.2; verify() runs via normalize() on every request containing min_p.

Common situations: Tuning min_p from papers/blogs that use different scales (e.g. percent 0-100 instead of 0-1); arithmetic on min_p overshooting 1; confusing min_p with min_tokens or presence_penalty ranges.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/96148bd20e176e71. Report an issue: GitHub.