Skip to content

[Kernel][SM70] Group QSA Page4 prefill - #387

Merged
yangzhuxinyzx merged 5 commits into
mainfrom
codex/v100-qwen38-grouped-page4-prefill-20260828-144759
Aug 28, 2026
Merged

yangzhuxinyzx merged 5 commits into
mainfrom
codex/v100-qwen38-grouped-page4-prefill-20260828-144759

Conversation

@yangzhuxinyzx

@yangzhuxinyzx yangzhuxinyzx commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Purpose

Follow up #378 with the exact grouped Page4 QSA prefill route for Qwen3.8
Flash-Next on SM70/V100.

  • Group eight adjacent query rows so their overlapping sparse Page4 K/V blocks
    are loaded once, while preserving an exact 4-bit mask per query row.
  • Use Volta WMMA for QK and PV and skip inactive row tiles.
  • Add a deterministic GPU planner that maps logical QSA selections through the
    paged cache, groups blocks by active-row category, and validates request,
    visibility, logical-page, tail, and physical-page bounds.
  • Keep the existing single-row Page4 route as a 1024-partition fallback.
  • Add --cuda-profile-case so one case can be captured with Nsight in an
    already-loaded engine while endpoint gates remain outside the capture range.
  • Record the design, correctness gates, and isolated measurements in the SM70
    migration control document.

Test Plan

  1. Rebuild flash-attention-v100 for SM70.

  2. Run the QSA operator/cache and V1 Qwen3.8 cache targeted suites:

    pytest -q \
      tests/benchmarks/test_benchmark_sm70_decode.py \
      tests/models/qwen4_exp/test_qsa_ops.py \
      tests/models/qwen4_exp/test_qsa_cache.py \
      tests/v1/core/test_qwen4_exp_kv_cache.py
  3. Compare the grouped route against the Triton reference using production
    Qwen3.8 geometry, including early rows, Page16/Page4 boundaries, a partial
    tail, nonmonotonic physical pages, and all-invalid padding.

  4. Run the no-MTP TP4 endpoint gate at 32K/64K/131K and capture only an 8192
    profiling case with Nsight Systems and NVML in the same loaded engine.

Test Result

  • Targeted tests: 19 passed, 16 warnings in 8.72s.
  • Four repeated planner/kernel replays are bitwise deterministic.
  • 4096-row hybrid Page16/Page4 correctness gate: relative L2 2.434e-4,
    cosine 1.0; an all-invalid group is bitwise-equal zero.
  • Production-layout isolated route, including Python dispatch, GPU planning,
    padding, and attention: 16.132 ms median (15.588 ms minimum) versus
    Triton 55.940 ms, or 3.468x; maximum absolute error 1.22e-4, relative
    L2 3.535e-4, cosine 0.99999988.
  • Matching no-MTP TP4 pure-prefill throughput is 5998.65/5777.43/5450.92
    tok/s at 32K/64K/131K, improving the retained
    4532.07/4446.64/4108.16 baseline by 32.36%/29.93%/32.69%. An exact 8K
    case is 6394.74 tok/s. Arithmetic, Chinese, and every performance-case
    token hash are bitwise identical to the baseline. The long endpoint sweep
    overlapped host/disk activity from an unrelated GPU4-7 model load, so these
    are conservative values.
  • The clean double-locked Nsight capture reduces grouped QSA attention to
    9.632 ms per QSA layer/rank plus 0.362 ms planning, versus the old
    55.151 ms path (5.518x, 81.88% lower). Per-GPU kernel duty is
    98.27-98.61%; the post-QSA first hotspot is now the routed NVFP4 MoE chain,
    not launch gaps or QSA.

Essential Elements of an Effective PR Description Checklist
  • Purpose is described and linked to the merged precursor.
  • Test plan includes focused commands and the required endpoint gate.
  • Current correctness and isolated performance results are included.
  • The SM70 migration control document is updated.

Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
@yangzhuxinyzx

Copy link
Copy Markdown
Contributor Author

TP4 endpoint acceptance — passed

