{"record":{"id":"1b202cdd305a7080","repo":"sgl-project/sglang","slug":"a-log-must-have-hv-elements-got-a-log-numel-1b202c","errorCode":null,"errorMessage":"`A_log` must have {HV} elements (got {A_log.numel()}).","messagePattern":"`A_log` must have (.+?) elements \\(got (.+?)\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/helion/kda_decode.py","lineNumber":302,"sourceCode":"    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 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(","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/helion/kda_decode.py#L284-L320","documentation":"A_log holds the log-decay coefficients, one per value head, so validate_packed_decode_inputs requires exactly HV elements (any shape). The numel check catches A_log tensors sized for a different head count, e.g. per-key-dim or query-head-sized decay parameters.","triggerScenarios":"Passing A_log with numel == HV*K (duplicated per key dim), numel == H (query heads, GQA mismatch), or a stale checkpoint parameter sized for another layer config.","commonSituations":"Loading a KDA checkpoint whose num_v_heads changed between model revisions; broadcasting A_log in tests with torch.full((HV, K), ...); mixing up A_log with dt_bias sizing.","solutions":["Verify A_log comes from the model parameter of shape [num_v_heads] and pass it unmodified","If the checkpoint has a different size, fix the model config / re-load the correct weights rather than padding","In tests, size A_log as torch.empty(HV) not (HV, K)"],"exampleFix":"// before\nA_log = layer.A_log.expand(HV, K).contiguous()  # numel = HV*K\n// after\nA_log = layer.A_log  # shape [HV], numel == HV","handlingStrategy":"validation","validationCode":"HV = initial_state.shape[-3]\nassert A_log.numel() == HV, (A_log.shape, HV)","typeGuard":"def valid_a_log(t: torch.Tensor, hv: int) -> bool:\n    return t.numel() == hv","tryCatchPattern":null,"preventionTips":["Pass model parameters (A_log) through unchanged","Add a checkpoint-shape validation step at load time"],"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"}