Skip to content

[DeepSeek-V4.1] Commit the engram decode history inside the hash kernel - #39138

Merged
hnyls2002 merged 4 commits into
dsv4.1from
lsyin/dsv41-engram-commit
Sep 12, 2026
Merged

hnyls2002 merged 4 commits into
dsv4.1from
lsyin/dsv41-engram-commit

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

In decode every token is its request's newest token, so the engram hash kernel already holds the row that becomes the request's new n-gram history. This writes it from the kernel instead of the five torch ops that followed the kernel (req_pool_indices cast, out_cache_loc == 0, where, flip, index_put). The kernel keeps one pure entry point, engram_hash_ids, and gains a decode one, engram_hash_ids_and_commit, which advances history in place (rows whose out_cache_loc is 0 are graph padding and write nothing) and skips the predecessor table that only the extend commit reads. The hasher is one node in the decode CUDA graph; extend keeps the torch commit, and verify is unchanged.

Hash ids are integers, so the change is bitwise. test_engram_hash.py adds a 5-row decode case (a padded row aliasing a live slot) and a 100-row case over four programs, both checked against the naive oracle and the expected history table.

A/B against the dsv4.1 base on DeepSeek-V4.1-Flash, TP4/EP4 on 4x GB300, one server at a time:

base this PR
28-prompt greedy, 64 tokens, first-token top-5 logprobs 28/28 identical, all deltas 0
bs=1 decode, 1k in 227.9 tok/s 228.1 tok/s
bs=1 decode, 16k in 196.8 tok/s 197.5 tok/s
bs=64 decode, 1k in 5225 tok/s 5240 tok/s
16k-prompt TTFT 0.422 s 0.424 s
gsm8k 5-shot 1319 0.895 0.902

CI States

Latest PR Test (Base): ❌ Run #34656639330
Latest PR Test (Extra): ❌ Run #34656639236
Latest PR Test (AMD ROCm 10): ❌ Run #34656639290

@hnyls2002
hnyls2002 merged commit 3a42fc5 into dsv4.1 Sep 12, 2026
81 of 91 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/dsv41-engram-commit branch September 12, 2026 00:00
kevin-mii added a commit to kevin-mii/sglang that referenced this pull request Sep 12, 2026
…dense route, Engram

if _is_hip dispatches from the model into deepseek_common/amd (fused mHC boundary with deferred
coefficients, gfx950 dense helpers, index-Q one-launch, fused decode glue, SWA tail slicing), the Engram
image select, the new SGLANG_OPT_HIP_* switches, and the ROCm defaults for the aiter batched GEMM and
the FlashMLA backend. The Engram hash kernel runs on HIP too, so upstream's in-kernel decode commit
(sgl-project#39138) serves both platforms and the history is written once per step.

deepseek_v4_low_ratio_sources and _every_row_routed follow the ForwardBatch rename
num_token_non_padded_cpu -> global_num_token_non_padded_cpu (the old name is no longer a field), which
the HIP low-ratio path reads under the breakable prefill graph.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019tZvxNDYPWtWc7ZtfXuybA
kevin-mii added a commit to kevin-mii/sglang that referenced this pull request Sep 15, 2026
…dense route, Engram

if _is_hip dispatches from the model into deepseek_common/amd (fused mHC boundary with deferred
coefficients, gfx950 dense helpers, index-Q one-launch, fused decode glue, SWA tail slicing), the Engram
image select, the new SGLANG_OPT_HIP_* switches, and the ROCm defaults for the aiter batched GEMM and
the FlashMLA backend. The Engram hash kernel runs on HIP too, so upstream's in-kernel decode commit
(sgl-project#39138) serves both platforms and the history is written once per step.

deepseek_v4_low_ratio_sources and _every_row_routed follow the ForwardBatch rename
num_token_non_padded_cpu -> global_num_token_non_padded_cpu (the old name is no longer a field), which
the HIP low-ratio path reads under the breakable prefill graph.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019tZvxNDYPWtWc7ZtfXuybA
kevin-mii added a commit to kevin-mii/sglang that referenced this pull request Sep 16, 2026
…dense route, Engram

if _is_hip dispatches from the model into deepseek_common/amd (fused mHC boundary with deferred
coefficients, gfx950 dense helpers, index-Q one-launch, fused decode glue, SWA tail slicing), the Engram
image select, the new SGLANG_OPT_HIP_* switches, and the ROCm defaults for the aiter batched GEMM and
the FlashMLA backend. The Engram hash kernel runs on HIP too, so upstream's in-kernel decode commit
(sgl-project#39138) serves both platforms and the history is written once per step.

deepseek_v4_low_ratio_sources and _every_row_routed follow the ForwardBatch rename
num_token_non_padded_cpu -> global_num_token_non_padded_cpu (the old name is no longer a field), which
the HIP low-ratio path reads under the breakable prefill graph.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019tZvxNDYPWtWc7ZtfXuybA
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