{"record":{"id":"57c541a6d4674f52","repo":"xai-org/x-algorithm","slug":"only-f16-and-bf16-are-supported-got-dtype-dtype","errorCode":null,"errorMessage":"Only f16 and bf16 are supported, got dtype: {dtype}","messagePattern":"Only f16 and bf16 are supported, got dtype: (.+?)","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/pallas/ranker_attention_fa3.py","lineNumber":108,"sourceCode":"        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))\n        history_upper_bound = plgpu.load(bound_ref, (batch, 1))\n        candidate_lower_bound = plgpu.load(bound_ref, (batch, 2))","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/pallas/ranker_attention_fa3.py#L90-L126","documentation":"The FA3-style kernel only implements f16 and bf16 paths — fp32, fp8, or integer dtypes are rejected with NotImplementedError since the tensor-core wgmma instructions assumed by the kernel need half precision.","triggerScenarios":"Passing q/k/v in jnp.float32 (the JAX default for randn), float8, or any dtype outside {float16, bfloat16}.","commonSituations":"Forgetting to cast synthetic test inputs; enabling fp32 debugging; new user passing default-dtype arrays without a params initialization.","solutions":["Cast inputs: q.astype(jnp.bfloat16) (and same for k, v)","For numeric debugging use attention_reference instead of the pallas kernel"],"exampleFix":"# before\nq, k, v = jnp.ones(...), ...  # float32\n# after\nq, k, v = (x.astype(jnp.bfloat16) for x in (q, k, v))","handlingStrategy":"validation","validationCode":"assert q.dtype in (jnp.float16, jnp.bfloat16), \"cast inputs to fp16/bf16\"\nq, k, v = (x.astype(jnp.bfloat16) for x in (q, k, v))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never feed raw jax.random outputs (fp32) to pallas attention","Use attention_reference for fp32 numerics checks"],"tags":["jax","pallas","attention","dtype-validation"],"backgroundTag":"unsupported-dtype","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}