{"record":{"id":"9ab04984a0eb0d92","repo":"sgl-project/sglang","slug":"refiner-cu-seqlens-live-text-length-must-be-in-1-9ab049","errorCode":null,"errorMessage":"refiner cu_seqlens live text length must be in [1, {int(text_embeddings_selected.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":2250,"sourceCode":"        Returns (decoder_input [S_local, H] bf16, t_emb [M, t_dim] fp32).\n        \"\"\"\n        # BCG pads the prompt tensor only to stabilize its input signature.\n        # Raw-input callers recover the live length from refiner metadata;\n        # request-static refined inputs carry it as a host integer and avoid a\n        # per-step device scalar read. Running the refiner at the bucketed M\n        # dimension changes GEMM selection and is not bitwise equivalent.\n        if refined_prompt_embeds_length is None:\n            text_len = int(refiner_cu_seqlens[1].item())\n        elif torch.is_tensor(refined_prompt_embeds_length):\n            # BCG turns this request-varying host constant into a scalar input\n            # so different live lengths can replay one padded-text signature.\n            # _embed is an eager graph break, so this value is read outside\n            # captured CUDA graphs.\n            text_len = int(refined_prompt_embeds_length.item())\n        else:\n            text_len = int(refined_prompt_embeds_length)\n        if text_len <= 0 or text_len > int(text_embeddings_selected.shape[0]):\n            raise ValueError(\n                \"refiner cu_seqlens live text length must be in \"\n                f\"[1, {int(text_embeddings_selected.shape[0])}], got {text_len}\"\n            )\n        text_pos = text_pos[:text_len]\n        if refined_prompt_embeds_length is not None:\n            text_embed = text_embeddings_selected[:text_len].to(\n                device=device, dtype=_BF16_DTYPE\n            )\n            if int(text_embed.shape[-1]) != self.hidden_size:\n                raise ValueError(\n                    \"refined prompt embeddings must have hidden width \"\n                    f\"{self.hidden_size}, got {int(text_embed.shape[-1])}\"\n                )\n        else:\n            text_embed = self.refine_prompt_embeds(\n                text_embeddings_selected,\n                refiner_cu_seqlens,\n                device=device,","sourceCodeStart":2232,"sourceCodeEnd":2268,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py#L2232-L2268","documentation":"Raised in MiniMaxH3DiTModel._embed when the live text length (refined_prompt_embeds_length) is <= 0 or exceeds the number of available refined text embedding rows (text_embeddings_selected.shape[0]). The model slices text_pos and text_embeddings by this length, so an out-of-range value would slice incorrectly or produce empty tensors.","triggerScenarios":"Calling forward with refined_prompt_embeds_length that is zero, negative, or larger than the row count of the supplied refined text embeddings tensor (e.g. padding/token-count bookkeeping that disagrees with the embedding batch dimension).","commonSituations":"Mismatch between the token count recorded by the scheduler/packing code and the actual rows in refined text embeddings after padding, truncation, or sequence packing; device-sync issues reading the length tensor after CUDA graph capture.","solutions":["Verify refined_prompt_embeds_length equals text_embeddings_selected.shape[0] (or is within it) before calling forward","Audit upstream packing/padding logic that computes the live text length for off-by-one or post-truncation mismatch","If the length arrives as a device tensor, ensure it is synced/read correctly relative to graph breaks (per the comment in the source)"],"exampleFix":"// before\nout = model.forward(..., refined_prompt_embeds_length=n_live, ...)\n// after\nassert 1 <= int(n_live) <= text_embeddings.shape[0], n_live\nout = model.forward(..., refined_prompt_embeds_length=n_live, ...)","handlingStrategy":"validation","validationCode":"n = int(refined_prompt_embeds_length.item()) if torch.is_tensor(refined_prompt_embeds_length) else int(refined_prompt_embeds_length)\nassert 1 <= n <= text_embeddings_selected.shape[0], (n, text_embeddings_selected.shape[0])","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep one source of truth for token counts between packing and embedding tensors","Add shape/length asserts in pipeline glue before model.forward"],"tags":["minimax-h3","dit","shape-validation","text-embeddings"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}