You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: PyTorch backend: logits row counts ignore encoder-replay rows when a step also returns context logits #22703
This affects models whose cache manager issues EncoderReplay plans (CSA2 sparse attention with encoder replay enabled, such as DeepSeek-V4.1), on a step where a request that resumes from a prefix-cache hit shares a prompt step with a request that sets return_context_logits=True.
A request with an EncoderReplay plan recomputes some earlier prompt tokens, so its rows in the step are its chunk plus encoder_replay_tokens(req) (engine/runners/decoder/inputs.py moves begin_compute back by that count, and py_executor.py adds it to num_ctx_tokens). The request that asks for context logits never gets a plan itself: requires_full_decoder_prefill sets its reuse limit to 0, so _resume_context_cache returns before issuing one. The replay rows therefore always belong to a request that did not ask for context logits.
The code that reads the step's logits counts context_chunk_size rows (or 1) per context request and does not add replay rows:
the context-logits prefix sum in PyExecutor._sample_async (py_executor.py, num_context_logits_prefix_sum), which HandleLogits uses to slice each request's rows
ContextLogitsPlan.project, which advances offset by context_chunk_size and takes hidden.shape[0] - sum(context_chunk_size) as the generation row count
So the context logits stored for the requesting request, the sampling rows of every context request after the replay request, and the generation rows can all be shifted by the replay row count.
Expected behavior
Each request's context logits and sampling row come from its own rows, whatever other requests in the step have encoder replay.
Notes on a fix
The replay row count has to be captured per request before the forward. The model consumes the replay plan, so encoder_replay_tokens() returns 0 afterwards. That count then needs to be applied in the sampler's prefix sum, HandleLogits and the context-logits plan together, and in store_context_logits_from_full_rows if #22038 merges first.
Raised by CodeRabbit on #22038 (thread on context_logits_plan.py); left out of that PR because it is the same on main.
I’ll work on this. I plan to capture per-request replay row counts before the forward pass and add a regression test for a mixed batch with encoder replay and context logits.
Activity
Super262 commentedon Nov 21, 2026
I’ll work on this. I plan to capture per-request replay row counts before the forward pass and add a regression test for a mixed batch with encoder replay and context logits.
fix: account for encoder replay rows in mixed context logits batches
fix: account for encoder replay rows in mixed context logits batches
fix: account for encoder replay rows in mixed context logits batches
fix: account for encoder replay rows in mixed context logits batches
fix: account for encoder replay rows in mixed context logits batches
[NVIDIA#22703][fix] Account for encoder replay rows when gathering co…