Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
80 lines
6.6 KiB
Markdown
80 lines
6.6 KiB
Markdown
# Chain kernels: the GPU chain of the decode verify window and of the MTP draft step (`claude/chain-kernels`)
|
|
|
|
Status: tables of section 2 are measured (ledger CUPTI traces, jobs 9062/9004). Sections 4-6 are filled as the model-free probe and A/B jobs
|
|
(`tools/chain-probe/`, jobs `9c*`) report; a number without a job name is not measured.
|
|
|
|
## 0. Summary
|
|
|
|
* In the hit-heavy regime of real agent sessions the verify window is the GPU chain plus the host/PCIe waits. The port's chain is **the Original's chain**: kernel for kernel the
|
|
same launch shapes and the same durations (12,561 us per 4-row window for both, section 2). Nothing in the window is slower than the Original's equivalent, and nothing is faster,
|
|
so "the port must be faster than the Original" needs kernels that the Original does not have.
|
|
* The chain is **latency-bound, not bandwidth-bound**: 2,418 kernels per 4-row window, 25 to 60 per layer, HBM busy about a quarter of the time. The biggest losses against the
|
|
bandwidth floor are small-grid kernels with serial dependent loads: the hyper-connection read (3.4 ms, 27 % of the chain, about 4x its floor), the CPU-leg row copy and the plan
|
|
copy from mapped host memory, the GDN alpha/beta gates, the QSA decode attention chunk, the hyper-connection up projection.
|
|
* `chain_window.cu` holds bit-identical variants of those kernels (same operations, same order, loads issued ahead), plus a few fusions; all behind `LELEKA_CHAIN` (off by default).
|
|
* Draft vocabulary: section 7.
|
|
|
|
## 1. Tools
|
|
|
|
| tool | what |
|
|
| --- | --- |
|
|
| `tools/chain-probe/window_table.py` | per-role kernel table of the verify windows of two CUPTI traces (`claude/ledger`'s `tools/cupti-trace`, `scripts/profile/lct.py`) |
|
|
| `tools/chain-probe/chain_probe.cpp` | model-free probe: loads the sealed Original PTX and `chain_window.ptx`, runs both on real-size random inputs, compares **every output byte**, times both inside a CUDA graph with cold weights |
|
|
| `tools/chain-probe/mb_pdl.cu` | graph kernel-to-kernel latency with and without programmatic dependent launch, and prefetch-ahead |
|
|
| `tools/chain-probe/jobs/` | holder jobs: `9c5` paired A/B (chain off / on), `9c6` CUPTI traces of both arms, `9c7` draft vocabulary on the CRM replay |
|
|
| `scripts/chain/{build_rt,test_driver,seal_chain}.sh` | WSL builds, driver unit tests, compile+seal of `chain_window.ptx` with `compile_assets.py` / `seal_pins.py` |
|
|
|
|
## 2. The window, kernel by kernel (port against Original, hit regime)
|
|
|
|
Traces: ledger job 9062, `port-corpus-hit` (rt-base, no draft vocabulary bound) and `orig-corpus-hit` (unmodified Original, `--dump-routing` profile of the corpus's own routing,
|
|
static 2048 slots, ledger tracer). Windows of 4 rows (49 port / 115 Original windows) and 6 rows (6 / 22). "chain" = every kernel that is not a host or PCIe wait.
|
|
|
|
### 2.1 Four-row window
|
|
|
|
TABLE4
|
|
|
|
### 2.2 Six-row window
|
|
|
|
TABLE6
|
|
|
|
### 2.3 Gaps inside the graph
|
|
|
|
Every window is one stream and one graph; consecutive kernels start 64 to 128 ns after the previous one ends (98 % of 112,000 gaps in the 64-128 ns bin): 218 us per port window
|
|
(1.7 % of the chain), 239 us for the Original. There are no event gaps (no cross-stream edges) in the window. The graph kernel gap is therefore not where the chain is lost; the loss
|
|
is the 0.7 to 1.0 us a tiny kernel takes between its first and last thread, and the serial dependent loads of the small-grid kernels. The only exception in the Original's trace is
|
|
an 0.9 us hole after the QSA K projection (`native_mmvq_multi -> norm`, 11 us per window) which the port does not have.
|
|
|
|
### 2.4 Ranking against the floor (4 rows, HBM 1.69 TB/s)
|
|
|
|
| rank | family | port us/window | floor us | gap us | what limits it |
|
|
| --- | --- | ---: | ---: | ---: | --- |
|
|
| 1 | hyper-connection read: norm + staged down + up (96 calls, 13.1 MB each) | 3,391 | 910 (7.7 us HBM + 1.5 norm per call) | 2,480 | 41-block down projection 13 us (8 serial cp.async tiles), up 7.5 us (8 rows per warp loaded one behind the other) |
|
|
| 2 | routed experts gate/up + down (hits + staged) | 2,434 | 950 (1.6 GB) | ~1,500 | grouped MMQ at 12.5 us per call; ramp and tail of many small groups; not touched here |
|
|
| 3 | dense projections (qkv, z, out, q, k, v, shared) | 2,250 | ~2,000 | ~250 | at the HBM floor already |
|
|
| 4 | CPU-leg rows copy + plan copy + doorbell + their waits' PCIe reads | 1,040 | ~250 | ~790 | serial volatile loads from mapped host memory: 5 and 6 PCIe round trips |
|
|
| 5 | QSA decode attention chunk | 470 | ~60 | ~410 | 64 cells walked one dependent load at a time |
|
|
| 6 | GDN alpha/beta | 368 | ~100 | ~270 | 12 blocks, 10 dependent weight/activation rounds |
|
|
| 7 | greedy argmax (248,320 logits, one block per token) | 79 | 10 | ~70 | 243 dependent loads per thread |
|
|
| 8 | ~25 tiny kernels per layer (quantize, swiglu, scale, sigmoid, ...) | ~900 | | ~450 | launch + ramp (0.7-1.0 us each) |
|
|
|
|
Which families are slower than the Original's equivalents: none beyond noise; routed experts gate/up and down are +100 us each in the port because the 4-row set contains more groups
|
|
(the port's hit regime differs by about 2 experts per layer between the two runs); `doorbell` is 142 us faster in the port. Extra kernels the port has: the split QSA scores/topk/resolve
|
|
(`qsa_decode_scores`, `qsa_topk_ref`, `leleka_qsa_resolve`, `leleka_qsa_miss_copy`) replace the Original's `block_scores_multi`, `block_topk_reg` (+60 us), and the PLE history snapshot copies;
|
|
no port-only guard kernels exist in the verify window (they are in the MTP step, section 5).
|
|
|
|
## 7. The MTP draft vocabulary (coordinator request)
|
|
|
|
DRAFTVOCAB
|
|
|
|
## Agreement at long context and decode gain (jobs 9c5, 9d6)
|
|
|
|
* Speed (9c5, paired by corpus prompt, 5 prompts x 3 repeats, short prompts, static tier): `LELEKA_CHAIN=all` 74.13 tok/s against 72.53 without it
|
|
(+2.2 %); all 15 pairs are positive and the number of verify rounds is the same in both arms.
|
|
* Agreement (9d6): the 40 requests of the live CRM session 9e3 teacher-forced along their recorded tokens (about 64k rows at 30-70k tokens of
|
|
context), top-16 log-probabilities of every row, against the same run without the chain kernels (arm G of 9d4, same chunk cut, static tier).
|
|
The kernels are NOT bit-identical at this length (the fusions change rounding): 5,993 of 64,355 rows are identical, d_top1 p99 0.327, max 4.31,
|
|
dmax16 p99 3.48, argmax flips 697 (1.08 %). The control for rounding noise is a chunk-cut change of the exact path (job 9d5): p99 0.394, max 4.64,
|
|
flips 1.45 %. The chain kernels deviate less than that, so they are within the rounding noise of any change in the order of the arithmetic
|
|
(the rule of `scripts/quality/q_tail_gate.py`: each of p99, max and flip rate at most 1.25 x the control's). They are enabled by the
|
|
`rtx5090-32g` profile (`engine_env`).
|