{"record":{"id":"a91ad4b6e2c0c258","repo":"xai-org/x-algorithm","slug":"head-dim-must-be-divisible-by-64","errorCode":null,"errorMessage":"{head_dim=} must be divisible by 64","messagePattern":"(.+?) must be divisible by 64","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/pallas/ranker_attention_fa3.py","lineNumber":106,"sourceCode":"):\n    if q.ndim != 4 or k.ndim != 4 or v.ndim != 4:\n        raise ValueError(f\"q, k, and v should all be 4D, got: {q.ndim=}, {k.ndim=}, {v.ndim=}\")\n    batch_size, q_seq_len, num_q_heads, head_dim = q.shape\n    _, kv_seq_len, num_kv_heads, _ = k.shape\n    kv_shape = (batch_size, kv_seq_len, num_kv_heads, head_dim)\n    if k.shape != kv_shape:\n        raise ValueError(f\"Expected {k.shape=} to be {kv_shape} (inferred from q)\")\n    if v.shape != kv_shape:\n        raise ValueError(f\"Expected {v.shape=} to be {kv_shape} (inferred from q)\")\n    if (dtype := q.dtype) != k.dtype or dtype != v.dtype:\n        raise ValueError(\n            f\"q, k, and v should all have the same dtype, got: {q.dtype}, {k.dtype}, {v.dtype}\"\n        )\n    if num_q_heads % num_kv_heads:\n        raise ValueError(f\"{num_q_heads=} must be divisible by and {num_kv_heads=}\")\n    q_heads_per_kv_head = num_q_heads // num_kv_heads\n    if head_dim % 64:\n        raise ValueError(f\"{head_dim=} must be divisible by 64\")\n    if jnp.dtype(dtype) not in map(jnp.dtype, [jnp.float16, jnp.bfloat16]):\n        raise NotImplementedError(f\"Only f16 and bf16 are supported, got dtype: {dtype}\")\n\n    max_concurrent_steps = min(config.max_concurrent_steps, kv_seq_len // config.block_kv)\n    block_q, block_kv = config.block_q, config.block_kv\n    if kv_seq_len % block_kv:\n        raise ValueError(f\"{kv_seq_len=} must be a multiple of {block_kv=}\")\n\n    def kernel(q_ref, k_ref, v_ref, bound_ref, out_ref, lse_ref, scoped):\n        batch = lax.axis_index(\"batch\")\n        q_head = lax.axis_index(\"heads\")\n        q_seq = lax.axis_index(\"q_seq\")\n        smem_buffers, buffer_barriers, consumed_barriers, schedule_barrier = scoped\n        wg_idx = lax.axis_index(\"wg\")\n        qo_smem2, k_smem, v_smem, lse_smem2 = smem_buffers\n        k_barriers, v_barriers, q_barriers = buffer_barriers\n        k_consumed_barriers, v_consumed_barriers = consumed_barriers\n        history_lower_bound = plgpu.load(bound_ref, (batch, 0))","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/pallas/ranker_attention_fa3.py#L88-L124","documentation":"The FA3-style pallas kernel requires head_dim to be a multiple of 64 because TMA loads and wgmma instructions operate on 64-element fragments of the head dimension.","triggerScenarios":"head_dim values like 32, 48, 96, or 80 — anything not divisible by 64.","commonSituations":"Small experimental models with head_dim=32; porting configs from FA2 pallas kernels which permit head_dim 32/16; adding a non-standard projection width.","solutions":["Use head_dim of 64 or 128","If a smaller head_dim is required, use a different attention implementation (e.g. ranker_attention.py non-FA3 path)"],"exampleFix":"# before\nhead_dim = 48\n# after\nhead_dim = 64","handlingStrategy":"validation","validationCode":"assert head_dim % 64 == 0, \"head_dim must be a multiple of 64 for the FA3 kernel\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer head_dim in {64, 128}","Fall back to a non-FA3 attention implementation for exotic head dims"],"tags":["jax","pallas","attention","alignment"],"backgroundTag":"invalid-head-dim-config","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}