{"record":{"id":"141c52e7ebb574a0","repo":"sgl-project/sglang","slug":"unconditional-token-logprobs-are-required-for-this","errorCode":null,"errorMessage":"Unconditional token logprobs are required for this method.","messagePattern":"Unconditional token logprobs are required for this method\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/lang/choices.py","lineNumber":132,"sourceCode":"        return True\n\n    def __call__(\n        self,\n        *,\n        choices: List[str],\n        normalized_prompt_logprobs: List[float],\n        input_token_logprobs: List[List[Any]],\n        output_token_logprobs: List[List[Any]],\n        unconditional_token_logprobs: Optional[List[List[Any]]] = None,\n    ) -> ChoicesDecision:\n        \"\"\"Select the option with the highest average token logprob once normalized by\n        the unconditional token logprobs.\n\n        The first unconditional token logprob is assumed to be None. If so, it is\n        replaced with 0 for the purposes of normalization.\"\"\"\n\n        if unconditional_token_logprobs is None:\n            raise ValueError(\n                \"Unconditional token logprobs are required for this method.\"\n            )\n\n        normalized_unconditional_prompt_logprobs = self._normalize_logprobs(\n            input_token_logprobs, unconditional_token_logprobs\n        )\n\n        best_choice = choices[np.argmax(normalized_unconditional_prompt_logprobs)]\n        meta_info = {\n            \"normalized_prompt_logprobs\": normalized_prompt_logprobs,\n            \"input_token_logprobs\": input_token_logprobs,\n            \"output_token_logprobs\": output_token_logprobs,\n            \"unconditional_token_logprobs\": unconditional_token_logprobs,\n            \"normalized_unconditional_prompt_logprobs\": normalized_unconditional_prompt_logprobs,\n        }\n        return ChoicesDecision(decision=best_choice, meta_info=meta_info)\n\n    def _normalize_logprobs(self, input_token_logprobs, unconditional_token_logprobs):","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/lang/choices.py#L114-L150","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nresult = choice_fn(input_token_logprobs=lp, unconditional_token_logprobs=None)\n# after\nuncond = gen_unconditional_logprobs(prompt, choices)  # reference pass with logprobs on\nresult = choice_fn(input_token_logprobs=lp, unconditional_token_logprobs=uncond)","handlingStrategy":"validation","validationCode":"assert unconditional_token_logprobs is not None, \"compute unconditional logprobs before scoring\"","typeGuard":"def has_uncond_logprobs(lp) -> bool:\n    return lp is not None and (len(lp) == 0 or lp[0] is None or isinstance(lp[0], float))","tryCatchPattern":"try:\n    score = chooser(input_logprobs, uncond_logprobs)\nexcept ValueError as e:\n    if \"Unconditional\" in str(e):\n        uncond = compute_reference_logprobs(...)\n        score = chooser(input_logprobs, uncond)\n    else:\n        raise","preventionTips":["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"],"tags":["validation","logprobs","argument-validation","choices"],"backgroundTag":"required-argument-missing","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}