{"record":{"id":"41cc818bc6bd5a12","repo":"sgl-project/sglang","slug":"inverse-indices-must-be-seq-len-got-list-inv","errorCode":null,"errorMessage":"inverse_indices must be [{seq_len}], got {list(inverse_indices.shape)}","messagePattern":"inverse_indices must be \\[(.+?)\\], got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py","lineNumber":2448,"sourceCode":"        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\n        # and online-softmax merges partial outputs (see\n        # _minimax_h3_attention_core_impl), so it has no head constraint.\n        ulysses_ws, ulysses_rank = get_ulysses_ctx()\n        ring_ws, ring_rank = get_ring_ctx()\n        sp_ws = ulysses_ws * ring_ws","sourceCodeStart":2430,"sourceCodeEnd":2466,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py#L2430-L2466","documentation":"inverse_indices must be length S (the full packed sequence length) so the model can un-permute/sort outputs back to the original token order. A wrong-length tensor would gather out-of-bounds.","triggerScenarios":"Passing inverse_indices from torch.argsort computed over a different sequence, or rank-local (already sharded) indices instead of global packed indices.","commonSituations":"Reusing sort indices from before packing changes; sharding/slicing the indices for sequence parallelism before the model expects to do its own slicing at line 2540 region.","solutions":["Recompute inverse_indices = torch.argsort(sort_indices) over the same S tokens that form x","Pass global full-length indices; the model slices them per rank itself","Assert inverse_indices.shape[0] == x.shape[1] before forward"],"exampleFix":"// before\nmodel(x=packed, inverse_indices=local_idx, ...)\n// after\nsort_idx = torch.argsort(keys, stable=True)\ninv_idx = torch.argsort(sort_idx)\nmodel(x=packed, inverse_indices=inv_idx, ...)","handlingStrategy":"validation","validationCode":"assert inverse_indices.shape[0] == x.shape[1], (inverse_indices.shape, x.shape)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute inverse_indices = argsort(sort_indices) on the same tokens as x","Never pre-shard indices; pass global ones"],"tags":["minimax-h3","inverse-indices","packed-sequence"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}