{"record":{"id":"b697445ef9ffade0","repo":"sgl-project/sglang","slug":"dt-bias-must-have-hv-k-elements-got-dt-bia-b69744","errorCode":null,"errorMessage":"`dt_bias` must have {HV * K} elements (got {dt_bias.numel()}).","messagePattern":"`dt_bias` must have (.+?) elements \\(got (.+?)\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/helion/kda_decode.py","lineNumber":304,"sourceCode":"    HV, V, K = initial_state.shape[-3:]\n    if not _is_power_of_two(K) or not _is_power_of_two(V):\n        raise ValueError(\n            \"Helion KDA decode requires power-of-two key and value head \"\n            f\"dimensions (got K={K}, V={V}).\"\n        )\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}.\"\n        )\n    q_dim = qk_dim // 2\n    if q_dim % K != 0:\n        raise ValueError(\n            f\"Invalid packed Q size {q_dim}: must be divisible by K={K}. \"\n            \"KDA packed decode requires num_q_heads == num_k_heads and \"","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/helion/kda_decode.py#L286-L322","documentation":"dt_bias supplies the softplus bias for the discretization, one value per (value-head, key-dim) pair, so validate_packed_decode_inputs requires exactly HV*K elements. The check mirrors the packing of `a` and catches dt_bias tensors sized per-head only or for the wrong head count.","triggerScenarios":"Passing dt_bias with numel == HV (per-head bias), numel == H*K (query heads in a GQA layout), or flattened with an extra time dimension of size > 1.","commonSituations":"Checkpoint parameter renamed/reshaped between versions; test fixtures reusing A_log's shape for dt_bias; models where dt_bias is stored [HV, K] but sliced incorrectly.","solutions":["Ensure dt_bias is flattened: dt_bias = dt_bias.reshape(-1) with numel == HV*K","Confirm the loaded checkpoint's dt_bias shape matches [num_v_heads, head_k_dim]","Match the packing of `a` — both must use the same HV and K inferred from initial_state"],"exampleFix":"// before\ndt_bias = layer.dt_bias  # [HV] by mistake\n// after\ndt_bias = layer.dt_bias.reshape(-1)  # [HV*K] from [HV, K] storage","handlingStrategy":"validation","validationCode":"HV, V, K = initial_state.shape[-3:]\ndt_bias = dt_bias.reshape(-1)\nassert dt_bias.numel() == HV * K","typeGuard":"def valid_dt_bias(t: torch.Tensor, hv: int, k: int) -> bool:\n    return t.numel() == hv * k","tryCatchPattern":null,"preventionTips":["Flatten dt_bias once at load: layer.dt_bias.reshape(-1)","Validate checkpoint parameter shapes against config before serving"],"tags":["kda","helion","parameter-shape","model-config"],"backgroundTag":"parameter-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}