File size: 12,220 Bytes
addfd4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# SGLang interface and implementation audit — 2026-10-19

The 21 definitions are **not all direct replacements for current SGLang calls**.
Seven have tensor operands matching a specialized attention leaf, three dense
GEMMs flatten the engine's leading dimensions, and eleven retain structural
adapters. No full serving run with substituted candidate kernels has been
performed. Saved inputs are materialized contiguous tensors: original storage
offsets, aliasing and arbitrary engine strides are not retained by safetensors.
A matching shape/dimension order therefore does not prove storage-ABI parity.
Standalone correctness and native tensor-layout correspondence are
reported separately from integration.

The complete, per-definition record is [interfaces.json](interfaces.json). It
lists every native call, pinned source link, remaining adapter and required
integration work. It covers all 21 definitions, including both GDN variants.

## Sources and scope

The capture used SGLang `684fea8af3b11a5b51ec9966c02959a32ad3421c`.
Current calls were inspected at
[`0025f939`](https://github.com/sgl-project/sglang/tree/0025f9394421451aa09ec192a4a6e7928e14736b),
with the [0.5.22 release](https://github.com/sgl-project/sglang/releases/tag/v0.5.22)
checked separately. New SGLang-based solutions pin the inspected commit;
capture baselines intentionally retain their original commit. A final
[head recheck](upstream-head-recheck.json) at 11:43 UTC found SGLang one commit
ahead (`ed0b8f43`); its [examined diff](sglang-head-recheck-diff.json) changes
an NPU output-gate guard and the Ascend MoE runner, not these NVIDIA operator
boundaries. The other five upstream heads were unchanged. The tested commit
remains pinned rather than silently replacing it with untested code.

The current DeepGEMM `1fc9c669`, FlashMLA `0f11e178`, NATTEN 0.21.7 and FA4
4.0.0b35 already match the inspected upstream snapshots/releases. FlashInfer
0.7.2 is the current stable release. Its current development snapshot
`f64b4ba8` was also tested for raw-gate GDN prefill; it did not beat the release
path on the ten dev workloads. CUTLASS DSL 4.8.0 matches the tested SGLang
runtime; this audit does not infer a speed advantage from the newer 4.8.1
version number. Exact source metadata is in [upstreams.json](upstreams.json). The explicit
[preferred solution list](preferred-solutions.json) identifies one measured
choice per definition; serving baselines remain separate.

These are current maintained implementations and scoped comparisons among the
tested alternatives. This is not evidence of global optimality across all
possible implementations, devices or serving configurations. In particular,
the newer FlashMLA MegaAttention fusion needs pre-RoPE/normalization inputs,
positions and weight preparation absent from the existing MLA definitions.
It cannot be applied faithfully by changing only the packaged function.

## Feasible changes

- Dense attention now accepts only Q/K/V. The scale was fixed by head dimension
  in all 162 workloads. The SGLang wrapper returns the native output view
  without a gratuitous contiguous copy.
- Cached-prefix attention now accepts Q, prefix K/V and current K/V in native
  positional order. All 28 calls have full visibility; artificial image IDs,
  the all-true key mask and fixed scale are removed. Its FA4 implementation
  consequently needs no custom mask.
- The twelve prefix-zero workloads drop empty prefix K/V tensors, the all-true
  key mask and fixed scale. Their image IDs still encode a composed sequence of
  native text/image segment calls; this remaining difference is explicit.
- All 202 changed attention contracts were replayed against their original
  saved engine outputs, without relaxing the replay tolerance. Workload UUIDs,
  surviving tensor values and saved outputs are preserved. Thirteen unused
  tensor files are removed; previous replay records remain in provenance.
- Audio attention removes the FP16 conversions and uses BF16 FA4, with native
  SDPA for self-attention tiles up to 64 tokens. Both paths pass all 108 current
  workloads under the pre-existing 99.99% matched-element requirement.
- GDN uses maintained FlashInfer calls instead of the vendored wrappers.
  Decode copies the input state before invoking the mutating API. Both paths
  honor runtime scale, preserve the contest's disabled Q/K normalization, and
  pass all 154 workloads without input mutation. See the separate
  [precision report](../gdn-prefill-numerics.md): strict FP32 prefill state
  accuracy remains unresolved.
- QSA index uses current SGLang scoring and native fast Top-K only to discover
  the threshold. Deterministic Triton compaction restores lower-ID ties and
  ascending IDs, independent of the native unordered selection. Capacities at
  most 512 skip scoring altogether. All 192 actual workloads pass exactly;
  all-tied, empty, short and padded rows are checked separately.
- The router uses native FP32-output projection and fused sqrt-softplus,
  modality selection, Top-6, normalization and routed scale. One Triton kernel
  performs the required output ordering/int64 conversion. All 50 workloads
  retain exact selected IDs and the original strict FP32 weight tolerance.
- A current native TRT-LLM sparse-GQA solution is added alongside FA4; its 192
  workloads pass. Its cache/layout preparation is explicit rather than being
  described as a direct replacement for the serving backend.
- The four SGLang neighborhood wrappers now honor the engine's NATTEN branch
  when available, retaining the existing FlexAttention fallback. All 45 actual
  workloads pass both the default NATTEN and SGLang/NATTEN paths.
- The BF16 N=12288/K=4096 solution uses native linear on the three measured
  large-M B300 shapes where it beat DeepGEMM; other shapes and B200 retain
  DeepGEMM.
- The retained dense GEMM cannot enter the old M<=4/M=32 branch, so the branch
  and its conflicting CUTLASS dependency are removed. FA4 dependencies are
  aligned with the tested CUTLASS DSL 4.8.0 environment.

## Remaining interface differences

| Definitions | Native boundary still missing or adapted |
|---|---|
| GDN decode | Mutable state pool and slot indices, Q/K L2 normalization, actual serving model/head configuration |
| GDN prefill | Normalized Q/K, prepared alpha/beta, output buffers/checkpoints and serving model configuration. The native FlashInfer prefill leaf already gets gathered per-batch state; claiming it always takes a full pool would be incorrect. |
| Two grouped GEMMs | Four global expert shards combined into one task, padding removed, logical scale bytes and row order replacing per-rank physical buffers/m_indices |
| Two sparse MLA and mixed MLA | Four ranks' real heads combined; native per-rank zero padding/output slices, original cache pools, explicit lengths and scheduling metadata reconstructed |
| QSA index | Zero query heads removed, live-page compaction, ordered task IDs versus native unordered IDs |
| Sparse GQA | Snapshot after current-token KV write, compact pools, request maps and physical packing reconstructed |
| Router | Projection plus routing combined; boolean modality replaces token IDs; int64 sorted IDs and applied scaling differ from native outputs |
| Prefix-zero attention | Several text/image leaf calls combined into one block-causal operation |
| Three dense GEMMs | Original batch/sequence dimensions flattened into M |

Changing these definitions to the full native contracts requires new native
captures or an explicit integration API, especially for pool side effects and
per-rank operands. Identity indices, invented padding or fabricated missing
inputs would not prove interface parity. The current inputs and references are
preserved instead of silently changing the task's mathematical meaning.

## Validation and timing

All task tolerances, dev UUIDs, timing parameters and reference mathematical
operations are preserved. The four attention references only specialize inputs
whose invariants were checked for every affected workload. Both validation
runners read the explicit task tolerance, including the GDN absolute-or-relative
rule. Matched-element fractions use integer counts, and nonfinite outputs fail.
The historical strict GDN diagnostic is reported separately and is not marked
as passing.

The native input checker verifies all 21 definitions, 1,104 workloads and 5,493
tensor paths: shape, dtype, content hash, constraints, provenance and absence of
unreferenced files. The dataset has 5,111 unique snapshots. The complete changed
attention replay covers 202 workloads. Per-workload validation and scoped
comparisons are summarized in [performance.md](performance.md) and recorded in
[results.jsonl](results.jsonl) and
[summary.json](summary.json); source hashes identify earlier and final variants.

GPU measurements use B300, PyTorch 2.14.1+cu130 and the dependencies recorded in
the summary. Eager timings and prepared-launch graph timings are separate.
Graph timings include GPU conversions/padding/gathers within launch; only
explicit prepare work is excluded. In particular a prepared serving baseline
is not compared silently with an untimed preparation of the candidate.
Compilation, reference execution and input loading occur outside timing.
Measurements are standalone; they do not establish end-to-end serving speedups.

The initial QSA compatibility experiment used TileLang 0.1.12, as required by
current SGLang, and the old custom implementation mismatched 45 workloads.
Rechecking its declared TileLang 0.1.15 produced **192/192 exact passes**.
Therefore those failures are a dependency-version incompatibility, not evidence
that the old implementation fails with its declared environment. The final
implementation uses the current native scoring path on 0.1.12 and is compared
with the old implementation on its actual declared 0.1.15 dependency.

## Reproduce

Install the selected solution's pinned dependencies and materialize the dataset
with Git LFS. Different historical solutions can require separate environments.
Run the audit from the repository root:

```bash
python scripts/audit_solutions.py \
  --gpu GPU-UUID --lock-directory /path/to/locks \
  --suite all --reference-cache --graph-timing \
  --report results/audit.jsonl

# Inspect GDN's historical strict bound in addition to formal acceptance.
python scripts/audit_solutions.py \
  --gpu GPU-UUID --lock-directory /path/to/locks \
  --definition gdn_prefill_qk4_v8_d128_k_last \
  --suite dev --strict-diagnostic --scale-probe \
  --report results/gdn-diagnostics.jsonl

python scripts/check_workload_inputs.py
python -m unittest discover -s tests
```

`--data-root` can point to separately materialized tensors; `--cache-directory`
selects a writable reference/module cache. `--solution` and `--definition` are
repeatable. `--validation-only` skips timing. `--candidate /path/to/main.py`
compares an extra implementation on one selected definition. The script exits
nonzero on load or correctness failure; graph-capture failures are reported
separately from numerical correctness.

## Build details

NATTEN 0.21.7 was built for SM103 with `CXX_STD=20` in its CMake cache:
PyTorch 2.14 headers require C++20, while the upstream build defaults to C++17.
The kernel sources were unchanged. `NATTEN_BUILD_DIR` must name an existing
directory for that cache setting to be used.

FlashMLA was built at the recorded commit and its CUTLASS submodule
`4faf1a1568cf1e4ad8ff71846a13e16f2a6a6f6b`. CUDA 13.0 cannot compile that source;
the upstream minimum is 13.1. Both isolated 13.1.115 and 13.3.73 compiler builds
were evaluated on all 72 workloads. The 13.3 build triggered upstream's
register-spill performance guard for sparse FP8 decode; its documented
`FLASH_MLA_SKIP_REG_SPILL_CHECK=1` build option was used for the additional
comparison. This skips a compiler performance guard, not output validation.
All 72 numerical/input-immutability checks passed for both builds. The 13.3
build gives about 3.3% geometric-mean improvement for the 42 mixed-decode
workloads and about 0.6% for the two sparse-prefill groups in this measurement.
These are compiler-specific results, not an algorithm or interface change.