{"record":{"id":"3533419929e40355","repo":"sgl-project/sglang","slug":"b-must-have-shape-b-hv-with-hv-hv-got-b-sh","errorCode":null,"errorMessage":"`b` must have shape [B, HV] with HV={HV} (got b.shape={tuple(b.shape)}).","messagePattern":"`b` must have shape \\[B, HV\\] with HV=(.+?) \\(got b\\.shape=(.+?)\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/fla/fused_recurrent.py","lineNumber":593,"sourceCode":"    if ssm_state_indices.shape[0] != B:\n        raise ValueError(\n            f\"`ssm_state_indices` must have shape [B] (got {tuple(ssm_state_indices.shape)}; expected ({B},)).\"\n        )\n\n    if initial_state.ndim != 4:\n        raise ValueError(\n            f\"`initial_state` must be a 4D tensor (got ndim={initial_state.ndim}).\"\n        )\n    if initial_state.stride(-1) != 1:\n        raise ValueError(\"`initial_state` must be contiguous in the last dim.\")\n    HV, V, K = initial_state.shape[-3:]\n    if a.shape[1] != HV * K:\n        raise ValueError(\n            f\"`a` must have shape [B, HV*K] with HV={HV}, K={K} \"\n            f\"(got a.shape={tuple(a.shape)}).\"\n        )\n    if b.shape[1] != HV:\n        raise ValueError(\n            f\"`b` must have shape [B, HV] with HV={HV} (got b.shape={tuple(b.shape)}).\"\n        )\n    if A_log.numel() != HV:\n        raise ValueError(f\"`A_log` must have {HV} elements (got {A_log.numel()}).\")\n    if dt_bias.numel() != HV * K:\n        raise ValueError(\n            f\"`dt_bias` must have {HV * K} elements (got {dt_bias.numel()}).\"\n        )\n    if out.shape != (B, 1, HV, V):\n        raise ValueError(\n            f\"`out` must have shape {(B, 1, HV, V)} (got out.shape={tuple(out.shape)}).\"\n        )\n\n    qkv_dim = mixed_qkv.shape[1]\n    qk_dim = qkv_dim - HV * V\n    if qk_dim <= 0 or qk_dim % 2 != 0:\n        raise ValueError(\n            f\"Invalid packed `mixed_qkv` last dim={qkv_dim} for HV={HV}, V={V}.\"","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/fla/fused_recurrent.py#L575-L611","documentation":"The gate tensor b must have width HV (one scalar gate per value head), matching the head count of initial_state. This fires when b carries per-channel values (HV*K), per-query-head values (H), or is truncated.","triggerScenarios":"b.shape[1] != HV, e.g. b sliced with the a-tensor's width, or built with query head count H in a GQA model.","commonSituations":"Incorrect split offsets in a fused gating projection; GQA models where H != HV and the wrong count is used for b.","solutions":["Slice b to exactly HV columns","Verify split sizes: gate.split([HV*K, HV], dim=-1) for (a, b)","Assert b.shape == (B, HV) from initial_state.shape[-3]"],"exampleFix":"# before\na, b = proj.split([HV*K, H], dim=-1)\n# after\na, b = proj.split([HV*K, HV], dim=-1)","handlingStrategy":"validation","validationCode":"HV = initial_state.shape[-3]\nassert b.shape == (mixed_qkv.shape[0], HV), (b.shape, HV)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use split([HV*K, HV]) widths derived from initial_state","Watch GQA configs where H != HV"],"tags":["shape-validation","kda","gqa"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}