gqa: ADR-0060/0062/0063/0064 unified GQA kernels + CPU cost model
Land the new GQA fused-attention kernels (ADR-0060) for prefill/decode
across long and short context, the TL discipline primitives they depend
on (ADR-0062 lazy load, ADR-0063 scratch_scope + copy_to), and the
per-op-type CPU issue cost model (ADR-0064). Remove the pre-ADR-0060
mesh-attention baseline now that the unified kernels supersede it.
ADR-0060 (long context)
- _gqa_decode.py: M-fold + 2-level chain reduce-to-root (Level-2
intra-CUBE row-then-col + Level-1 inter-CUBE) — root-only output.
- _gqa_prefill.py: head-parallel + Ring KV rotation around C CUBEs,
online-softmax merge per ring step, per-CUBE distributed output.
- Each merge stage wraps in scratch_scope() and persists running
(m, l, O) via copy_to() to lift the 1 MiB scratch ceiling.
ADR-0060 §B.split.2 (short context, kv_per_cube in {1,2,4,8})
- _gqa_decode_short.py / _gqa_prefill_short.py: no cube-SP; each CUBE
owns whole KV heads; PE-parallel heads with intra-group chain
reduce. Prefill has no Ring KV (each head fully resident).
ADR-0062 (lazy tl.load): future-bearing TensorHandle, auto-wait at
first consuming op (dot/MATH/store/send/copy_to/composite).
ADR-0063 (tl.scratch_scope + tl.copy_to): scoped per-tile arena with
copy_to writeback primitive for persistent running state.
ADR-0064 (CPU issue cost model)
- common/cpu_issue_cost.py: per-op-type table (composite=40 ns,
primitives=5 ns); ratios are load-bearing per D1.
- TLContext: issue_cost_table param; _emit_dispatch_overhead(kind)
consults table with dispatch_cycles fallback (ADR-0046 §D6
back-compat).
- Live PE_CPU paths (greenlet + legacy) construct TLContext with
DEFAULT_CPU_ISSUE_COST so saturation lever (ADR-0060 §1) is
measurable end-to-end.
P7 headline bench: milestone-gqa-headline writes per-panel
op_log_summary to 1H_milestone_output/gqa_headline/sweep.json. No
figure renderers yet (deferred).
Removals (pre-ADR-0060 baseline now superseded):
- benches: _attention_mesh_kv.py, _attention_mesh_mlo.py,
_attention_mesh_mlo_2d.py, milestone_gqa_llama70b.py
- tests: test_attention_*, test_mesh_*, test_milestone_gqa_llama70b
- topology: llama70b_4sip.yaml (only consumer was the deleted diag)
- artifacts: 1H_milestone_output/gqa/ (sweep.json + 5 PNGs)
- tests/gqa/ plot helper + test (broken on Windows Tcl/Tkinter)
- ADR-0060/0061 references to deleted file paths cleaned up
(EN + KO kept in sync).
Tests: 124/124 focused regression green (attention + Phase E + TL
discipline + triton_emu + pe_components). Full regression: 764 pass,
2 pre-existing test_bench_registry failures (stale EXPECTED_NAMES
across multiple benches, not introduced here).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -32,9 +32,8 @@ the group is the decode-time efficiency win (ADR-0060 §5.2).
|
||||
|
||||
### Why it does not work today
|
||||
|
||||
The existing mesh kernels reshape tensors with a metadata-only helper
|
||||
`_view` (`src/kernbench/benches/_attention_mesh_kv.py:25-36`,
|
||||
`_attention_mesh_mlo.py:25-36`):
|
||||
Pre-ADR-0060 mesh kernels reshaped tensors with a metadata-only `_view`
|
||||
helper that rewrote `shape` but kept the original `nbytes`:
|
||||
|
||||
```python
|
||||
def _view(handle, new_shape):
|
||||
@@ -62,8 +61,7 @@ A reshape conserves bytes; a **broadcast does not** (`[S_kv, 1, d]` →
|
||||
kernel tries to view a `h_kv`-headed K as if it had `h_q` heads, the
|
||||
stored array has `1/G` of the requested bytes and `read` raises.
|
||||
|
||||
The current test suite documents this as a deliberate limitation
|
||||
(`tests/attention/test_milestone_gqa_llama70b.py:137-142`):
|
||||
The pre-ADR-0060 baseline documented this as a deliberate limitation:
|
||||
|
||||
> "v1 uses `h_q == h_kv == 1` to avoid … GQA broadcast view (which is
|
||||
> symbolic and does not survive MemoryStore's nbytes check under
|
||||
@@ -196,7 +194,7 @@ entire point of GQA (it `G×`'s KV-cache HBM footprint and bandwidth).
|
||||
2. **Phase 2 data**: broadcasting a known array yields the numpy
|
||||
`broadcast_to(...).copy()` result; a downstream `tl.dot` consuming it
|
||||
passes the MemoryStore nbytes check (the exact case that fails today).
|
||||
3. **GQA end-to-end**: re-run a reduced `milestone-gqa-llama70b` panel
|
||||
3. **GQA end-to-end**: re-run a reduced `milestone-gqa-headline` panel
|
||||
with `h_q=8, h_kv=1` under `enable_data=True`; it must complete (today
|
||||
it raises `ValueError: Shape mismatch`).
|
||||
4. **Broadcast-incompatible shape** (e.g. axis size 3 → 8) raises a
|
||||
|
||||
Reference in New Issue
Block a user