{"record":{"id":"ae5976ab0e042516","repo":"jax-ml/jax","slug":"num-queries-per-block-must-be-positive","errorCode":null,"errorMessage":"{num_queries_per_block=} must be positive.","messagePattern":"(.+?) must be positive\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/pallas/ops/tpu/ragged_paged_attention/kernel.py","lineNumber":283,"sourceCode":"        \"The dtype of `kv_lens`, `page_indices`, and `cu_q_lens` must be\"\n        f\" int32. Got {kv_lens.dtype=}, {page_indices.dtype=},\"\n        f\" {cu_q_lens.dtype=}.\"\n    )\n  if num_q_heads % num_kv_heads != 0:\n    raise ValueError(f\"{num_q_heads=} must be divisible by {num_kv_heads=}\")\n  if sliding_window is not None and sliding_window <= 0:\n    raise ValueError(f\"{sliding_window=} must be positive.\")\n  if soft_cap is not None and soft_cap == 0.0:\n    raise ValueError(f\"{soft_cap=} must not be 0.0.\")\n  if (\n      num_kv_pages_per_block is not None\n      and not 0 < num_kv_pages_per_block <= pages_per_seq\n  ):\n    raise ValueError(\n        f\"{num_kv_pages_per_block=} must be in range (0, {pages_per_seq}].\"\n    )\n  if num_queries_per_block is not None and num_queries_per_block <= 0:\n    raise ValueError(f\"{num_queries_per_block=} must be positive.\")\n  if vmem_limit_bytes is not None and vmem_limit_bytes <= 0:\n    raise ValueError(f\"{vmem_limit_bytes=} must be positive.\")\n  del sm_scale  # No constraints on sm_scale.\n  del mask_value  # No consstraints on mask_value.\n\n\ndef ragged_paged_attention_kernel(\n    # Prefetch\n    kv_lens_ref,  # [max_num_seqs]\n    page_indices_ref,  # [max_num_seqs, pages_per_seq]\n    cu_q_lens_ref,  # [max_num_seqs + 1]\n    seq_buf_idx_ref,\n    # TODO(jevinjiang): if OOM in SMEM, consider pack to other scalar refs.\n    num_seqs_ref,\n    # Input\n    q_ref,  # [num_q_per_blk, num_q_heads_per_blk, head_dim]\n    kv_pages_hbm_ref,  # [total_num_pages, page_size, num_combined_kv_heads, head_dim]\n    # Output","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/pallas/ops/tpu/ragged_paged_attention/kernel.py#L265-L301","documentation":"num_queries_per_block optionally sets how many query rows the ragged paged attention kernel processes per block; it must be a positive integer. Zero or negative values are rejected by static_validate_inputs.","triggerScenarios":"Passing num_queries_per_block=0 (intending autotune/disabled) or a negative tuning value from a config sweep.","commonSituations":"Hyperparameter search code writing 0 as 'unset', or arithmetic that underflows (e.g. max_seq_len // something == 0 for tiny inputs).","solutions":["Pass None to let autotuning choose","Ensure the computed value is >= 1; guard with max(1, value) if derived from arithmetic","Validate tuning configs before passing them to the kernel"],"exampleFix":"// before\nattn(..., num_queries_per_block=num_q // blk)  # 0 when num_q < blk\n// after\nattn(..., num_queries_per_block=max(1, num_q // blk) if blk <= num_q else None)","handlingStrategy":"validation","validationCode":"num_queries_per_block = None if num_queries_per_block is None else max(1, int(num_queries_per_block))\nif num_queries_per_block is not None:\n    assert num_queries_per_block > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat 0 as 'unset' and convert to None","Guard arithmetic that computes block sizes from small sequence lengths"],"tags":["jax","pallas","tpu","block-size","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}