Final source/workload contract:

  • PR head: c334a77f8c2a0ab7b06970d40be49c3b755c3255.
  • The loaded Flash-V100 extension SHA256 is
    108d740581aac41f9d72618b366622ef6ac2c294837a7107fe544aa149ac3636;
    it was built before the final clang-format-only commit.
  • 4 x V100-SXM2-32GB, TP4, V2, Qwen3.8-Flash-Next-NVFP4, ModelOpt NVFP4,
    FP16 activations/KV, MTP off, 8192-token chunked prefill, PIECEWISE graph.
  • Quality-safe route: online QPN8, FP8 QPN8, GDN QPN8 split, QPN2, and QPN2
    prefill are all explicitly disabled. QPN-M1 only repacks checkpoint-native
    FP4 expert weights for decode.
Case Pure prefill Prompt throughput Repeats
8K 1.281053 s mean / 1.280154 s median 6394.74 tok/s mean / 6399.23 tok/s median 3
32K 5.462565 s 5998.65 tok/s 2
64K 11.343458 s 5777.43 tok/s 2
131K 24.032633 s 5450.92 tok/s 1

The 8K pure-prefill samples are
1.283281 / 1.280154 / 1.279723 s (0.124% population CV). Relative to the
latest QPN8-off pre-Page4 8K observation (1.842520 s, 4446.08 tok/s), this
is 1.4383x, a 43.83% throughput increase and 30.47% latency reduction.
Relative to the retained BN16 long-context baseline, 32K/64K/131K improve
1.3236x / 1.2993x / 1.3269x.

Quality and route gates:

  • Arithmetic remains 42<|im_end|>, token hash
    93def17bbf14ec663ecd18061fa1ebaa5c7171deb4b1c64a16cb6c5e47213173.
  • Chinese remains 在标准大气压下,水的沸点是100摄氏度。<|im_end|>, token hash
    11d98c01ccdae0ca8d2d19e36486b4a7e35c3042160f646a92019ab1e2a67334.
  • All repeated performance-case token hashes are stable and exactly match the
    retained pre-Page4 baseline.
  • Runtime log proves the grouped route at both full and tail chunks:
    rows=8192, groups=1024 and rows=8120, groups=1015.
  • Peak device memory is 29493 MiB on every rank. Minimum host MemAvailable is
    34.441 GiB; minimum SwapFree is 244.539 GiB.

The focused 8K trace was recovered as both .nsys-rep and SQLite. Critical
rank NVTX wall is about 1260.5 ms; kernel span is 1288.5 ms. Grouped QSA
attention is 116.791 ms total across 12 layers and its planner is 4.371 ms.
The preceding selected-attention trace was 55.151 ms/layer, or 661.812 ms;
the new 121.162 ms attention+planner total saves 540.650 ms, closely
closing the measured 561.467 ms endpoint reduction.

The new first-order hotspots on rank 0 are NVFP4 MoE GEMM (308.187 ms,
24.22%), dense FP16 GEMM families, NCCL all-reduce (118.651 ms, 9.33%),
grouped QSA attention (116.791 ms, 9.18%), hyperconnection combine/norm
(82.453 ms, 6.48%), row expansion (71.380 ms, 5.61%), and FlashQLA GDN
(56.647 ms, 4.45%). QSA is no longer the dominant bottleneck.

Final local evidence:

  • JSON: .artifacts/qwen38_grouped_page4_prefill_20260828/results/grouped-page4-endpoint-profile-tp4.json
  • Log: .artifacts/qwen38_grouped_page4_prefill_20260828/results/grouped-page4-endpoint-profile-tp4.log
  • Trace: .artifacts/qwen38_grouped_page4_prefill_20260828/profiles/grouped-page4-endpoint-profile-tp4.nsys-rep
  • SQLite: .artifacts/qwen38_grouped_page4_prefill_20260828/profiles/grouped-page4-endpoint-profile-tp4.sqlite

The endpoint/quality gate passes. Keep the PR Draft while the post-Page4 trace
is used to select the next GEMM/MoE/hyperconnection optimization.

Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant