{"record":{"id":"3f96fb67332cbea0","repo":"sgl-project/sglang","slug":"helion-kda-decode-requires-power-of-two-key-and-va","errorCode":null,"errorMessage":"Helion KDA decode requires power-of-two key and value head dimensions (got K={K}, V={V}).","messagePattern":"Helion KDA decode requires power-of-two key and value head dimensions \\(got K=(.+?), V=(.+?)\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/helion/kda_decode.py","lineNumber":288,"sourceCode":"            \"Mismatched batch sizes: \"\n            f\"mixed_qkv.shape[0]={B}, a.shape[0]={a.shape[0]}, \"\n            f\"b.shape[0]={b.shape[0]}.\"\n        )\n    if ssm_state_indices.shape[0] != B:\n        raise ValueError(\n            f\"`ssm_state_indices` must have shape [B] \"\n            f\"(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 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        )","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/helion/kda_decode.py#L270-L306","documentation":"The Helion KDA decode kernel is specialized for power-of-two head dimensions: it uses the fast power-of-two code path (tower-of-power decays) for key dim K and value dim V taken from initial_state.shape[-3:]. validate_packed_decode_inputs rejects any non-power-of-two K or V so the Triton/Helion kernel never receives a shape it cannot compile a cache entry for.","triggerScenarios":"Running a KDA/GDN model whose value_dim or key_dim is e.g. 96, 192, or any non-power-of-two, with the Helion decode path enabled; passing a hand-built initial_state with odd V/K in a unit test.","commonSituations":"Loading an experimental checkpoint with non-standard head dims; a config where head_v_dim differs from head_k_dim and neither is a power of two; upgrading a model config without re-checking the Helion kernel constraints.","solutions":["Fall back to the reference/Triton KDA decode path when K or V is not a power of two","Change the model config so key_dim and value_dim are powers of two (64/128/256) if you control the checkpoint","Gate model registration: assert _is_power_of_two(head_k_dim) and _is_power_of_two(head_v_dim) before selecting the Helion backend"],"exampleFix":"// before\nuse_helion = True  # model has head_v_dim=96\n// after\nuse_helion = _is_power_of_two(cfg.head_k_dim) and _is_power_of_two(cfg.head_v_dim)\nif not use_helion:\n    backend = \"triton\"","handlingStrategy":"fallback","validationCode":"def helion_ok(cfg):\n    return cfg.head_k_dim & (cfg.head_k_dim - 1) == 0 and cfg.head_v_dim & (cfg.head_v_dim - 1) == 0\nbackend = \"helion\" if helion_ok(cfg) else \"triton\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check power-of-two head dims at model registration time","Keep a reference decode path for non-power-of-two configs"],"tags":["kda","helion","power-of-two","head-dim","model-config"],"backgroundTag":"unsupported-head-dimension","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}