Add optional sparse-prefill statistics without conversion launches #17
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #17"
general
weight: 0.35
DarkSharpness
Motivation
SGLang's compatibility entry point
csrc/python_api.cpp::sparse_prefill_fwdcurrently launches twoTensor::mul_kernels after attention to convertmax_logitsandlsefrom natural-log to base-2 units. For short H64 prefill, these launches cost about 2.2–2.5 us even under CUDA Graph replay.This removes compatibility-layer overhead, not attention computation. Following DarkSharpness's review, sparse prefill now supports optional statistics without post-attention
mul_launches on any supported prefill path. Native FlashMLA keeps its natural-log default.Related: https://github.com/sgl-project/sglang/pull/41512 skips these conversions for a packed output-only serving API. This change instead preserves all three outputs on the ordinary H64 API. It does not add conversion savings to that packed output-only path. When combined with #14, its packed parameter initializer and the downstream dependency pin will need updating.
Changes
return_log2_lse: the SGL compatibility API defaults toTrue, preserving its base-2 statistics;Falsereturns(output, None, None)and skips both statistics allocations/stores.return_log2_lse=None. ExplicitTruerequests base-2 statistics;Falserequests output only. This intentional default distinction avoids silently changing existing native callers' numerical contract. Legacy seven-argument native calls still work, and the returned list container is preserved.Tensor::mul_conversions in either statistics-enabled or output-only mode.No head-width/dispatch expansion, QK/PV changes, shared-memory/TMEM layout changes, or decode changes. Sinks still affect only output normalization. Empty-row sentinels remain output=0, max=-inf, LSE=+inf. Auxiliary results are numerically equivalent, not promised bitwise identical after eliminating the max's base2->natural->base2 round trip.
Historical fusion-only A/B
The measurements below validated the earlier
1dd928bimplementation, not the latest optional-statistics API changes. H128 still had the two conversion launches in that measured implementation.Clean baseline from
3620b63, versus that patch; identical compiler flags, inputs, allocation contracts, and all three outputs. Built separate symbol-isolated DSOs from the actual C++ entry points, with a third same-binary control that restores the two multiplies. No native-head or Gluon experiment code is included.Median of nine interleaved CUDA-graph measurements; 32 real H64 queries, D512, 8192 cached tokens:
| GPU | Top-k | Original us | Fused us | Speedup |
|---|---:|---:|---:|---:|
| GB200 | 128 | 8.533 | 6.374 | 1.34x |
| GB300 | 128 | 8.925 | 6.454 | 1.38x |
| GB200 | 512 | 14.620 | 12.417 | 1.18x |
| GB300 | 512 | 14.664 | 12.203 | 1.20x |
| GB200 | 2048 | 38.337 | 36.211 | 1.06x |
| GB300 | 2048 | 37.385 | 34.960 | 1.07x |
The restored-multiplies control at top-k128 is 8.543/8.925 us respectively, matching the original rather than the fused path. Profiling confirms 3 GPU kernels -> 1 for H64, while H128 correctly retains 3. The one-kernel regression test fails on the untouched baseline and passes on the candidate.
Additional sweeps varied queries 1/32/128/512, D512/D576, top-k128/512/2048, and selected KV allocations 1K/8K/128K/1M. These are operator microbenchmarks, primarily warm-cache graph replay, not model throughput or a blanket 30% gain for arbitrary contexts. Eviction controls were also checked, but are not used for the headline result.
Validation
Fresh optional-API validation (
6f9da943b2454d46af89bcb0cf3e67aae4203ed6): 144/144 native prefill cases passed on GB300/SM103 with CUDA 13.0.88 and PyTorch 2.14.1+cu130, including natural-log defaults, explicit base-2/output-only modes, legacy seven-argument calls, masks/empty rows, sinks, regular/small-topk H128, H64, D512/D576, and mutated CUDA Graph replay. These used a separately compiled prefill-only DSO with the actual native pybind registration and unmodified Python facade, not a complete installed FlashMLA wheel. The paired merged SGLang head0fb8a8f742now built its actual SM100f/SM103a CMakeflashmla_opstarget, including both bindings and all 18 Mega CUDA sources. Against that real target, optional-statistics tests passed 193/193, MegaAttention 4/4, serving caller contracts 37 with 2 SM90-only skips, and server-args 428/428: 662 passed / 2 architecture skips / 0 failures/errors. The profiler cases confirm a single attention kernel with no statistics-conversion launches for True/False, H64/H128, D512/D576, and small/regular top-k paths. This is a full FlashMLA target build, not a complete SGLang wheel/all-common-ops rebuild or Hopper validation. Earlier isolated compatibility/boxing evidence at5e7360cc64remains separately archived, not relabeled.Native job
1218787completed in 3m37s; compatibility retry1220016in 11m59s; actual merged-target CPU build1220991in 10m06s and GPU tests1221154in 1m47s. All allocations were released; cumulative related four-GPU time is 18m23s. Evidence:/tmp/fresh-review-evidence-bd90b/optional-stats/results/native.xml,results/retry/optional-stats/, andresults/merged-full-aot/in the author's environment. Python AST/compile, targeted formatting/lint, mocked wrapper forwarding, layout/synchronization static comparisons, independent changed-code review, andgit diff --checkalso pass. No numerical tolerances were relaxed. Full wheel CI and Hopper runtime coverage remain outstanding.Historical validation of
1dd928b, CUDA 13.0, PyTorch 2.13.0+cu130, aarch64, on GB200 and GB300:git diff --checkpass.Remaining: full repository/wheel CI and Hopper runtime coverage. No claim of whole-library sanitizer cleanliness or end-to-end serving improvement. Ready for review; full wheel CI and Hopper runtime validation remain outstanding. Companion SGLang pin update and compatibility-unit/launch-count tests: https://github.com/sgl-project/sglang/pull/42232.
Native test:
python -m pytest -q tests/test_sparse_prefill_stats_units.py.