Repository navigation
Conversation
This branch has not been deployed
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.
Problem
During decode, DeepSeek-V4 runs two skinny fp32 GEMMs per layer (
hc_pre, plushc_headonce):[rows, 16384] x [24, 16384], 86 calls per step. Hererowsis the number of tokens in the step, i.e. 1-16 concurrent requests. The weight is only 1.5 MB, but BLAS has no good kernel for this shape:hc_mix(5090 / R9700)(per call, CUDA-graph steady state; full 1-64 row sweep is easy to reproduce with the tests' shapes)
Change
hc.py: new split-K GEMVhc_mix(a partial kernel over K chunks, then a fixed-order reduce, so it is deterministic).model.py:hc_preandhc_headcall it through_mixwhenrows <= HC_MIX_MAX_ROWS(32 on CUDA, 64 on ROCm, where BLAS stays slow longer). Larger row counts (prefill) keep the originalF.linearpath.bf16_linear.py:bf16_linear_fp32had a GEMV only for M=1 and fell back toF.linearfor M>1. It now handles M <= 16 in the same kernel (each program loops over the rows, so the weight tile comes from cache). Callers: compressorwkv/wgateand the V4 / V4.1 MoE gate scores.No fp8, attention or comm code is touched; no new env vars.
Results
Aggregate decode tok/s, AIME 2024 prompts, greedy, <= 600 tokens/request, 2 launches each, 0 CPU-thread warnings.
main-> PR--disable-pynccl)Setup:
deepseek-ai/DeepSeek-V4-Flash,--moe-strategy hybrid --moe-hybrid-max-fetch 1, Triton 3.8.0; 5090: CUDA 13.2,--moe-cache-mem 12GiB,main81c162b; R9700 (gfx1201): torch 2.14.0+rocm10.1.0,--moe-cache-mem 16GiB.mainhas no DSV4 TP, so the R9700 run is on top of #952; with #952's default PyNCCL not buildable on ROCm, it uses--disable-pynccl. The R9700 runs used a local--distributed-timeoutflag (TP4 ranks finish loading >60 s apart); it is not part of this PR.Correctness
The fp32 accumulation order of two small GEMMs changes, so greedy outputs are not bit-identical to
main(gate top-k can flip on near-ties). On 40 addition prompts the answers differ frommainon 11/40 (sequential) and 3-9/40 (8 concurrent) on the 5090. That is the same size as the differencemainhas against itself between batch sizes (11-16/40). Accuracy 24 vs 27 sequential (sign test p ~ 0.26), no garbled output. Max abs error vs an fp32 reference is 1e-6 to 2e-5.Unit tests (new
test_dsv4_hc_mix.py,test_dsv4_bf16_linear.py, plus the unchanged fp8 / sparse-attn / e4m3 test files): 71 passed, 1 skipped on the 5090. On the R9700, 69 passed and 3@pytest.mark.slowtests intest_e4m3_compat.pyfail, identically on unmodifiedmain.Limitations
HC_MIX_MAX_ROWS = 32on CUDA comes from the microbenchmark only (no end-to-end test above CUDA graph batch size 8).bf16_linear_fp32too but was not tested on a V4.1 checkpoint; only Triton 3.8.0 was tested (pyproject.tomlallows>=3.6,<3.9).Reproduce
For R9700 use
--tensor-parallel-size 4 --gpu 0,1,2,3 --moe-cache-mem 16GiB --disable-pynccl. Client (same on both platforms; reads the 30 AIME 2024 problem strings from/tmp/aime.json; usageaime_client.py PORT C NPROB MAXTOK):aime_client.py