Skip to content

Fix duplicate global scaling in NVFP4 prefill workspaces - #43524

Closed
jethac wants to merge 1 commit into
sgl-project:mainfrom
jethac:fix/nvfp4-workspace-globals-main
Closed

jethac wants to merge 1 commit into
sgl-project:mainfrom
jethac:fix/nvfp4-workspace-globals-main

Conversation

@jethac

@jethac jethac commented Oct 10, 2026 •

Copy link
Copy Markdown

Motivation

FlashInfer prefill applies NVFP4 global K/V scales twice when reading the FP8
dequant workspace. The existing NVFP4 recipe restores physical values with
packed * block_scale * global_scale before conversion to FP8. Passing the same
global scales to the paged attention consumer then changes both logits and
output values. This affects non-unit scales in paged prefill and the cached
prefix of ragged prefill.

Modifications

Pass no additional K/V global scales to these two consumers when
prefill_uses_dequant_workspace is selected. Ordinary FP8 reads retain their
existing scale arguments. No decode, planner/CSR, native packed access, TRTLLM,
pool allocation or model-weight changes are included.

The branch starts at exact main
e35f60b9bcb51045fd0602d8ed12cff8021c040f. This is a standalone correction to
the existing workspace path. It does not require or duplicate native-prefill
#43471 or the FlashInfer decode/heterogeneous changes in #43247.

Reviewed candidate commit: 3c06207371 (DCO signed off, AI-attributed).

Accuracy Tests

Pinned CPU red/green regression with non-unit unequal global scales K=2, V=4:

  • Baseline main plus the new test: two workspace cases fail; two ordinary FP8
    control cases pass.
  • Corrected source: one test, all four subcases pass, covering paged prefill
    with physical fresh KV and ragged suffix/cached-prefix composition.

The test executes actual FlashInferAttnBackend.forward_extend and the actual
NVFP4 recipe's global-scale selection/FP8 conversion under a real scoped runtime
topology. It substitutes CPU numerical attention/merge and the CUDA unpack
primitive. It therefore verifies the serving consumer contract and numerical
regression, not compiled FlashInfer kernel execution or end-to-end model quality.

Exact CPU environment: /home/jethac/sglang-stage1-20261010/venv/bin/python,
CUDA_VISIBLE_DEVICES=99, PYTHONPATH=<exact-source>/python; command:

python test/registered/unit/layers/attention/test_nvfp4_workspace_globals.py

No GPU serving test has been run for this main-based source. Historical GPU
results from composed campaign branches are not used as evidence for this PR.

Speed Tests and Profiling

No performance benchmark or speed claim. The change only changes scale
arguments at existing calls.

Checklist

  • Format your code according to the contribution guide (scoped pre-commit formatting/lint passed).
  • Add registered CPU unit regression.
  • Update documentation (no user-facing option or behavior documentation change).
  • Provide accuracy and speed benchmarks (CPU regression only; no model/performance claim).
  • Follow SGLang code style; configured Ruff and syntax checks pass.

Implementation and regression were developed with OpenAI Codex under human
direction. The commit includes DCO sign-off and AI attribution. Maintainer
review and configured CI remain required before merge.

On Windows, three configured local hooks could not launch python3; the exact
scripts for bare pytest entry points, registered CI tests and package test
placement all passed when run with installed Python through uv run.


CI States

Latest PR Test (Base): ❌ Run #38037758892
Latest PR Test (Extra): ❌ Run #38037758612
Latest PR Test (AMD ROCm 10): ❌ Run #38037758784

Dequantized cached KV and physical current KV already carry their global scales. Pass no extra scale arguments to paged workspace reads or ragged cached-prefix reads; preserve ordinary FP8 and decode behavior. Add CPU numerical consumer red/green regression with unequal non-unit scales.

Assisted-by: OpenAI Codex
Signed-off-by: Jetha Chan <[email protected]>
@github-actions github-actions Bot added the blackwell SM100/SM120 label Oct 10, 2026
detain added a commit to detain/sglang that referenced this pull request Oct 19, 2026
…en prefill reads the FP8 dequant workspace

Both prefill consumers of the dequant workspace (paged prefill overlay + ragged cached-prefix paged read) passed layer.k/v_scale_float although the workspace restore already multiplied packed*block_scale*global_scale, doubling the checkpoint scales for non-unit values on --kv-cache-dtype=nvfp4. git apply -3 landed both hunks cleanly on the heavily customized file (KVLocPlan plan, ragged wrappers, dq workspace all survive; diff is +18/-4 pure PR semantics). PR test stubs adapted to the stack: forward_metadata carries prefill_wrappers_ragged=None (entry-175 list route falls back to the backend attr) and batch gains a plain-prefill forward_mode (stack spec-mode reject guard at the workspace read). Red/green verified: 2 subfails at pre-fix HEAD, 1P/4sub post-fix. 4/4 subtests pass on the fp8/legacy arms unchanged.
detain added a commit to detain/sglang that referenced this pull request Oct 19, 2026
…r snapshot release, sgl-project#43524 prefill double global-scale) + entry-206 test-gate follow-up + header sync
detain added a commit to detain/sglang that referenced this pull request Oct 30, 2026
…m re-plant, flashinfer_backend 175/208/233 re-plants + spec-workspace pool pair, trtllm_mha fail-loud, qsa folds, dsv4 wrapper redirect -- entries 54,57,64,102,120,166,175,176,178,192,194,200,203,208,210,213,233,241,125,118,184

