sgl-project/sglang · error · ValueError
Unconditional token logprobs are required for this method.
Error message
Unconditional token logprobs are required for this method.
What it means
Raised by the choices module (PMI/length-normalization helpers) when a method that computes contrastive scores is called with unconditional_token_logprobs=None. The algorithm needs the unconditional (reference) logprobs to normalize against, so refusing on None prevents silent nonsense results.
Solutions
- Compute unconditional logprobs for each choice (run the reference generation with logprobs enabled) and pass them as unconditional_token_logprobs
- Ensure the first element may be None (it's replaced with 0) but the array itself is not None
- Check upstream generation code actually returned logprobs (not None) before calling this method
Example fix
# before result = choice_fn(input_token_logprobs=lp, unconditional_token_logprobs=None) # after uncond = gen_unconditional_logprobs(prompt, choices) # reference pass with logprobs on result = choice_fn(input_token_logprobs=lp, unconditional_token_logprobs=uncond)
Defensive patterns
Strategy: validation
Validate before calling
assert unconditional_token_logprobs is not None, "compute unconditional logprobs before scoring"
Type guard
def has_uncond_logprobs(lp) -> bool:
return lp is not None and (len(lp) == 0 or lp[0] is None or isinstance(lp[0], float)) Try / catch
try:
score = chooser(input_logprobs, uncond_logprobs)
except ValueError as e:
if "Unconditional" in str(e):
uncond = compute_reference_logprobs(...)
score = chooser(input_logprobs, uncond)
else:
raise Prevention
- Always run the unconditional/reference generation with logprobs enabled before choice scoring
- Keep conditional and unconditional token arrays aligned in length
- Add unit asserts on logprob arrays in tests of choice logic
When it happens
Trigger: Calling the choice-scoring __call__ (e.g. contrastive/PMI-style selection over branches in an SGL program) without passing the unconditional_token_logprobs array, typically because the branch generation didn't request logprobs or the caller forgot to compute the reference scores.
Common situations: Using sgl.choice / branch selection helpers where only conditional generations were run; refactoring removed the unconditional scoring pass; sampling params without logprobs enabled so the array came back None.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- a port must be specified in IPv6 address (format…
- A tokenizer is required to load an external ngram corpus.
- action_mode is set but the loaded Cosmos3 checkpoint has no…
- action must have shape [T, D], got
- action string is empty
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/141c52e7ebb574a0.
Report an issue: GitHub.
Appendix: source
Thrown at python/sglang/lang/choices.py:132
return True
def __call__(
self,
*,
choices: List[str],
normalized_prompt_logprobs: List[float],
input_token_logprobs: List[List[Any]],
output_token_logprobs: List[List[Any]],
unconditional_token_logprobs: Optional[List[List[Any]]] = None,
) -> ChoicesDecision:
"""Select the option with the highest average token logprob once normalized by
the unconditional token logprobs.
The first unconditional token logprob is assumed to be None. If so, it is
replaced with 0 for the purposes of normalization."""
if unconditional_token_logprobs is None:
raise ValueError(
"Unconditional token logprobs are required for this method."
)
normalized_unconditional_prompt_logprobs = self._normalize_logprobs(
input_token_logprobs, unconditional_token_logprobs
)
best_choice = choices[np.argmax(normalized_unconditional_prompt_logprobs)]
meta_info = {
"normalized_prompt_logprobs": normalized_prompt_logprobs,
"input_token_logprobs": input_token_logprobs,
"output_token_logprobs": output_token_logprobs,
"unconditional_token_logprobs": unconditional_token_logprobs,
"normalized_unconditional_prompt_logprobs": normalized_unconditional_prompt_logprobs,
}
return ChoicesDecision(decision=best_choice, meta_info=meta_info)
def _normalize_logprobs(self, input_token_logprobs, unconditional_token_logprobs):View on GitHub (pinned to 0132848349)