gqa(decode-4cases): rename bench/kernels/panels with long_ctx token
The 4-cases comparative study is specifically about long-context
decode (LLaMA-3.1-70B, S_kv=128K, T_q=1); the long_ctx token in the
names makes the scope explicit and aligns with the existing
_gqa_attention_decode_long convention.
Renames (mechanical; no semantic change):
- bench file: milestone_gqa_decode_4cases.py
→ milestone_gqa_decode_long_ctx_4cases.py
- bench name: milestone-gqa-decode-4cases
→ milestone-gqa-decode-long-ctx-4cases
- output dir: 1H_milestone_output/gqa_decode_4cases/
→ 1H_milestone_output/gqa_decode_long_ctx_4cases/
- env vars: GQA_DECODE_4CASES_RUN / _TOPOLOGY
→ GQA_DECODE_LONG_CTX_4CASES_RUN / _TOPOLOGY
- 4 kernel files _gqa_attention_decode_<case>.py
→ _gqa_attention_decode_long_ctx_<case>.py
- 4 kernel functions gqa_attention_decode_<case>_kernel
→ gqa_attention_decode_long_ctx_<case>_kernel
- 4 dispatch kinds decode_<case> → decode_long_ctx_<case>
- 4 panel names single_kv_group_decode_gqa_<case>
→ single_kv_group_decode_long_ctx_gqa_<case>
- 4 helper functions _run_decode_panel_<case>
→ _run_decode_panel_long_ctx_<case>
- test file renamed in lockstep
Also: Case 4 smoke test now uses its case-specific helper
_run_decode_panel_long_ctx_cube_sp_pe_sp (consistent with Cases 1-3)
instead of the legacy _run_decode_panel from milestone_gqa_headline.
16 tests pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@ from kernbench.benches._gqa_attention_decode_long import _merge_running
|
||||
TILE_S_KV = 1024 # ADR-0063 §A.2 S_kv-axis tile sweep (per-tile width).
|
||||
|
||||
|
||||
def gqa_attention_decode_cube_repl_pe_sp_kernel(
|
||||
def gqa_attention_decode_long_ctx_cube_repl_pe_sp_kernel(
|
||||
q_ptr: int,
|
||||
k_ptr: int,
|
||||
v_ptr: int,
|
||||
+1
-1
@@ -31,7 +31,7 @@ from __future__ import annotations
|
||||
TILE_S_KV = 1024 # match decode_long — per-tile S_kv width (ADR-0063 §A.2).
|
||||
|
||||
|
||||
def gqa_attention_decode_cube_repl_pe_tp_kernel(
|
||||
def gqa_attention_decode_long_ctx_cube_repl_pe_tp_kernel(
|
||||
q_ptr: int,
|
||||
k_ptr: int,
|
||||
v_ptr: int,
|
||||
+1
-1
@@ -23,7 +23,7 @@ from kernbench.benches._gqa_attention_decode_long import (
|
||||
)
|
||||
|
||||
|
||||
def gqa_attention_decode_cube_sp_pe_sp_kernel(
|
||||
def gqa_attention_decode_long_ctx_cube_sp_pe_sp_kernel(
|
||||
q_ptr: int,
|
||||
k_ptr: int,
|
||||
v_ptr: int,
|
||||
+1
-1
@@ -33,7 +33,7 @@ from kernbench.benches._gqa_attention_decode_long import _merge_running
|
||||
TILE_S_KV = 1024 # ADR-0063 §A.2 S_kv-axis tile sweep (per-tile width).
|
||||
|
||||
|
||||
def gqa_attention_decode_cube_sp_pe_tp_kernel(
|
||||
def gqa_attention_decode_long_ctx_cube_sp_pe_tp_kernel(
|
||||
q_ptr: int,
|
||||
k_ptr: int,
|
||||
v_ptr: int,
|
||||
+47
-52
@@ -1,7 +1,8 @@
|
||||
"""milestone-gqa-decode-4cases: comparative study of 4 decode sharding cases.
|
||||
"""milestone-gqa-decode-long-ctx-4cases: long-context decode 4-cases study.
|
||||
|
||||
Per GQA_full_deck.pptx slides 11-17: 4 KV-cache sharding strategies on
|
||||
the LLaMA-3.1-70B single-KV-head group (8 cubes × 8 PEs):
|
||||
the LLaMA-3.1-70B single-KV-head group (8 cubes × 8 PEs) at long
|
||||
context (S_kv = 128K, T_q = 1):
|
||||
|
||||
Case 1 Cube-SP / PE-TP → KV split by S_kv across cubes; PEs TP on batch
|
||||
Case 2 Cube-Repl / PE-TP → full KV per cube; PEs TP on batch
|
||||
@@ -13,18 +14,11 @@ invocation and writes per-panel op_log_summary to sweep.json so the
|
||||
comparative analysis (latency, GEMM/MAC util, comm volume) can be
|
||||
generated from a single sweep.
|
||||
|
||||
Status (initial commit, 5C.D):
|
||||
- Case 4 panel implemented (uses _gqa_attention_decode_long with
|
||||
sub_w=4 — ADR-0060 §4.2 lrab-adapted center-root reduce; that is
|
||||
structurally Case 4 per slide 11 with the reduce-to-root variant
|
||||
of the AR pattern).
|
||||
- Cases 1-3 panels: TBD in subsequent sub-increments (5C.A/B/C).
|
||||
|
||||
Deviation from slide 13: slide prescribes AllReduce (every rank has
|
||||
the answer); the kernel does reduce-to-root (only the lrab center
|
||||
cube has it) per ADR-0060 §4. Treated as the kernbench Case-4 baseline.
|
||||
|
||||
Gated by ``GQA_DECODE_4CASES_RUN=1``.
|
||||
Gated by ``GQA_DECODE_LONG_CTX_4CASES_RUN=1``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -32,17 +26,17 @@ import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from kernbench.benches._gqa_attention_decode_cube_repl_pe_sp import (
|
||||
gqa_attention_decode_cube_repl_pe_sp_kernel,
|
||||
from kernbench.benches._gqa_attention_decode_long_ctx_cube_repl_pe_sp import (
|
||||
gqa_attention_decode_long_ctx_cube_repl_pe_sp_kernel,
|
||||
)
|
||||
from kernbench.benches._gqa_attention_decode_cube_repl_pe_tp import (
|
||||
gqa_attention_decode_cube_repl_pe_tp_kernel,
|
||||
from kernbench.benches._gqa_attention_decode_long_ctx_cube_repl_pe_tp import (
|
||||
gqa_attention_decode_long_ctx_cube_repl_pe_tp_kernel,
|
||||
)
|
||||
from kernbench.benches._gqa_attention_decode_cube_sp_pe_sp import (
|
||||
gqa_attention_decode_cube_sp_pe_sp_kernel,
|
||||
from kernbench.benches._gqa_attention_decode_long_ctx_cube_sp_pe_sp import (
|
||||
gqa_attention_decode_long_ctx_cube_sp_pe_sp_kernel,
|
||||
)
|
||||
from kernbench.benches._gqa_attention_decode_cube_sp_pe_tp import (
|
||||
gqa_attention_decode_cube_sp_pe_tp_kernel,
|
||||
from kernbench.benches._gqa_attention_decode_long_ctx_cube_sp_pe_tp import (
|
||||
gqa_attention_decode_long_ctx_cube_sp_pe_tp_kernel,
|
||||
)
|
||||
from kernbench.benches.milestone_gqa_headline import (
|
||||
_ccl_cfg,
|
||||
@@ -55,7 +49,7 @@ from kernbench.policy.placement.dp import DPPolicy
|
||||
_OUTPUT_DIR = (
|
||||
Path(__file__).resolve().parent
|
||||
/ "1H_milestone_output"
|
||||
/ "gqa_decode_4cases"
|
||||
/ "gqa_decode_long_ctx_4cases"
|
||||
)
|
||||
_SWEEP_JSON = _OUTPUT_DIR / "sweep.json"
|
||||
|
||||
@@ -64,10 +58,10 @@ _SWEEP_JSON = _OUTPUT_DIR / "sweep.json"
|
||||
|
||||
|
||||
_PANELS = (
|
||||
"single_kv_group_decode_gqa_cube_sp_pe_sp", # Case 4 ★ optimal
|
||||
"single_kv_group_decode_gqa_cube_repl_pe_tp", # Case 2 (no comm; 8× memory)
|
||||
"single_kv_group_decode_gqa_cube_repl_pe_sp", # Case 3 (intra-CUBE AR only; 8× memory)
|
||||
"single_kv_group_decode_gqa_cube_sp_pe_tp", # Case 1 (inter-CUBE lrab only; PE-TP B=1 waste)
|
||||
"single_kv_group_decode_long_ctx_gqa_cube_sp_pe_sp", # Case 4 ★ optimal
|
||||
"single_kv_group_decode_long_ctx_gqa_cube_repl_pe_tp", # Case 2 (no comm; 8× memory)
|
||||
"single_kv_group_decode_long_ctx_gqa_cube_repl_pe_sp", # Case 3 (intra-CUBE AR only; 8× memory)
|
||||
"single_kv_group_decode_long_ctx_gqa_cube_sp_pe_tp", # Case 1 (inter-CUBE lrab only; PE-TP B=1 waste)
|
||||
)
|
||||
|
||||
# Each entry: (kind, panel-specific params).
|
||||
@@ -76,7 +70,7 @@ _PANELS = (
|
||||
# 8 cubes (head-parallel group), 8 PEs/cube
|
||||
# S_kv = 128K (long-context decode), T_q = 1 (one new token per pass)
|
||||
_PANEL_DISPATCH: dict[str, tuple[str, dict]] = {
|
||||
"single_kv_group_decode_gqa_cube_sp_pe_sp": ("decode_cube_sp_pe_sp", {
|
||||
"single_kv_group_decode_long_ctx_gqa_cube_sp_pe_sp": ("decode_long_ctx_cube_sp_pe_sp", {
|
||||
# Case 4: KV split 64-way (Cube-SP × PE-SP), 2-level reduce.
|
||||
# The sub_w=4/sub_h=2 lrab center-root geometry (root cube 6) is
|
||||
# baked into the Case-4 wrapper kernel.
|
||||
@@ -84,7 +78,7 @@ _PANEL_DISPATCH: dict[str, tuple[str, dict]] = {
|
||||
"T_q": 1, "S_kv": 131_072,
|
||||
"d_head": 128, "h_q": 8, "h_kv": 1,
|
||||
}),
|
||||
"single_kv_group_decode_gqa_cube_repl_pe_tp": ("decode_cube_repl_pe_tp", {
|
||||
"single_kv_group_decode_long_ctx_gqa_cube_repl_pe_tp": ("decode_long_ctx_cube_repl_pe_tp", {
|
||||
# Case 2: K, V replicated everywhere (8× memory waste); PEs TP
|
||||
# on batch. For B=1 only one rank works (slide-11 PE-TP waste).
|
||||
# No inter-rank communication.
|
||||
@@ -92,7 +86,7 @@ _PANEL_DISPATCH: dict[str, tuple[str, dict]] = {
|
||||
"T_q": 1, "S_kv": 131_072,
|
||||
"d_head": 128, "h_q": 8, "h_kv": 1,
|
||||
}),
|
||||
"single_kv_group_decode_gqa_cube_repl_pe_sp": ("decode_cube_repl_pe_sp", {
|
||||
"single_kv_group_decode_long_ctx_gqa_cube_repl_pe_sp": ("decode_long_ctx_cube_repl_pe_sp", {
|
||||
# Case 3: K, V replicated per cube (8× memory); PEs SP on S_kv
|
||||
# within each cube. Intra-CUBE 8-way reduce; no inter-CUBE comm
|
||||
# (every cube ends with full answer; designated writer = cube 0).
|
||||
@@ -100,7 +94,7 @@ _PANEL_DISPATCH: dict[str, tuple[str, dict]] = {
|
||||
"T_q": 1, "S_kv": 131_072,
|
||||
"d_head": 128, "h_q": 8, "h_kv": 1,
|
||||
}),
|
||||
"single_kv_group_decode_gqa_cube_sp_pe_tp": ("decode_cube_sp_pe_tp", {
|
||||
"single_kv_group_decode_long_ctx_gqa_cube_sp_pe_tp": ("decode_long_ctx_cube_sp_pe_tp", {
|
||||
# Case 1: K, V split across cubes (S_local = S_kv/C per cube);
|
||||
# PEs TP on batch — at B=1 only PE 0 of each cube works (PE-TP
|
||||
# waste). Inter-CUBE lrab AR (root = cube 6); no intra-CUBE comm.
|
||||
@@ -114,7 +108,7 @@ _PANEL_DISPATCH: dict[str, tuple[str, dict]] = {
|
||||
# ── Per-panel runner ─────────────────────────────────────────────────
|
||||
|
||||
|
||||
def _run_decode_panel_cube_repl_pe_tp(
|
||||
def _run_decode_panel_long_ctx_cube_repl_pe_tp(
|
||||
ctx, *, panel: str, C: int, P: int,
|
||||
T_q: int, S_kv: int,
|
||||
d_head: int, h_q: int, h_kv: int,
|
||||
@@ -138,14 +132,14 @@ def _run_decode_panel_cube_repl_pe_tp(
|
||||
o = ctx.empty((T_q, h_q * d_head),
|
||||
dtype="f16", dp=dp_repl, name=f"{panel}_o")
|
||||
ctx.launch(
|
||||
panel, gqa_attention_decode_cube_repl_pe_tp_kernel,
|
||||
panel, gqa_attention_decode_long_ctx_cube_repl_pe_tp_kernel,
|
||||
q, k, v, o,
|
||||
T_q, S_kv, h_q, h_kv, d_head, C, P,
|
||||
_auto_dim_remap=False,
|
||||
)
|
||||
|
||||
|
||||
def _run_decode_panel_cube_repl_pe_sp(
|
||||
def _run_decode_panel_long_ctx_cube_repl_pe_sp(
|
||||
ctx, *, panel: str, C: int, P: int,
|
||||
T_q: int, S_kv: int,
|
||||
d_head: int, h_q: int, h_kv: int,
|
||||
@@ -171,14 +165,14 @@ def _run_decode_panel_cube_repl_pe_sp(
|
||||
o = ctx.empty((T_q, h_q * d_head),
|
||||
dtype="f16", dp=dp_full, name=f"{panel}_o")
|
||||
ctx.launch(
|
||||
panel, gqa_attention_decode_cube_repl_pe_sp_kernel,
|
||||
panel, gqa_attention_decode_long_ctx_cube_repl_pe_sp_kernel,
|
||||
q, k, v, o,
|
||||
T_q, S_kv, h_q, h_kv, d_head, C, P,
|
||||
_auto_dim_remap=False,
|
||||
)
|
||||
|
||||
|
||||
def _run_decode_panel_cube_sp_pe_tp(
|
||||
def _run_decode_panel_long_ctx_cube_sp_pe_tp(
|
||||
ctx, *, panel: str, C: int, P: int,
|
||||
T_q: int, S_kv: int,
|
||||
d_head: int, h_q: int, h_kv: int,
|
||||
@@ -205,14 +199,14 @@ def _run_decode_panel_cube_sp_pe_tp(
|
||||
o = ctx.empty((T_q, h_q * d_head),
|
||||
dtype="f16", dp=dp_full, name=f"{panel}_o")
|
||||
ctx.launch(
|
||||
panel, gqa_attention_decode_cube_sp_pe_tp_kernel,
|
||||
panel, gqa_attention_decode_long_ctx_cube_sp_pe_tp_kernel,
|
||||
q, k, v, o,
|
||||
T_q, S_kv, h_q, h_kv, d_head, C, P,
|
||||
_auto_dim_remap=False,
|
||||
)
|
||||
|
||||
|
||||
def _run_decode_panel_cube_sp_pe_sp(
|
||||
def _run_decode_panel_long_ctx_cube_sp_pe_sp(
|
||||
ctx, *, panel: str, C: int, P: int,
|
||||
T_q: int, S_kv: int,
|
||||
d_head: int, h_q: int, h_kv: int,
|
||||
@@ -237,7 +231,7 @@ def _run_decode_panel_cube_sp_pe_sp(
|
||||
o = ctx.empty((T_q, h_q * d_head),
|
||||
dtype="f16", dp=dp_full, name=f"{panel}_o")
|
||||
ctx.launch(
|
||||
panel, gqa_attention_decode_cube_sp_pe_sp_kernel,
|
||||
panel, gqa_attention_decode_long_ctx_cube_sp_pe_sp_kernel,
|
||||
q, k, v, o,
|
||||
T_q, S_kv, h_q, h_kv, d_head, C, P,
|
||||
_auto_dim_remap=False,
|
||||
@@ -248,17 +242,17 @@ def _make_bench_fn(panel: str):
|
||||
kind, params = _PANEL_DISPATCH[panel]
|
||||
|
||||
def _bench_fn(ctx):
|
||||
if kind == "decode_cube_sp_pe_sp":
|
||||
_run_decode_panel_cube_sp_pe_sp(ctx, panel=panel, **params)
|
||||
elif kind == "decode_cube_repl_pe_tp":
|
||||
_run_decode_panel_cube_repl_pe_tp(ctx, panel=panel, **params)
|
||||
elif kind == "decode_cube_repl_pe_sp":
|
||||
_run_decode_panel_cube_repl_pe_sp(ctx, panel=panel, **params)
|
||||
elif kind == "decode_cube_sp_pe_tp":
|
||||
_run_decode_panel_cube_sp_pe_tp(ctx, panel=panel, **params)
|
||||
if kind == "decode_long_ctx_cube_sp_pe_sp":
|
||||
_run_decode_panel_long_ctx_cube_sp_pe_sp(ctx, panel=panel, **params)
|
||||
elif kind == "decode_long_ctx_cube_repl_pe_tp":
|
||||
_run_decode_panel_long_ctx_cube_repl_pe_tp(ctx, panel=panel, **params)
|
||||
elif kind == "decode_long_ctx_cube_repl_pe_sp":
|
||||
_run_decode_panel_long_ctx_cube_repl_pe_sp(ctx, panel=panel, **params)
|
||||
elif kind == "decode_long_ctx_cube_sp_pe_tp":
|
||||
_run_decode_panel_long_ctx_cube_sp_pe_tp(ctx, panel=panel, **params)
|
||||
else:
|
||||
raise RuntimeError(
|
||||
f"milestone-gqa-decode-4cases panel {panel!r} has "
|
||||
f"milestone-gqa-decode-long-ctx-4cases panel {panel!r} has "
|
||||
f"unsupported kind={kind!r}."
|
||||
)
|
||||
return _bench_fn
|
||||
@@ -280,7 +274,7 @@ def _run_panel(panel: str, topology: str) -> dict:
|
||||
)
|
||||
if not result.completion.ok:
|
||||
raise RuntimeError(
|
||||
f"milestone-gqa-decode-4cases panel {panel!r} failed: "
|
||||
f"milestone-gqa-decode-long-ctx-4cases panel {panel!r} failed: "
|
||||
f"{result.completion}"
|
||||
)
|
||||
kind, params = _PANEL_DISPATCH[panel]
|
||||
@@ -296,25 +290,26 @@ def _run_panel(panel: str, topology: str) -> dict:
|
||||
|
||||
|
||||
@bench(
|
||||
name="milestone-gqa-decode-4cases",
|
||||
name="milestone-gqa-decode-long-ctx-4cases",
|
||||
description=(
|
||||
"Comparative decode study of 4 KV-cache sharding cases on the "
|
||||
"Long-context decode 4-cases comparative study on the "
|
||||
"LLaMA-3.1-70B single-KV-head group (8 cubes × 8 PEs)."
|
||||
),
|
||||
)
|
||||
def run(torch) -> None:
|
||||
"""Drive the registered decode case panels; write sweep.json.
|
||||
|
||||
Gated by GQA_DECODE_4CASES_RUN=1.
|
||||
Gated by GQA_DECODE_LONG_CTX_4CASES_RUN=1.
|
||||
"""
|
||||
_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
if not os.environ.get("GQA_DECODE_4CASES_RUN"):
|
||||
if not os.environ.get("GQA_DECODE_LONG_CTX_4CASES_RUN"):
|
||||
raise RuntimeError(
|
||||
"milestone-gqa-decode-4cases needs GQA_DECODE_4CASES_RUN=1."
|
||||
"milestone-gqa-decode-long-ctx-4cases needs "
|
||||
"GQA_DECODE_LONG_CTX_4CASES_RUN=1."
|
||||
)
|
||||
|
||||
topology = os.environ.get(
|
||||
"GQA_DECODE_4CASES_TOPOLOGY", "topology.yaml",
|
||||
"GQA_DECODE_LONG_CTX_4CASES_TOPOLOGY", "topology.yaml",
|
||||
)
|
||||
rows = [_run_panel(panel, topology) for panel in _PANELS]
|
||||
sweep = {
|
||||
@@ -324,5 +319,5 @@ def run(torch) -> None:
|
||||
}
|
||||
_SWEEP_JSON.write_text(json.dumps(sweep, indent=2))
|
||||
print(
|
||||
f" milestone-gqa-decode-4cases: {len(rows)} rows -> {_SWEEP_JSON}"
|
||||
f" milestone-gqa-decode-long-ctx-4cases: {len(rows)} rows -> {_SWEEP_JSON}"
|
||||
)
|
||||
Reference in New Issue
Block a user