{"record":{"id":"f7da28beec300f37","repo":"sgl-project/sglang","slug":"update-mask-length-mismatch-update-mask-shape-0","errorCode":null,"errorMessage":"update_mask length mismatch: {update_mask.shape[0]} != {video_logits.shape[0]}","messagePattern":"update_mask length mismatch: (.+?) != (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py","lineNumber":2638,"sourceCode":"                torch.cat((video_logits, audio_logits), dim=-1), dim=0\n            )\n            video_logits, audio_logits = logits.split(\n                (video_width, logits.shape[-1] - video_width), dim=-1\n            )\n\n        # Preserve the full-row output GEMM (and therefore its numerical\n        # contract), but defer TP column gathers until after dead text/padding\n        # rows have been removed. For hybrid TP+Ulysses, the preceding SP row\n        # gather also carries only the TP-local output width.\n        video_logits = video_logits.index_select(0, infer_out_pos.to(device))\n        audio_logits = audio_logits.index_select(0, audio_pos.to(device))\n        if get_tp_world_size() > 1:\n            video_logits = tensor_model_parallel_all_gather(video_logits)\n            audio_logits = tensor_model_parallel_all_gather(audio_logits)\n        if not skip_mask_out_condition:\n            update_mask = update_mask.view(-1).to(device)\n            if update_mask.shape[0] != video_logits.shape[0]:\n                raise ValueError(\n                    \"update_mask length mismatch: \"\n                    f\"{update_mask.shape[0]} != {video_logits.shape[0]}\"\n                )\n            video_logits = video_logits * update_mask.unsqueeze(-1)\n            # Audio has no condition rows in the supported tasks, so its\n            # derived update mask is all ones. Honor an explicit mask when\n            # provided.\n            update_audio_mask = kwargs.get(\"update_audio_mask\")\n            if update_audio_mask is not None:\n                audio_logits = audio_logits * update_audio_mask.view(-1).unsqueeze(-1)\n        return video_logits, audio_logits\n\n\nEntryClass = MiniMaxH3DiTModel\n\n__all__ = [\n    \"MINIMAX_H3_FP32_BUFFER_NAMES\",\n    \"MINIMAX_H3_FP32_PARAM_NAMES\",","sourceCodeStart":2620,"sourceCodeEnd":2656,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py#L2620-L2656","documentation":"Before zeroing out condition rows in output logits, forward validates that update_mask (flattened) length equals the gathered video_logits row count. A mismatch means the mask was built for a different token set than the logits.","triggerScenarios":"Passing an update_mask sized to the pre-TP-gather local rows, or to text+video tokens, while video_logits has the full gathered video-row count.","commonSituations":"TP all-gather changing row counts vs. locally-built masks; update masks built before packing/padding changes; masks computed for audio rows instead of video rows.","solutions":["Build update_mask over exactly the video token rows of the packed sequence (length must equal video_logits.shape[0] after all-gather)","If you pass token_tags, prefer deriving the mask from tags so lengths stay consistent","Verify skip_mask_out_condition when condition zeroing is not needed"],"exampleFix":"// before\nmodel(..., update_mask=local_mask)  # length != gathered video rows\n// after\nvideo_mask = torch.ones(num_video_rows, device=x.device)\nvideo_mask[cond_video_rows] = 0\nmodel(..., update_mask=video_mask)","handlingStrategy":"validation","validationCode":"update_mask = update_mask.view(-1)\nassert update_mask.shape[0] == num_gathered_video_rows, (update_mask.shape[0], num_gathered_video_rows)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive update_mask from the same token tags used for packing","Remember TP all-gather restores full row counts — build masks globally"],"tags":["minimax-h3","update-mask","tensor-parallel","logits"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}