grill: tt-metal #59695 SDPA prefill opt-in flags (pack_gqa_heads / reuse_kv / math row sums) — fit to our causal chunked prefill #215

Open
opened 2026-10-09 08:55:58 +02:00 by tenstorrent · 0 comments
Member

Pickup (same day from the upstream watch, 2026-10-09; PP scope)

Grill first: desk only, no card runs, no code. Tree read: master f30ab09 (CONTROL …-dx-w2t-b8k3-cph48). Branch grill/metal-59695-sdpa-gqa-flags is cut from master, with no commits.

Upstream: https://github.com/tenstorrent/tt-metal/pull/59695, [Performance] SDPA: pack_gqa_heads, reuse_kv and single-K-chunk row sums for batched GQA prefill, by amorrisonTT.

  • State: open. Filed 2026-10-07 17:40 UTC (19:40 Prague).
  • Size: 18 files, +836/−45.
  • All four flags are opt-in and default off.

Their claims (theirs; Qwen3-4B-shaped embedding prefill: GQA 32/8, S=512, d=128, single P150)

  • pack_gqa_heads: schedules each GQA group as one head of (NQH/NKH)·S rows, so K/V streams once per KV head. bs1: 49.7 → 38.5 µs/call.
    • Under packing, q_chunk need not divide S: q192 35.9 → 29.3 µs.
    • Preconditions: non-causal, no attn_mask, tile-aligned unpadded S.
  • reuse_kv: a core keeps K/V across consecutive Q chunks of the same (batch, KV head). bs16: 512 → 355 µs.
    • Preconditions: one K chunk (k_chunk_size >= s), the streaming kernel, fp32_dest_acc_en=False. Their guidance is to leave it off at batch 1.
  • math_thread_row_sums: single-K-chunk row sums on the math thread, −7…−8%.
    • Accuracy trade-off: per-row denominator error ~1.6× at S=1024 LoFi.
    • Ignored with more than one K chunk.

Fit to our prefill SDPA (P4)

  • Ours is causal chunked prefill over paged KV: QWEN36_SDPA_STREAMING (fp32_dest_acc_en=False), LoFi (QWEN36_SDPA_PREFILL_LOFI), GQA multicast q128 (patch 0025/0026), and reader depth (0027).
  • docs/OP-DATASHEETS.md puts P4 chunked SDPA at 10.7% of the eager 30k chunk at HiFi2 (served LoFi ~−30%). It runs 96/110 cores, and its binding floor is unresolved (FPU vs SFPU exp).
  • pack_gqa_heads: not applicable. It is non-causal only, and our prefill is causal with a growing KV prefix.
  • reuse_kv / math_thread_row_sums: not applicable in the served shape. Both need a single K chunk covering the whole KV. Our chunks attend over up to the full 32k/128k prefix (many K chunks).
    • The only single-K-chunk call is the first chunk of a prompt (KV = the chunk itself). That is ≈ 1/16 of a 32k prefill and ≈ 1/64 of a 128k prefill.
  • Our GQA K/V-traffic problem is already addressed by the GQA multicast (0025/0026). Theirs is a different mechanism for the non-causal case.

Estimate

  • PP: ~0 on the served path (derived from the preconditions above, not measured).
  • At most a first-chunk-only effect, bounded by P4's share of one chunk out of 16–64 chunks.
  • TG: 0 (prefill op only).

Grill questions

  1. Close as WATCH (no port) unless upstream generalises packing/reuse to causal chunked prefill?
  2. Is the first-chunk-only reuse_kv case worth anything at 4k (2 chunks)? Proposed: no. It needs k_chunk >= s plus a separate program at chunk 0, and the gain is bounded by P4 × ½ chunk.
  3. Does math_thread_row_sums's 16-bit DEST row-sum error class matter for #201 U6 (QWEN36_SDPA_PREFILL_KCHUNK)? No k passed U6's 1.05× fp64-error gate.

Out of scope

  • No code, no card boots. Upstream numbers are theirs.