gdn_backend.py (54/120/203): THE FULL fork delta RE-PLANTED onto the
  post-merge structure (the merge took upstream's file and the saved hunks
  were the loss): extend-side circular replayssm fold (metadata wiring +
  once-per-forward fold before _prefill_gates), the lossless-verify (u,k,g)
  tuple plumbing through target_verify (buffer kwargs + recurrent-fallback
  _lossless arm + the EAGLE-tree assert), _assert_lossless_verify_kernel
  (the FlashInfer verify kernel swallows **kwargs -- silent zero-ring class,
  fail here instead), and the SGLANG_GDN_REPLAYSSM_VERIFY_NUM_STAGES pin.
  Every supporting seam (spec_utils fold pair re-homed by B4-4 onto
  mamba_pool, TritonGDNKernel u/k/g params, pool-side buffers) verified
  live; hybrid_linear's accept-side twin survived.
flashinfer_backend.py (175/178/192/194/208/233): marker file with THREE
  confirmed losses re-planted -- (a) entry-233 sgl-project#45092 wrapper REUSE on both
  per-bs dicts (the double-capture wrong-output class is ACTIVE on this
  stack: graph_variants capture the same bs twice; merge restored the
  unconditional overwrite); (b) entry-208 sgl-project#43524 None-if-workspace scale
  arms on both forward_extend consumers (the merged pool DOES global-scale
  in dequantize_prev_kv -- unconditional k_scale_float double-scales);
  (c) entry-175 sgl-project#43356 speculative workspace: forward_extend mode split +
  eager draft-extend paged branch + pool methods (MHATokenToKVPool main +
  HybridLinearKVPool + SWA wrapper delegations; the quant-method seam
  dequantize_speculative_prefix_to_workspace arrived in-range and the pool
  accessor + backend wiring are OUR half). B3-8's 'no caller' dedupe was
  WRONG-DIRECTION: the callers are this route and its test.
  VERIFIED-PRESENT: entry-194 spec_kv_index_token_blocks at :2576,
  KVWriteLoc.for_layer x3, is_draft_extend_v2 x3; the 39-hunk saved delta
  is mostly re-sited fork content (access-kind refactor upstream itself
  landed in-range).
hybrid_linear_attn_backend.py (102/176/203): upstream-side patch dry-run
  proves ALREADY-FOLDED at the merge (36/36 hunks previously-applied);
  side-state getattr pair rides memory_pool's compat properties (:1721-34).
trtllm_mha_backend.py (64/178): entry-64 layers_mapping arm ABSORBED by
  layer_router (the merged pool routes full/SWA + waits there); entry-178
  SM120-FP8-KV fail-loud construction guard RE-PLANTED (FMHAv2 e4m3 raise
  class returns otherwise).
qsa folds (15/118/125/166/184/200/210/212/213): metadata VERIFIED-
  SUPERSEDED (the merged pack-kernel + sharded + CP-subset path is beyond
  the window delta); qsa_indexer folded (project_qk ensure_cos_sin_cache
  param -- the CP caller as merged TypeErrors without it -- + the guarded
  out-of-capture sizing safety net at both sites); sparse_attn folded the
  SLOT_INDICES int64 overflow guard (comment-hunk superseded by the fork's
  KV_IS_FP8 form); qwen_sparse_attn_backend folded the CP K/V side-stream
  PREFETCH MACHINERY (prefetch_cp_kv/_gather_cp_kv/_cp_kv_pending +
  leak-guard + join + release-ordering -- qwen4_exp.py:2614 CALLS
  prefetch_cp_kv so as merged the CP path AttributeErrors), the sync-free
  slot-table prefix reads, the device-built cu_k and max_q pass-through,
  and upstream's in-place paged-prefill fast path WITH a fork FP8 guard
  (our scaled stores need the descale pack loop; unscaled pools take the
  fast path exactly as upstream intends).
deepseek_v4.py (57/176): shared-experts symbols verified present; raw
  'from deep_gemm import' restored by the merge RE-REDIRECTED to the
  guarded wrapper (mega_moe sibling). glm5_next.py (176): upstream-side
  fold verified fully PRESENT (stale marker).

Battery ACTUALS (CVD=9, prod venv, PYTHONPATH=python, import sglang OK):
  test_flashinfer_nvfp4_speculative: 6F -> **6P** (re-anchored: iteration-
  ids plan seam, kv_layers store seam, dispatch_reason/ragged_verify_layout
  stub fields; all entry-175 beliefs PRESERVED, none weakened)
  test_qsa_cp_unit: 50F -> **65P/0F** across the pair
  gdn/replayssm CPU surface (extend_fold + verify_ple_commit + stages +
  prefill_graph): 5P/2S (stages honest-CUDA-skip)
  ruff F821+E9 + format: clean on all 14 files touched
  KNOWN CARRY: test_mega_moe_deepgemm_api 1F is the DOCUMENTED mega_moe
  class (pre-existing at b3207c7 with and without the B5-3 redirect;
  mxfp4.py's in-range wrapper import vs the test's deep_gemm fake) -> B2
  marker at :905 covers the test-side re-anchor.
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Thanks @jethac. Closing this because it is still a draft and has not been updated in 26 days.

Reopen it if the work is still relevant.

Some directories moved recently, so an older branch may need retargeting:
sgl-kernel/ -> python/sglang/kernels/aot/, python/sglang/jit_kernel/
-> python/sglang/kernels/jit/, docs/ -> docs/docs/ (.mdx),
bench_serving.py -> benchmark/serving.py, test/srt/ -> test/registered/.

@github-actions github-actions Bot closed this Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant