Repository navigation
perf(b12x/moe): optimize W4A8 inline 1-bit CSF staging and register-direct decode - #191
Open
voipmonitor wants to merge 1 commit into
Open
voipmonitor wants to merge 1 commit into
voipmonitor wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eliminates the decode regression and narrows prefill overhead for W4A8 MXFP4 inline 1-bit CSF (
--expert-scale-compression csf,destination == 3, bits == 1) on SM120, making inline CSF 3–5% faster than native scales on decode (M=4..128) and at parity on 16K prefill while preserving 100% bitwise lossless parity (max_err = 0.00000) and the full-3.41 GiB/GPU/+24%KV cache savings.Key Changes
STScp.asyncstaging + register-direct decode (b12x/_lib/quant/csf_inline.py):STS+sync_threads+LDS) withstage_compact_1bit(256B-aligned slot:cp.async1-bit codes + sparse exception positions/values up to 32/group, overlappingbounds_smemLDS.64ahead of code staging) and register-directdecode_compact_1bit_words/decode_compact_1bit_pair_words(PRMT+IMAD+LOP3+ single zero-exception skip branch + shared_patch_compact_1bit_exceptionsstaged +>32overflow fallback).prefetch_column_bounds_smem+ packed invariant lane row bases (load_lane_bases_packed/load_lane_pair_bases_packed) hoisted outside K-loops.w4a8_compact_projection.py):MicroProjection:88regs vs96native;CoalescedFC1:118vs124;CoalescedFC2:96regs,o128=5,STACK:0).w4a8_phase1.py,w4a8_phase2.py):tok_smemsync_threads(), unified 64-thread gate+up producer, register-direct interleaved pair decode (REG:255, STACK:0, LOCAL:0), noevict_firsthint on reused prefill scale blocks.mbarrier_initsync_threads()(REG:254, STACK:0, LOCAL:0)._tuning.py,tests/experimental/b12x/moe/test_mxfp4_csf.py):TUNING.candidate_contract_version(74 -> 75) so cached plans re-racecsf_inline_scales=(False, True).test_w4a8_inline_compact_1bit_exception_overflow_parityverifying bitwise parity (torch.equal) with>32exceptions/group (up to ~350/group),n64_tail(nr=64,nc=2), oddtopk(fused_groups=2), and poisoned scale scratch.Verification (SM120, RTX PRO 6000 Blackwell)
1. GPU Microbenchmarks — Real DeepSeek-V4.1-Flash Layer-10 Weights (
h=5120, n=576, E=384, topk=6, L2-flushed CUDA graphs,max_err = 0.00000)nativecsf_inlcsf_inlnativeM=1 micro:6441.0 us49.2 us (+20.0%)43.0 us+5.00%M=4 micro:6469.6 us67.6 us-2.99%fasterM=8 micro:64126.9 us122.9 us-3.20%fasterM=16..64 micro:64219–586 us209–561 us-3.9% to -4.7%fasterM=128 micro:64823.3 us782.3 us-4.98%fasterM=128 dynamic:16849.9 us815.1 us-4.09%fasterM=4096 dynamic:1281,354.7 us1,355.7 us+0.07%(Phase2 -6.0 us)M=8192 dynamic:1282,222.0 us2,244.1 us+0.99%(Phase2 -10.2 us)2. End-to-End Same-GPU A/B — DeepSeek-V4.1-Flash 16K TP4 C32 (
4x RTX PRO 6000, GPUs4–7)80.10 -> 76.69 GiB/GPU(-3.41 GiB/GPU), KV capacity17.03M -> 21.16Mtokens (+24.2%).qualify_release_16k:C=1step latency:5.734 -> 5.489 ms(-4.27%faster, vs+2.87%pre-opt).by_shapestep latency:B1xW8 -3.73%,B2xW8 -0.62%,B4xW8 -1.91%,B6xW8 -8.96%,B8xW8 -1.63%,B12xW8 -10.04%,B24xW8 -1.02%.C24_P256 +2.02%,C32_P256 +4.05%(1,581.7 vs 1,520.1 tok/s),C32_P2048 +0.72%(req +3.15%,step -1.29%).8K–128K, 10/10 needles):8K -0.31%,16K +0.00%,32K +0.05%,64K +0.21%,128K +0.20%GPU /+1.40%wall (vs-1.3% to -2.0%pre-opt).llm_decode_bench(max_tokens=8192,30s):ctx=0C1+3.11%/ C8+1.00%/ C32+2.42%(3,018.3 vs 2,946.9 tok/s);ctx=32kC1+3.54%/ C8+1.97%/ C32+1.12%.8K–128K:-1.2% to -1.6%.3. Tests
pytest tests/experimental/b12x/moe/test_mxfp4_csf.py(including newtest_w4a8_inline_compact_1bit_exception_overflow_parity): PASSpytest tests/experimental/b12x/moe/test_w4a8_compact_coalesced.py: 74/74 PASSpytest tests/experimental/b12x/quantization/test_mxfp4_csf.py tests/experimental/b12x/quantization/test_csf_warp_rows.py: PASSruff check&git diff --check: clean