## Pickup (same day from the upstream watch, 2026-10-09; PP scope) Grill first: desk only, no card runs, no code. Tree read: master `f30ab09` (CONTROL `…-dx-w2t-b8k3-cph48`). Branch `grill/metal-59695-sdpa-gqa-flags` is cut from master, with no commits. Upstream: https://github.com/tenstorrent/tt-metal/pull/59695, **[Performance] SDPA: pack_gqa_heads, reuse_kv and single-K-chunk row sums for batched GQA prefill**, by amorrisonTT. - State: open. Filed 2026-10-07 17:40 UTC (19:40 Prague). - Size: 18 files, +836/−45. - **All four flags are opt-in and default off.** ### Their claims (theirs; Qwen3-4B-shaped embedding prefill: GQA 32/8, S=512, d=128, single P150) - **`pack_gqa_heads`:** schedules each GQA group as one head of `(NQH/NKH)·S` rows, so K/V streams once per KV head. bs1: 49.7 → 38.5 µs/call. - Under packing, q_chunk need not divide S: q192 35.9 → 29.3 µs. - Preconditions: **non-causal**, no `attn_mask`, tile-aligned unpadded S. - **`reuse_kv`:** a core keeps K/V across consecutive Q chunks of the same (batch, KV head). bs16: 512 → 355 µs. - Preconditions: **one K chunk (`k_chunk_size >= s`)**, the streaming kernel, `fp32_dest_acc_en=False`. Their guidance is to leave it off at batch 1. - **`math_thread_row_sums`:** single-K-chunk row sums on the math thread, −7…−8%. - Accuracy trade-off: per-row denominator error ~1.6× at S=1024 LoFi. - Ignored with more than one K chunk. ### Fit to our prefill SDPA (P4) - Ours is **causal chunked prefill over paged KV**: `QWEN36_SDPA_STREAMING` (`fp32_dest_acc_en=False`), LoFi (`QWEN36_SDPA_PREFILL_LOFI`), GQA multicast q128 (patch 0025/0026), and reader depth (0027). - `docs/OP-DATASHEETS.md` puts P4 chunked SDPA at **10.7% of the eager 30k chunk at HiFi2** (served LoFi ~−30%). It runs 96/110 cores, and its binding floor is unresolved (FPU vs SFPU exp). - **`pack_gqa_heads`: not applicable.** It is non-causal only, and our prefill is causal with a growing KV prefix. - **`reuse_kv` / `math_thread_row_sums`: not applicable** in the served shape. Both need a single K chunk covering the whole KV. Our chunks attend over up to the full 32k/128k prefix (many K chunks). - The only single-K-chunk call is the first chunk of a prompt (KV = the chunk itself). That is ≈ 1/16 of a 32k prefill and ≈ 1/64 of a 128k prefill. - Our GQA K/V-traffic problem is already addressed by the GQA multicast (0025/0026). Theirs is a different mechanism for the non-causal case. ### Estimate - **PP: ~0 on the served path** (derived from the preconditions above, not measured). - At most a first-chunk-only effect, bounded by P4's share of one chunk out of 16–64 chunks. - **TG: 0** (prefill op only). ### Grill questions 1. Close as **WATCH** (no port) unless upstream generalises packing/reuse to causal chunked prefill? 2. Is the first-chunk-only `reuse_kv` case worth anything at 4k (2 chunks)? Proposed: no. It needs `k_chunk >= s` plus a separate program at chunk 0, and the gain is bounded by P4 × ½ chunk. 3. Does `math_thread_row_sums`'s 16-bit DEST row-sum error class matter for #201 U6 (`QWEN36_SDPA_PREFILL_KCHUNK`)? No k passed U6's 1.05× fp64-error gate. ### Out of scope - No code, no card boots. Upstream numbers are **theirs**. ### Links - Upstream: https://github.com/tenstorrent/tt-metal/pull/59695, https://github.com/tenstorrent/tt-metal/pull/57395 (tracked on #154) - Ours: #201 (prefill U2–U7, U6 SDPA k_chunk), #154, #39 (BH SDPA watch), #151 (prefill AGMM / Tracy), #208 (metal bump)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitpartner/tt-stack#215
No description provided.