Skip to content

perf(hcu): optimize DeepSeek-V4 DSpark decode paths - #314

Open
lungy666 wants to merge 4 commits into
HYGON-AI:mainfrom
lungy666:perf/hcu-dsv4-decode-fast-paths
Open

lungy666 wants to merge 4 commits into
HYGON-AI:mainfrom
lungy666:perf/hcu-dsv4-decode-fast-paths

Conversation

@lungy666

@lungy666 lungy666 commented Sep 5, 2026

Copy link
Copy Markdown

Motivation

DeepSeek-V4 Flash with DSpark on HCU could not use several optimized kernels
without broad global switches or a matching recent sgl-kernel wheel:

  1. DsparkDraftSampler only admitted VanillaMarkov to the fused greedy
    proposal path. DSparkV4MarkovHead has the same vanilla Markov recurrence,
    but is a separate class and therefore materialized full-vocabulary bias and
    corrected-logit tensors on every proposal step.
  2. Some released HCU images do not contain
    torch.ops.sgl_kernel.deepseek_v4_topk_transform_512, while their LightOp
    package exposes the ABI-compatible fused transform.
  3. DSV4's existing SGLANG_OPT_BF16_FP32_GEMM_ALGO selector could not select
    the already-supported AITER path independently of the broad
    SGLANG_USE_AITER switch.

The result was avoidable decode latency on BW1000, especially at batch size 1.

Modifications

  • Make DSpark fused-greedy dispatch capability-based instead of checking the
    concrete VanillaMarkov class.
  • Implement sample_block_greedy_fused for DSparkV4MarkovHead using the
    existing MarkovGreedyStep kernel. It crops padded vocabulary columns and
    retains the eager path for genuinely TP-sharded Markov heads.
  • Prefer the existing sgl-kernel DSV4 AOT top-k op on HIP, and fall back to
    LightOp's ABI-compatible fused top-k/page-table transform when that op is not
    present.
  • Accept SGLANG_OPT_BF16_FP32_GEMM_ALGO=aiter as a narrow DSV4 compressor
    switch. SGLANG_USE_AITER=true keeps its existing behavior.
  • Add a CPU unit test proving a non-VanillaMarkov head can opt into the fused
    greedy interface without entering the eager fallback.

All performance-sensitive choices remain opt-in except the missing-AOT-op
fallback. The default compressor algorithm remains cublas.

Accuracy Tests

Test system:

  • 8 x Hygon BW1000 (gfx936), DTK 26.04, PyTorch 2.10
  • DeepSeek-V4-Flash-0731-W4A8-INT4-Channel-Attn-W8A8-INT8-Channel
  • TP8 + DP8 + DP Attention + DP LM head, DSpark gamma 5
  • temperature 0

GSM8K, five-shot Chat API, 50 examples, 8 client threads, max 1024 output
tokens:

Score Correct Latency Output throughput Mean DSpark accept length
1.000 50/50 21.370 s 281.606 tok/s 4.1817

The fixed long-form Chinese prompt also produced coherent, non-repeating
technical prose for exactly 1024 output tokens.

Precision note: AITER's tuned BF16 GEMM returns BF16-rounded values before this
function converts the tensor back to FP32. For M=6, N=1024, K=4096, comparison
against torch.mm(..., out_dtype=torch.float32) measured max absolute error
0.498169 and mean absolute error 0.070678. For that reason the AITER algorithm
is explicitly opt-in; users needing the original FP32-accumulation path keep
the default cublas setting.

The fused Markov kernel can select a different draft token on rare near ties
because it accumulates in FP32 instead of reproducing eager BF16 intermediate
rounding. These are proposals only; target verification still controls emitted
tokens.

Speed Tests and Profiling

Single-request OpenAI Chat API benchmark with a fixed realistic technical
writing prompt, temperature=0, ignore_eos=true, and exactly 1024 generated
tokens:

Compressor path Runs End-to-end throughput
strict FP32 accumulation 2 40.083, 41.024 tok/s
AITER BF16 GEMM (opt-in) 3, including cold restart 74.089, 73.407, 75.452 tok/s

The W4A8 MoE, communication settings, prompt, and other service configuration
were held constant for this A/B comparison.

Kernel measurements on one BW1000:

Operation and shape Before After Speedup
DSV4 top-k transform, M=6, L=4096, K=512 0.3575 ms 0.0111 ms 32.2x
compressor GEMM, M=6, N=1024, K=4096 0.6583 ms 0.0384 ms 17.1x
DSpark Markov greedy step, vocab=128800 0.7703 ms 0.1243 ms 6.2x

The top-k parity sweep covered mixed sequence lengths and confirmed that this
image had no DSV4 sgl-kernel AOT op, so the LightOp fallback was exercised
rather than merely imported.

Tests

  • pytest -q test/registered/spec/dspark/test_dspark_draft_path_default.py::TestDsparkFusedGreedyRouting::test_custom_markov_head_can_provide_fused_greedy_sampler
    • 1 passed
  • Direct HCU parity test for DSV4 fused greedy, including padded vocabulary
    cropping and TP-sharded fallback: passed.
  • Direct HCU LightOp top-k parity over sequence lengths 127, 512, 1025 and
    4096: passed.
  • Direct HCU SGLANG_OPT_BF16_FP32_GEMM_ALGO=aiter routing and output
    shape/dtype test: passed.
  • Black 26.1.0, isort 7.0.0, Ruff 0.15.1, codespell 2.4.1, compileall, and
    git diff --check: passed.

Checklist

  • Format code with the repository's pinned formatter versions.
  • Add and run a focused unit test.
  • Document the new algorithm value and numerical behavior inline.
  • Provide accuracy and speed benchmark results.
  • Follow the SGLang code style guidance.

CI States

Latest PR Test (Base): ❌ Missing run-ci label -- add it to run CI tests.
Latest PR Test (Extra): ❌ Blocked -- run-ci is required first.

@lungy666

lungy666 commented Sep 5, 2026

Copy link
Copy Markdown
Author

/tag-run-ci-label

Restore the HCU Stage B registration dropped during the upstream sync. The required workflow still includes this file, so its missing registration aborted all four partitions before test execution. Verified all 46 required files resolve across the four partitions with run_suite.py --list.
Install the shared pinned sgl-eval CLI in regular and image/wheel modes. Derive FP8 reference scales and one-ULP rounding bounds from the output format. Add the config_value interface to the serving-chat mock. Validated FP8 numeric cases on gfx936, 17 chat tests (one existing skip), installer branch/failure behavior, and actual pinned CLI installation in a disposable container.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant