English · 简体中文
Overview · EPLB · DeepSeek-V4.1 · Host Path & Upstream PRs · 🐋 mini-DeepInfer · 📚 Engineering notes
DeepSeek inference & Ascend NPU engineering
SGLang sgl-kernel-npu DeepSeek Ascend 910C Ascend 950 CANNBot-DSL Triton
I work on DeepSeek inference on Ascend 910C and Ascend 950, contributing across SGLang and sgl-kernel-npu. My work spans the full serving path: MoE expert placement and weight migration, prefill/decode state handoff, NPU kernels and ACL Graph optimization, RadixCache/API/benchmark host bottlenecks, and end-to-end performance measurement.
| Track | Key upstream PRs | Verified outcome / scope |
|---|---|---|
| Dynamic EPLB on Ascend | Merged #47574, #49701, #48751* · Open #53290, #50784 · Draft #50517 | +36.93% 910C W8A8 PD throughput (2,648.89 → 3,627.05 tok/s); #53290 auto D128 +29.4% median PD tok/s on 8× A5 (217.65 → 281.66); async HCCL worst step 11.48 → 3.79 ms |
| DeepSeek-V4.1 on Ascend 950 & 910C | Merged #47660*, kernel #964*, kernel #1012 · Open #53702, #53837, #53836, #53835, #53709, #53715, #53963 · Draft #53965, #53977 | 7 CANNBot-DSL APIs; 29,553.51 tok/s on 8× A5 128K (+3.70% via #53702); Engram gate 389.4 → 153.1 µs (66 → 2 tasks); DSpark wo_a 1,023 → 159 µs; A3 Engram column restriction (#53963) |
| RadixCache, API & benchmark host path | Open #53862, #53718, #53757, #53726, #53760, #53761, #53762 | 128K RadixCache lookup 258.7 → 146.4 µs (match_at 176.2 → 73.4 µs); /generate validation 18.61 → 3.52 ms (~5.3×); /detokenize 24.54 → 17.40 ms; 128K prefix-only reload 648.44 → 5.11 MiB |
| PD handoff, MoE graph & NPU kernels | Merged #47934 · Open #53815, #53838, kernel #1077 + 21 targeted SGLang / kernel patches | Fixed A3 unequal-ring C4 handoff; TopK recorder mask skip -226 µs (320 → 160 tasks); HashTopK -45 µs; Triton allocator 13 → 3 cache entries (37.54 → 7.37 s) |
* Collaborated or follow-up merged PRs incorporating my patches or integration work (details below).
In an expert-parallel MoE, one overloaded rank can hold up the rest. Dynamic EPLB uses recent routing counts to decide where expert replicas should live, and only pays off when the reduction on slow ranks outweighs planning, weight migration, and routing-table switch costs.
EPLB study guide · GPU and NPU implementations · How the storage PR evolved · Dynamic interval tuning design · Foreground wait in async EPLB
- Initial Ascend dynamic EPLB. #47574 added the first NPU support using valid sender routing statistics and address-preserving weight updates.
- Isolate draft forwards from target statistics. I reported the rolling-window contamination in #48603 and opened the initial fix in #47922 (closed); ch-wan's merged #48751 incorporates the core fix.
- In-place physical expert storage migration. #49701 moves complete physical blocks through writable byte views, retaining FRACTAL_NZ padding and captured-graph allocations, reusing compatible TP/HCCL groups, isolating draft warmup/capture, and covering FP4 NZ format 50 on Ascend 950PR.
- Dynamic rebalance interval controller · Open. #53290 adds
recommendandautointerval policies over rolling routing windows, evaluating check/migration costs, routing overlap, and colocated/per-rank P95 guardrails (53 CPU/Gloo checks pass). On 8× Ascend 950DT DeepSeek-V4.1-Flash, switching a colocated worker from fixed64 → 128raised output throughput 569.6 → 661.7 tok/s (check time75.0 → 35.8 s); in PD disaggregated serving (663050a65),autotrialed and retainedD128over fixedD64, cutting check cost 28.15 → 13.09 ms/forward and lifting median output throughput +29.4% (217.65 → 281.66 tok/s, P95 TTFT2,743.76 → 1,648.05 ms, P95 TPOT32.12 → 31.56 ms, P95 E2E+4.9%). Design doc - Async HCCL P2P migration · Open. #50784 stages one layer at a time over a dedicated HCCL P2P group while serving continues on the current layout, then installs weights and routing rows in place once all ranks finish. Includes Ascend 910C migration and correctness checks; in an EP16 fixed-layout test, the worst forward step dropped from 11.48 to 3.79 ms while step P95 rose from 0.61 to 2.71 ms.
- Per-batch replica selection (LPLB) · Draft. #50517 distributes tokens across existing expert replicas per batch while preserving logical top-k choices, refreshing preallocated solver buffers in place after EPLB updates for captured graphs. In an earlier matched long-decode P/D test, throughput fell 6.33% and mean TPOT rose from 19.07 to 20.87 ms.
Choosing prefill and decode sampling windows and update intervals
Measured EPLB OFF → ON: output throughput 2,648.89 → 3,627.05 token/s (+36.93%) and mean E2E 50.49 → 36.39 s in the documented DeepSeek-V4-Flash W8A8 PD copying workload. Mean TPOT rose from 8.85 to 10.52 ms/token alongside the larger observed decode batch.
🔬 Experiment setup, acceptance counters & latency
The paired run at 08865d168 used Ascend 910C: 16 physical cards / 32 chips across P+D, TP16/EP16/attention-DP16 per endpoint, DSpark gamma 5 / verify 6, 16,384 input and 1,024 output tokens, concurrency 128, prefix/index caches disabled, and matched actual KV limits.
Throughput counts received generated tokens in the common [60, 360) s window. Latencies use successful requests started inside that window.
| Metric | EPLB OFF | EPLB ON |
|---|---|---|
| Output throughput, token/s | 2,648.89 | 3,627.05 |
| Mean TTFT, s | 41.43 | 25.63 |
| Mean TPOT, ms/token | 8.85 | 10.52 |
| Mean E2E, s | 50.49 | 36.39 |
| Acceptance length, tokens/verify | 5.988304 | 5.988304 |
| Measured strict draft acceptance | 100% | 100% |
| Correct / proposed draft tokens, latency cohort | 658,350 / 658,350 | 908,010 / 908,010 |
| Full-run successful / failed requests | 3,072 / 0 | 3,072 / 0 |
All 3,072 paired generated texts match. For the separate comparison of old ND and physical-byte migration costs, see the storage migration write-up.
- SGLang backend. #47660 adds low-ratio KV compression, two-level indexing, mixed-quantization sparse attention, graph replay, and DSpark on Ascend A5. I contributed the migrated operator API integration and metadata validation; related upstream alignment is tracked in draft #49005.
- NPU CANNBot-DSL operators. Worked with ClownBin on seven CANNBot-DSL compute and metadata APIs in sgl-kernel-npu #964 (dispatch contracts, PyTorch references/tests, and a K-tail storage fix). My merged #1012 unified all seven public wrappers, registry keys, tests, and docs under explicit
_dslnames.
- Remove
int64 LeftShiftin Engram E8M0 scale decoding · Open. #53702 replaces(exps << 23)withexponent * (1 << 23)(bitwise-exact across all 256 byte values), eliminating anint64 LeftShiftkernel that accounted for a median 4.58 ms per target-verify replay on 8× Ascend 950DT (isolated helper dropped 2.415 → 0.055 ms at(3,840, 24, 8)and 58.716 → 0.059 ms at(25,728, 24, 8)). Delivered the +3.70% 128K hot-cache throughput gain below. Write-up - Fuse the Engram gate on Ascend 950 · Open. #53837 reuses the Triton gate for contiguous BF16 activations (4 HC copies, hidden 4096/5120, ≥256 rows) with FP32 reductions and bitwise-exact image-token residual pass-through. On Ascend 950DT (two calls/graph), replay dropped 389.42 → 153.12 µs at 320×5120 and 538.24 → 153.50 µs at 480×5120 (10/10 pairs faster), cutting device tasks 66 → 2 (
383.4 → 103.0 µs). - Keep DSpark
wo_aoperands in BF16 on Ascend 950 · Open. #53836 replaces per-call FP32 casting inDSparkAttention._project_wo_a(avoiding a 128 MiB temporary weight cast for 8 groups × 1024 × 4096) with BF16 grouped transpose BMM. Single-NPU replay fell 1,023.0 → 159.4 µs (~6.4×) at 320 rows × 8 groups (256 rows: 777.8 → 158.3 µs); on an 8× A5 DeepSeek-V4.1-Flash C128 check (256/256 requests), output throughput rose 854.3 → 984.6 tok/s and TPOT fell 27.40 → 24.23 ms (AL2.896 → 2.901, strict draft acceptance44.46% → 44.75%). - Avoid MegaMoE for incompatible DSpark draft expert geometry · Open. #53715 resolves draft phase modes before AscendOps dispatcher construction on Ascend 950 when draft expert count or top-k differs from the target (e.g., 128/top-3 vs. 384/top-6), falling back from
fused_optoalltoallv(prefill) and MC2low_latency(decode) to preventaclnnMegaMoe EZ0024. Validated on 8× Ascend 950DT (416399706cdc): all 8 ranks captured both graphs and served 1,536/1,536 128K requests at concurrency 256 (13,258.43 tok/s full-run, 14,263.63 tok/s steady-state, mean TPOT 14.97 ms). - Cut graph-replay length & metadata overhead · Open. #53709 skips blocking device-to-host
seq_lens_cpu_intcopies during mirrorless DSpark draft verify replays (109.92 → 39.19 µs at B=32, saving ~70 µs/call; 66/66 tests, 24/24 128K retrieval). #53835 drops redundantFloorDiv+Castfor unusedseqused_cmp_kvin Ascend 950 CANNBot-DSL compressed attention (114 → 38 device tasks across 38 calls,-86 µs/replay, bitwise-exact BF16 across 24 eager/graph checks).
- Restrict Engram INT8 verify lookups to owned hash columns · Open. #53963 gathers and dequantizes only the 1–3 hash columns intersecting each TP rank's local shard instead of all 24 columns while keeping the full-width BF16 collective input (13 CPU tests pass; current-commit A3 validation pending). On an earlier Ascend 910C prototype, synthetic graph replay fell 3.742 → 0.316 ms at 2,240 rows (reading 2/24 columns) and 8-card W4A8 64K steady-state output throughput rose 11,797.31 → 12,489.28 tok/s (+5.87%).
- Opt-in paged candidate scoring (LI V2) for A3 verify & short extends · Draft. #53965 (fixed-shape graph verify) and #53977 (eager short extends with score-based native fallback) share a candidate-page planner that packs causally visible 8-token blocks for LightningIndexer V2. CPU oracle, dispatch, and fallback coverage is complete; current-commit Ascend 910C parity and serving measurements are pending.
Ascend 910C hot-prefix tuning guide
On November 28, two follow-up runs of DeepSeek-V4.1-Flash with #53702 reached 29,553.51 output tok/s across the full runs, up 3.70% from the earlier 28,500.16 tok/s on the same workload. Each run served 6,144 requests at concurrency 768 (131,072 input, 1,024 output, 99.90% on-device prefix hits). All 12,288 requests succeeded, with mean TTFT 3.42 s, TPOT 21.50 ms/token (down from 22.53 ms), and E2E 25.42 s (down from 26.48 s).
128K launch configuration guide · 128K decode tuning report up to 28,500.16 tok/s · Engram E8M0 int64 LeftShift analysis
📊 Per-run throughput and DSpark counters
- Full-run throughput: 29,033.89 and 30,092.06 tok/s. The combined figure divides total generated tokens by total elapsed wall time across both runs.
- Combined steady-state throughput: 30,398.04 tok/s. Mean acceptance length across the two formal runs was 4.0373 tokens/verify (colocated serving, DSpark gamma 4, verification width 5).
- Measured strict draft acceptance: 76.26% (593,055 accepted / 777,688 proposed across 194,422 verifies) in a separate 768-request diagnostic. Strict acceptance counters were unavailable in the formal throughput runs.
- Merged · A3 prefill/decode C4 state handoff. SGLang #47934 fixes C4 compressor state transfer across unequal prefill and decode ring sizes (8 vs. 16 rows) via row-sized registration and peer-local addressing.
- Open · Long-context RadixCache, API validation & detokenize hot path. #53862 compares zero-copy NumPy views with single-pass
argmax()inRadixKey.match_at()for windows ≥ 8,192 tokens (avoiding 1.875 MiB of copies on a 128K match), cutting AArch64 128K single-edgematch_prefix()from 258.68 → 146.40 µs andmatch_at()from 176.20 → 73.37 µs. #53718 cuts 128K/generatevalidation 18.608 → 3.516 ms (~5.3×), and #53757 cuts 128K/detokenize24.54 → 17.40 ms. - Open · Prefix-only benchmark & warm-cache host memory reuse. #53726, #53760, #53761, and #53762 eliminate redundant per-request token-ID and prompt-string copies across GSP, one-batch, and HiCache benchmarks—cutting 128 × 128K GSP reload private memory 648.44 → 5.11 MiB (cache
61.9 MB → 490 KB), one-batch 100% warmup lists 16.78 MB → 262 KB, and HiCache 100% prefix lists 35.84 MB → 562 KB. - Open · MoE ACL Graph task elimination. #53815 defers building
-1-masked TopK recorder copies until an active gatherer is selected, cutting 40-call TopK replay on Ascend 950DT from 674.15 → 448.43 µs at 320 rows (-225.84 µs, device tasks 320 → 160) and 757.60 → 528.25 µs at 480 rows. #53838 removes duplicate HashTopK padding masking without Waterfill (516.8 → 471.8 µs across 12 calls, dropping 3 tasks/call). - Open · Deduplicate Ascend Triton allocator compilations. sgl-kernel-npu #1077 keys
alloc_extendon the number of 2,048-token loop blocks instead of raw batch bounds. Across 15 fixed-batch inputs on Ascend 910C, Triton cache entries dropped 13 → 3, first compile + replay fell 37.54 → 7.37 s, and ~2.13 s stream-wide compile stalls observed in EP16 replay disappeared.
⚡ RadixCache, API & long-context benchmark host-path optimizations (7 Open PRs)
| Area | Engineering change & measured impact | PR | Status |
|---|---|---|---|
| RadixCache lookup | Zero-copy NumPy view + single-pass argmax() in RadixKey.match_at() for windows ≥ 8K (AArch64 128K match_prefix 258.68 → 146.40 µs, match_at 176.20 → 73.37 µs) |
#53862 | Open |
| API contract decoder | Exact-int fast path for generated TokenIds / Int64List / MatchedTokens decoders (18.608 → 3.516 ms for 128K IDs on Linux aarch64) |
#53718 | Open |
| Detokenize API | Reuse Pydantic-validated token IDs without extra scan/copy (24.54 → 17.40 ms for 1 × 128K; 22.80 → 16.49 ms for 8 × 16K) |
#53757 | Open |
| GSP token-ID dataset | Share group prefix token list when question_len=0 (128 × 128K generate 138.21 → 10.75 MiB, reload 648.44 → 5.11 MiB, pickle 61.9 MB → 490 KB) |
#53726 | Open |
| GSP text dataset | Reuse rendered first-turn text prompt & length per group (32 × 32K encode calls 32 → 1, pickle 4.09 MB → 129 KB; 512-row sampler 5.59 → 1.10 ms) |
#53760 | Open |
| One-batch benchmark | Share fixed prompt IDs across generation and warmup batches (32 × 32K at 100% warmup 16.78 MB → 262 KB) |
#53761 | Open |
| HiCache benchmark | Reuse full shared prefix list at --pcts 100 and release temporary 99% warmup slice (64 × 70K lists 64 → 1, 35.84 MB → 562 KB) |
#53762 | Open |
📦 SGLang MoE, PD/gateway, memory, attention & quantization patches (14 PRs: 13 Open, 1 Draft)
| Area | Engineering change | PR | Status |
|---|---|---|---|
| MoE graph | Skip unused TopK recorder masks when recording is inactive (674.15 → 448.43 µs, 320 → 160 tasks) |
#53815 | Open |
| MoE graph | Avoid masking HashTopK padding twice without Waterfill (516.8 → 471.8 µs, -3 tasks/call) |
#53838 | Open |
| Gateway lifecycle | Cancel pending prefill on early decode failures | #49792 | Open |
| Benchmark timing | Record PD decode handoff time for non-streaming metrics | #47772 | Open |
| Context memory | Bound DeepSeek-V4 RoPE tables by serving context | #47721 | Draft |
| Memory cleanup | Release temporary DeepSeek-V4 RoPE tables | #47718 | Open |
| Metadata reuse | Reuse CPU query lengths for prefill metadata | #47663 | Open |
| MLA / KV cache | Preserve NZ cache data during CPU retraction | #47659 | Open |
| Sparse KV | Preserve shared prefixes in physical host slots | #47654 | Open |
| MLA attention | Slice MLA latent K after TP all-gather | #47634 | Open |
| MoE | Honor SwiGLU clamp for BF16 and INT8 experts | #47656 | Open |
| MoE routing | Honor simple TopK scoring and routing scale | #47629 | Open |
| Quantization | Preserve AWQ weight dtype in linear fallback | #47639 | Open |
| Quantization | Correct GPTQ linear zero-point offset sign | #47637 | Open |
⚙️ NPU operator precision, tiling & graph replay in sgl-kernel-npu (9 Open PRs)
| Area | Engineering change | PR | Status |
|---|---|---|---|
| GDN numerics | Preserve Softplus accuracy in GDN gating and decode | #933 | Open |
| GDN layout | Normalize strided GDN gating inputs | #932 | Open |
| Sparse indexer | Exclude padded lanes from non-power-of-two decode TopK minimum | #935 | Open |
| Indexer cache | Include sparse attributes in the indexer tiling cache key | #926 | Open |
| RMSNorm | Compute weightless RMSNorm in float32 | #934 | Open |
| Graph replay | Preserve matmul tiling configurations across graph replays | #930 | Open |
| KV cache | Handle cache-location windows larger than 16 tokens | #925 | Open |
| Sampling | Handle fully masked leading tiles in argmax probability | #924 | Open |
| Compressor | Preserve arch22 accumulation order across batch sizes | #922 | Open |
- mini-DeepInfer — A runnable 14-lesson teaching inference engine tracing DeepInfer's execution design (scheduling, continuous batching, chunked prefill, KV-slot reclamation, and speculative decoding), with CPU walkthroughs and Qwen3.5 (0.8B draft / 2B target) generation on Ascend 910C. Repository
- LLM Inference Notes — My Chinese-language technical blog and engineering archive covering SGLang internals, Ascend deployment, EPLB, speculative decoding, and serving performance analysis, with source references and runnable labs. Blog
Inference, kernels, and a well-reproduced bug. Let's talk 🐋


