{"record":{"id":"8a9ada989f904f92","repo":"sgl-project/sglang","slug":"refiner-cu-seqlens-live-text-length-must-be-in-1","errorCode":null,"errorMessage":"refiner cu_seqlens live text length must be in [1, {int(prompt_embeds.shape[0])}], got {text_len}","messagePattern":"refiner cu_seqlens live text length must be in \\[1, (.+?)\\], got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py","lineNumber":2143,"sourceCode":"    def _psp_optional_field(psp: Any, field: str) -> Any:\n        if isinstance(psp, dict):\n            return psp.get(field)\n        return getattr(psp, field, None)\n\n    def refine_prompt_embeds(\n        self,\n        prompt_embeds: torch.Tensor,\n        refiner_cu_seqlens: torch.Tensor,\n        *,\n        device: torch.device,\n    ) -> torch.Tensor:\n        \"\"\"Project and refine request-static text conditioning once.\"\"\"\n        self.materialize_mps_non_layer_weights(\n            \"condition_proj\", \"token_refiner.final_norm\"\n        )\n        text_len = int(refiner_cu_seqlens[1].item())\n        if text_len <= 0 or text_len > int(prompt_embeds.shape[0]):\n            raise ValueError(\n                \"refiner cu_seqlens live text length must be in \"\n                f\"[1, {int(prompt_embeds.shape[0])}], got {text_len}\"\n            )\n        text_rows = prompt_embeds[:text_len].to(device=device, dtype=_BF16_DTYPE)\n        true_refiner_cu = torch.stack(\n            (\n                refiner_cu_seqlens[0],\n                refiner_cu_seqlens[1],\n                refiner_cu_seqlens[1],\n            )\n        )\n        text_embed, _ = self.condition_proj(text_rows)\n        refined = self.token_refiner(\n            text_embed,\n            cu_seqlens=true_refiner_cu,\n            cu_seqlens_host=(0, text_len, text_len),\n            max_seqlen=text_len,\n        )","sourceCodeStart":2125,"sourceCodeEnd":2161,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py#L2125-L2161","documentation":"refine_prompt_embeds reads text_len = refiner_cu_seqlens[1] (the live text length in the cumulative-sequence-lengths tensor) and requires 1 <= text_len <= prompt_embeds.shape[0]. Outside that range the row slice prompt_embeds[:text_len] would be empty or out of bounds, so it raises with the valid range and actual value.","triggerScenarios":"Passing refiner_cu_seqlens like [0, 0, ...] (zero live text rows) or [0, N+5] where N is prompt_embeds' row count; mismatch between the cu_seqlens built by the tokenizer/batcher and the truncated prompt_embeds tensor.","commonSituations":"Truncating or padding prompt_embeds after cu_seqlens was computed; batching bugs that pair a batch's cu_seqlens with the wrong embeds tensor; empty-text requests reaching the refiner.","solutions":["Recompute refiner_cu_seqlens from the same prompt tokens that produced prompt_embeds","Assert 1 <= int(refiner_cu_seqlens[1]) <= prompt_embeds.shape[0] before calling","Filter out empty-text requests before they reach the refiner"],"exampleFix":"# before\nrefine_prompt_embeds(prompt_embeds=emb[:10], refiner_cu_seqlens=torch.tensor([0, 25]))\n# after\ntext_len = int(cu[1].item())\nassert 1 <= text_len <= emb.shape[0]\nrefine_prompt_embeds(prompt_embeds=emb, refiner_cu_seqlens=cu)","handlingStrategy":"validation","validationCode":"text_len = int(refiner_cu_seqlens[1].item())\nassert 1 <= text_len <= int(prompt_embeds.shape[0]), (text_len, prompt_embeds.shape)","typeGuard":"def cu_seqlens_valid(cu: torch.Tensor, n_rows: int) -> bool:\n    t = int(cu[1].item())\n    return 1 <= t <= n_rows","tryCatchPattern":null,"preventionTips":["Compute cu_seqlens and prompt_embeds from the same tokenization pass","Drop empty-text requests before the refiner"],"tags":["input-validation","cu-seqlens","off-by-one","batching"],"backgroundTag":"sequence-length-out-of-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}