Skip to content

Add FP4 Indexer for DeepSeek V4 - #26209

Merged
Fridge003 merged 1 commit into
sgl-project:mainfrom
liz-badada:FP4-indexer
Jun 2, 2026
Merged

Fridge003 merged 1 commit into
sgl-project:mainfrom
liz-badada:FP4-indexer

Conversation

@liz-badada

@liz-badada liz-badada commented May 24, 2026 •

Copy link
Copy Markdown
Collaborator

Modifications

  • Add an opt-in DeepSeek V4 FP4 indexer path with --enable-deepseek-v4-fp4-indexer.
  • Keep the default DeepSeek V4 indexer path unchanged.
  • Add FP4 indexer cache layout, FP4 Q/K quantization helpers, fused KV store path, and registered kernel tests.

Accuracy

GSM8K

Dataset FP8 indexer FP4 indexer
GSM8K 0.980 0.965

GPQA

Dataset N Metric FP8 indexer FP4 indexer
GPQA 198 pass@1 avg-of-16 0.835227 0.833333
GPQA 198 majority@16 0.845960 0.845960
GPQA 198 pass@16 0.944444 0.934343
GPQA 198 no_answer 0.030934 0.027462
export SGLANG_JIT_DEEPGEMM_FAST_WARMUP=1
export SGLANG_DEFAULT_THINKING=1
export SGLANG_REASONING_EFFORT=max
export PYTHONDONTWRITEBYTECODE=1

# Launch server: Default FP8 indexer
python3 -m sglang.launch_server --model-path /models/DeepSeek-V4/DeepSeek-V4-Flash --served-model-name deepseek-ai/DeepSeek-V4-Flash --host 127.0.0.1 --port 30000 --trust-remote-code --tp 4 --moe-runner-backend flashinfer_mxfp4 --chunked-prefill-size 4096 --disable-flashinfer-autotune

# Launch server: FP4 indexer
python3 -m sglang.launch_server --model-path /models/DeepSeek-V4/DeepSeek-V4-Flash --served-model-name deepseek-ai/DeepSeek-V4-Flash --host 127.0.0.1 --port 30000 --trust-remote-code --tp 4 --moe-runner-backend flashinfer_mxfp4 --chunked-prefill-size 4096 --disable-flashinfer-autotune --enable-deepseek-v4-fp4-indexer

# GSM8K FP8
python3 /bench_out/eval_gsm8k.py --label default_fp8_no_mtp --eval-name gsm8k --base-url http://127.0.0.1:30000/ --model deepseek-v4-flash --out-dir /bench_out --num-examples 200 --num-threads 128 --num-shots 5 --api completion --max-tokens 512

# GSM8K FP4
python3 /bench_out/eval_gsm8k.py --label fp4_indexer_no_mtp --eval-name gsm8k --base-url http://127.0.0.1:30000/ --model deepseek-v4-flash --out-dir /bench_out --num-examples 200 --num-threads 128 --num-shots 5 --api completion --max-tokens 512

# GPQA FP8 / FP4
sgl-eval run gpqa --model deepseek-ai/DeepSeek-V4-Flash --api-key "${OPENAI_API_KEY:-EMPTY}" --n-repeats 16 --max-tokens 200000 --temperature 1.0 --top-p 1.0 --thinking --from-dataset "${GPQA_DATASET_PATH}" --out-dir "${GPQA_OUT}" --base-url http://localhost:30000/v1

Speed Tests and Profiling

Kernel-Level

SM100, B=256, H=64, D=128, NextN=1, block_kv=64.

Case FP8 us FP4 us FP4 speedup FP8 eff TFLOPS FP4 eff TFLOPS FP8 logical BW FP4 logical BW
B=256, L=8192 58.18 39.04 1.49x 590.55 880.23 4.98 TB/s 3.98 TB/s
B=256, L=32768 184.62 121.04 1.53x 744.46 1135.48 6.20 TB/s 5.03 TB/s

E2E Fixed Long-Context

DeepSeek-V4-Flash, SM100, TP=4, flashinfer_mxfp4, fixed input ids, input_len=8192, output_len=1024, concurrency=256, --disable-radix-cache, 2 repeats.

