Skip to content

[Model][SM70][FP8] Integrate calibrated E4M3 QSA KV capacity path - #462

Merged
yangzhuxinyzx merged 7 commits into
mainfrom
agent/v100-qwen4exp-e4m3-kv-main-20260903-045347
Sep 3, 2026
Merged

yangzhuxinyzx merged 7 commits into
mainfrom
agent/v100-qwen4exp-e4m3-kv-main-20260903-045347

Conversation

@yangzhuxinyzx

Copy link
Copy Markdown
Contributor

Purpose

Integrate the calibrated Qwen4Exp QSA E4M3 KV capacity path from #447 plus the independent hot-loop follow-ups #452 and #453 on current public main after #460.

This is an explicit capacity mode, not a new default. The validated contract is NVIDIA SM70, TP4, MTP0, FP16 activations, and a checkpoint-revision-bound 24-scale overlay. Unsupported combinations fail closed. Default FP16/BF16 KV and current FlashNext MTP4 serving behavior are unchanged.

Base SHA: c4c81296874771bd8cb256899ea0eb77970a4a6c.

Changes

  • Store only the main QSA K/V cache in calibrated E4M3; keep raw and compressed indexer caches in FP16.
  • Require all 24 finite positive per-layer K/V scales and refuse startup when the overlay is missing or incomplete.
  • Add offline calibration and revision-bound overlay tooling.
  • Cover Flash-V100 grouped page4, XQA, generic Triton, and mixed catch-up/decode batches.
  • Use the exact bitcast E4M3 software decoder and hoist K/V scaling out of per-element Triton load loops.
  • Preserve [Perf][SM70] Share Qwen4Exp QSA top-k workspace #460 model-level QSA top-k workspace sharing and its private-buffer fallback.

The only source conflict with current main was an adjacent-method insertion in qsa.py: #460 added _set_topk_indices_buffer, while #447 added validate_loaded_kv_scales. The integrated tree retains both. One #460 test fixture was updated with the now-required FP16 cache config.

Test Plan

Test Result

  • Integrated focused suite: 68 passed, 10 skipped. CUDA-only cases skipped because local GPUs were intentionally not used.
  • All changed-file pre-commit hooks passed, including Ruff, format, mypy, clang-format, SPDX, accelerator API, configuration, and attention-backend checks.
  • git diff --check and Python compile checks passed.
  • Original exact-runtime-commit V100 evidence: 4x V100, TP4, MTP0, full-and-piecewise CUDA Graph, NVFP4 and AWQ W4A16 checkpoints.
  • KV capacity: approximately 1.83x at the same memory budget.
  • Matched quality: 128K retrieval 6/6 vs 6/6, held-out tools 10/12 vs 10/12, GSM8K 29/32 vs 29/32, HumanEval/MBPP 9/10 vs 9/10, with zero paired regressions in those gates.
  • Performance tradeoff: E4M3 decode was approximately 1.92-2.54% slower and long-context server E2E approximately 1.26-3.12% slower, depending on checkpoint/matrix.

Validation boundary

  • This first-phase route deliberately requires MTP0 and TP4.
  • Prefix caching, MTP, TP8, and a 256K end-to-end run are not claimed as validated.
  • The capacity mode requires a scale overlay generated for the exact checkpoint revision; no generic or unit-scale fallback is accepted.
  • Default FlashNext FP16 KV, MTP4, prefix-cache, sampling, and output-quality paths are unchanged.

Provenance

Runtime and test commits retain the original #447/#452/#453 authorship and DCO trailers. OpenAI Codex assisted with latest-main integration, conflict review, test execution, and this write-up.

Leonccaa and others added 7 commits September 3, 2026 12:54
Add per-layer calibrated E4M3 K/V storage to Qwen4Exp QSA for the
fixed SM70, TP4, MTP0, and FP16 activation contract. The main QSA
cache uses E4M3 while the raw and compressed indexer caches remain FP16.

Design decisions:

- Keep checkpoint loading slots at an invalid -1.0 sentinel, separate
  from runtime scale buffers whose upstream default remains 1.0.
  Finalization validates and deletes the loading slots.
- Fail closed if any of the 12 layers' K/V scales is missing, non-finite,
  or non-positive. This intentionally replaces the upstream KV-cache
  warning and unit-scale fallback, and is confined to 1Cat-owned
  Qwen4Exp files.
- Keep indexer caches FP16 so K/V quantization cannot change QSA block
  selection.
- Use P256 for E4M3 on generic G6 XQA virtual-page4. The P1024
  specialization assumes the page1568 layout and is not valid here.
- Do not bundle a scale overlay. Generate an exact-checkpoint-revision-
  bound model-kvscales overlay with
  tools/qwen4_exp/qsa_kv_calibration.py; E4M3 startup rejects unless all
  24 scales are explicitly loaded.

Also add offline normal-inference scale collection, report and overlay
generation, and matched route/selected-block comparison.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
Apply the pinned CUDA formatter, add the required SPDX copyright header, and express the reference attention with equivalent matmul operations so the tensor subscripts do not trigger the spelling hook.

Co-authored-by: OpenAI Codex <codex@openai.com>

Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
E4M3 XQA accepts at most 16 query rows, while chunked scheduling can form non-grouped catch-up/decode batches above that limit. Route the divisible bulk through grouped page4 and split the remainder into supported XQA chunks instead of falling back to the larger Triton split-K workspace.

Add routing coverage and an SM70 numerical regression for the observed 46+1+1+1 request layout.

Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
The dedicated PLE offload process builds the full model structure on meta but intentionally loads only the PLE subtree. Skip QSA KV scale finalization in that process; it never runs QSA forward, while every GPU worker retains the existing 24/24 fail-closed gate.

Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
Route the existing QSA decoder symbol to the exact bitcast implementation. Keeping the call sites unchanged makes this optimization independent from the sibling scale-hoisting change while preserving the same Triton specialization and generated behavior validated in the combined performance tree.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
Fold the per-layer K scale into the post-dot softmax factor and apply the V scale after normalized accumulation. Split-K applies V scaling once after merge, while the single-split path applies it directly before the final store.

This independent follow-up keeps the existing scalar E4M3 decoder unchanged, removes per-element K/V scale multiplies, and preserves the FP16 constexpr branch and calibrated scale contract.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
Signed-off-by: yangzhuxinyzx <153831768+yangzhuxinyzx@users.noreply.github.com>
@yangzhuxinyzx
yangzhuxinyzx marked this pull request as ready for review September 3, 2026 05:02
@yangzhuxinyzx
yangzhuxinyzx merged commit ca73a34 into main Sep 3, 2026
4 checks passed
@yangzhuxinyzx
yangzhuxinyzx deleted the agent/v100-qwen4exp-e4m3-kv-main-20260903-045347 branch September 3, 2026 05:03
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.

2 participants