{"record":{"id":"f66f004c485db783","repo":"sgl-project/sglang","slug":"token-tags-must-cover-the-full-packed-sequence-s","errorCode":null,"errorMessage":"token_tags must cover the full packed sequence ({seq_len}), got {token_tags.shape[0]}.","messagePattern":"token_tags must cover the full packed sequence \\((.+?)\\), got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py","lineNumber":2443,"sourceCode":"            )\n        )\n        # max_seqlen_q is set to cu_seqlens[1] (`used`, the real/non-padding\n        # row count) by construction -- already a plain host int here, so\n        # ring can reuse it as real_seq_len below with no new device sync.\n        max_seqlen = int(self._psp_field(psp, \"packed_seq_params\", \"max_seqlen_q\"))\n        refiner_psp = _required_kwarg(kwargs, \"refiner_packed_seq_params\")\n        refiner_cu = self._psp_field(\n            refiner_psp, \"refiner_packed_seq_params\", \"cu_seqlens_q\"\n        ).to(torch.int32)\n        refiner_max = int(\n            self._psp_field(refiner_psp, \"refiner_packed_seq_params\", \"max_seqlen_q\")\n        )\n\n        if x.dim() != 3 or x.shape[0] != 1:\n            raise ValueError(f\"x must be [1, S, C], got {list(x.shape)}\")\n        seq_len = int(x.shape[1])\n        if token_tags is not None and token_tags.shape[0] != seq_len:\n            raise ValueError(\n                \"token_tags must cover the full packed sequence \"\n                f\"({seq_len}), got {token_tags.shape[0]}.\"\n            )\n        if inverse_indices.shape[0] != seq_len:\n            raise ValueError(\n                f\"inverse_indices must be [{seq_len}], got {list(inverse_indices.shape)}\"\n            )\n        device = x.device\n        if subblock_sparse_query_block_mask is not None and not isinstance(\n            subblock_sparse_query_block_mask, torch.Tensor\n        ):\n            raise ValueError(\"subblock_sparse_query_block_mask must be a tensor\")\n        self._resolve_attention_backend_once()\n\n        # Row split is 2D: ring first (an outer, contiguous ring_chunk_len\n        # slice of the packed sequence), Ulysses second (an inner slice\n        # within this rank's ring chunk). Only Ulysses shards heads inside\n        # attention -- ring instead ring-rotates each rank's local KV chunk","sourceCodeStart":2425,"sourceCodeEnd":2461,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py#L2425-L2461","documentation":"When token_tags is provided it must have shape[0] equal to the packed sequence length S so every packed token carries a tag. Mismatched tag length means condition/contrast tagging cannot be aligned to tokens.","triggerScenarios":"Passing token_tags computed for a different sequence (e.g. before padding, or for only the video tokens while text tokens are also packed).","commonSituations":"Recomputing latents/token counts after padding changes but reusing stale tag tensors; concatenating tag arrays in the wrong order or omitting a modality segment.","solutions":["Rebuild token_tags from the same packing metadata that produced x, ensuring len(tags) == x.shape[1]","Include tags for every packed segment (text + video + audio) in packed order","Add an assert len(token_tags) == x.shape[1] before calling forward"],"exampleFix":"// before\nmodel(x=packed, token_tags=video_tags_only, ...)\n// after\nall_tags = torch.cat([text_tags, video_tags, audio_tags])\nassert all_tags.shape[0] == packed.shape[1]\nmodel(x=packed, token_tags=all_tags, ...)","handlingStrategy":"validation","validationCode":"assert token_tags is None or token_tags.shape[0] == x.shape[1], (token_tags.shape, x.shape)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate token_tags from the same packing metadata as x","Include every modality segment in tag order"],"tags":["minimax-h3","token-tags","packed-sequence"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}