xai-org/x-algorithm · error · ValueError
{head_dim=} must be divisible by 64
Error message
{head_dim=} must be divisible by 64 What it means
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.
Source
Thrown at phoenix/xrex/pallas/ranker_attention_fa3.py:106
):
if q.ndim != 4 or k.ndim != 4 or v.ndim != 4:
raise ValueError(f"q, k, and v should all be 4D, got: {q.ndim=}, {k.ndim=}, {v.ndim=}")
batch_size, q_seq_len, num_q_heads, head_dim = q.shape
_, kv_seq_len, num_kv_heads, _ = k.shape
kv_shape = (batch_size, kv_seq_len, num_kv_heads, head_dim)
if k.shape != kv_shape:
raise ValueError(f"Expected {k.shape=} to be {kv_shape} (inferred from q)")
if v.shape != kv_shape:
raise ValueError(f"Expected {v.shape=} to be {kv_shape} (inferred from q)")
if (dtype := q.dtype) != k.dtype or dtype != v.dtype:
raise ValueError(
f"q, k, and v should all have the same dtype, got: {q.dtype}, {k.dtype}, {v.dtype}"
)
if num_q_heads % num_kv_heads:
raise ValueError(f"{num_q_heads=} must be divisible by and {num_kv_heads=}")
q_heads_per_kv_head = num_q_heads // num_kv_heads
if head_dim % 64:
raise ValueError(f"{head_dim=} must be divisible by 64")
if jnp.dtype(dtype) not in map(jnp.dtype, [jnp.float16, jnp.bfloat16]):
raise NotImplementedError(f"Only f16 and bf16 are supported, got dtype: {dtype}")
max_concurrent_steps = min(config.max_concurrent_steps, kv_seq_len // config.block_kv)
block_q, block_kv = config.block_q, config.block_kv
if kv_seq_len % block_kv:
raise ValueError(f"{kv_seq_len=} must be a multiple of {block_kv=}")
def kernel(q_ref, k_ref, v_ref, bound_ref, out_ref, lse_ref, scoped):
batch = lax.axis_index("batch")
q_head = lax.axis_index("heads")
q_seq = lax.axis_index("q_seq")
smem_buffers, buffer_barriers, consumed_barriers, schedule_barrier = scoped
wg_idx = lax.axis_index("wg")
qo_smem2, k_smem, v_smem, lse_smem2 = smem_buffers
k_barriers, v_barriers, q_barriers = buffer_barriers
k_consumed_barriers, v_consumed_barriers = consumed_barriers
history_lower_bound = plgpu.load(bound_ref, (batch, 0))View on GitHub (pinned to 24c60942c5)
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)
Example fix
# before head_dim = 48 # after head_dim = 64
Defensive patterns
Strategy: validation
Validate before calling
assert head_dim % 64 == 0, "head_dim must be a multiple of 64 for the FA3 kernel"
Prevention
- Prefer head_dim in {64, 128}
- Fall back to a non-FA3 attention implementation for exotic head dims
When it happens
Trigger: head_dim values like 32, 48, 96, or 80 — anything not divisible by 64.
Common situations: 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.
Related errors
- Invalid backward pass implementation: {backward_pass_impl}
- cap_method must be in [tanh, soft_sign, none], got {cap_meth
- {self.block_q=} must be a multiple of 64
- {self.block_kv=} must be a multiple of 64
- q, k, and v should all be 4D, got: {q.ndim=}, {k.ndim=}, {v.
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/a91ad4b6e2c0c258.
Report an issue: GitHub.