Mode Metric Default FP8 indexer FP4 indexer FP4 speedup
no MTP total tok/s 27177.99 29409.28 1.08x
no MTP output tok/s 3019.78 3267.70 1.08x
no MTP req/s 2.95 3.19 1.08x
no MTP mean TTFT 32097.72 ms 29561.58 ms 1.09x
no MTP mean TPOT 53.35 ms 49.34 ms 1.08x
no MTP mean E2E 86672.76 ms 80038.84 ms 1.08x
MTP total tok/s 27211.11 28844.20 1.06x
MTP output tok/s 3023.46 3204.91 1.06x
MTP req/s 2.95 3.13 1.06x
MTP mean TTFT 32221.33 ms 30289.45 ms 1.06x
MTP mean TPOT 49.23 ms 46.67 ms 1.05x
MTP mean E2E 82586.15 ms 78035.07 ms 1.06x

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #26712479836
Latest PR Test (Extra): 🚫 Run #26794563741

@liz-badada liz-badada changed the title Add optional DeepSeek V4 FP4 indexer path Add FP4 Indexer for DeepSeek V4 May 24, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements an experimental FP4 C4 indexer for DeepSeek V4, including Triton kernels for quantization and storage, memory pool adjustments for reduced token sizes, and integration into the attention forward pass. Feedback suggests optimizing the hot path by caching server configuration flags and refining type hints to replace "Any" with a more specific Union type for the query tensor.

@liz-badada

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label May 25, 2026
@liz-badada

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@liz-badada

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

1 similar comment
@liz-badada

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@Fridge003 Fridge003 mentioned this pull request Jun 2, 2026
24 of 36 tasks
@Fridge003 Fridge003 added the run-ci-extra CI: also run the extra suite (requires run-ci) label Jun 2, 2026
@liz-badada

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

@Fridge003
Fridge003 merged commit 301bcf0 into sgl-project:main Jun 2, 2026
573 of 676 checks passed
mqhc2020 pushed a commit to mqhc2020/sglang that referenced this pull request Jun 2, 2026
@liz-badada liz-badada mentioned this pull request Jun 2, 2026
5 tasks done
hanming-lu pushed a commit that referenced this pull request Jun 3, 2026
vincentzed added a commit to vincentzed/sglang that referenced this pull request Jul 8, 2026
…gl-project#26209)

Add --enable-dsa-fp4-indexer (default off): store the DSA lightning-indexer
K cache as MXFP4 (E2M1 elements + packed UE8M0/32 scales, 68 B/token/layer)
instead of FP8 (128 B key + 4 B fp32 scale = 132 B/token/layer), a ~48% cut
of the indexer KV footprint, and route the indexer top-k logits through
DeepGEMM's FP4 MQA kernels.

This is a plumbing port of the DeepSeek-V4 FP4 indexer (sgl-project#26209) to the
shared DSA path; it reuses the existing V4 kernels unmodified:

- Store: quantize_fp4_indexer_tensor / store_fp4_index_k_cache
  (dsv4/fp4_indexer.py Triton kernels; bit-identical to DeepGEMM's
  per_token_cast_to_fp4(use_ue8m0=True, gran_k=32, use_packed_ue8m0=True)).
- Decode/verify top-k: deep_gemm.fp8_fp4_paged_mqa_logits over the 68 B
  paged layout.
- Prefill top-k: deep_gemm.fp8_fp4_mqa_logits over the gathered FP4 pair
  (the index_buf_accessor gathers are parametrized on a new
  pool.index_k_bytes_per_token instead of the hardcoded 128 B width).
- Q side is quantized with the same Triton FP4 quantizer after the eager
  RoPE(+Hadamard) split path, so both RoPE conventions (NeoX V3.2 /
  interleaved GLM-5.x) are handled; the per-token q_scale folding into the
  head-gate weights is dropped because the FP4 kernels consume q_sf
  directly.

Constraints / guards (fail loudly, never degrade silently):
- SM100+ only; DeepGEMM build must expose the FP4 MQA-logits kernels.
- DeepGEMM paged-MQA backend only (no cutedsl/aiter FP4 path).
- Indexer fusion is disabled under the flag (the fused kernels
  quantize/store the FP8 132 B layout).
- Incompatible with --enable-hisparse, DSA prefill-CP, and
  piecewise/breakable CUDA graph (explicit errors).
- Flag off: FP8 path byte-identical (132 B sizing and kernels unchanged).

MXFP4 only: the DeepGEMM sm100 MQA-logits kernel hardcodes E2M1+UE8M0;
there is no NVFP4/E4M3-scale mode.
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek jit-kernel run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants