Skip to content

[Fix] Stop DeepSeek-V4.1 encoder bounded replay from crashing on the first prefill without speculation - #42902

Closed
vincentzed wants to merge 1 commit into
sgl-project:mainfrom
vincentzed:fix-dsv41-encoder-replay-no-spec-crash
Closed

vincentzed wants to merge 1 commit into
sgl-project:mainfrom
vincentzed:fix-dsv41-encoder-replay-no-spec-crash

Conversation

@vincentzed

@vincentzed vincentzed commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On main, a DeepSeek-V4.1 server started with --enable-encoder-swa-bounded-replay and no speculative decoding crashes on its first prefill:

AttributeError: 'DeepSeekV4TokenToKVPool' object has no attribute 'full_to_swa_index_mapping'

Why it crashes:

  • Prefill reads the attribute full_to_swa_index_mapping from the pool on every batch.
  • That attribute is only created when an allocator registers a mapping.
  • In this configuration no allocator does, because the request windows already hold every sliding-window row.
  • With DSpark an allocator exists, so the crash does not happen there.

Modifications

  • The pool now always has full_to_swa_index_mapping. It stays None when no allocator registers one.
  • The sparse prefill cache builder already ignores the mapping when it is given a request-window layout. Its type hint now says the mapping is optional.

Accuracy Tests

  • The new unit test TestEncoderReplayWithoutSpeculation builds the pool in this configuration. It fails on main with the error above and passes with the fix.
  • On 4x B300 with deepseek-ai/DeepSeek-V4.1-Flash (TP4, EP4), main crashes on the first request with the command below. With this fix the server runs and GSM8K (1319 questions) scores 0.904. That run was on a branch that also carries my decoder bounded replay changes, which do not touch this code path.
python3 -m sglang.launch_server --trust-remote-code --model-path deepseek-ai/DeepSeek-V4.1-Flash --tp 4 --ep-size 4 --mem-fraction-static 0.8 --cuda-graph-max-bs-decode 64 --max-running-requests 16 --chunked-prefill-size 8192 --enable-encoder-swa-bounded-replay --disable-prefill-cuda-graph

Speed Tests and Profiling

Not applicable. This only fixes a crash.

Checklist


CI States

Latest PR Test (Base): ❌ Run #37569845440
Latest PR Test (Extra): ❌ Run #37569845137
Latest PR Test (AMD ROCm 10): ❌ Run #37569845389

…first prefill without speculation

Without speculation the request windows hold every SWA row and no allocator
registers a full-to-SWA mapping, so the pool never had the attribute that
prefill reads on every batch.
@hnyls2002

Copy link
Copy Markdown
Collaborator

Thanks @vincentzed for tracking down this crash! #43165 has since landed the same fix on main: the pool now initializes full_to_swa_index_mapping to None when request windows hold the SWA rows, with a unit test for encoder replay without speculation. Closing as superseded; please reopen if I've missed a case.

@hnyls2002 hnyls2002 closed this Oct 16, 2026
@vincentzed

Copy link
Copy Markdown
Contributor Author

Thanks @hnyls2002, agreed. #43165 covers this case, including the encoder replay without speculation test.

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.

2 participants