fix(frontend): offload prompt tokenization off the async event loop - #3
Merged
Merged
Conversation
ROOT CAUSE of the DSV4 disagg SLO collapse: the frontend generate path tokenized the ~40k-token prompt SYNCHRONOUSLY on the async event loop (gather_tokens -> encode_with_timing -> tokenizer.encode), unlike the embedding path which already offloads via spawn_blocking. At high concurrency this stalls the frontend tokio runtime multi-second (measured: 135 event-loop stalls, max 2.66s), starving the request-plane I/O -> 5s ACK timeout -> CannotConnect -> GEN worker inhibited -> flap/cascade -> throughput collapse (105 -> 14-30 req/s), while GEN/CTX engines stay healthy. Evidence: iter4 C8diag2 stall logs + send->decode 14.6s arrival. Fix: make encode_with_timing async and run tokenizer.encode on the bounded blocking pool (spawn_blocking), mirroring the embedding path; propagate async through gather_tokens and its two callers. Frees the event loop so request-plane I/O is polled -> no false CannotConnect -> no cascade. Signed-off-by: Yuewei Na <nv-yna@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root-cause fix for the DeepSeek-V4-Pro disagg SLO collapse. This is the clean, core-only subset of
nv-yna/dynamo#1: a single functional commit with no env-gated
diagnostic/instrumentation code (the
DYN_ACK_TRACE/DYN_STALL_OP_TRACE/DYN_PREFILL_TRACEtraces),no request-plane msgpack codec, and no fault-inhibit hysteresis change. Just the fix.
The bug
The frontend generate path tokenized the prompt synchronously on the async event loop
(
gather_tokens→encode_with_timing→tokenizer.encode), unlike the embedding path which alreadyoffloads via
spawn_blocking. For DeepSeek-V4's ~40k-token prompts at high concurrency this stalls thefrontend tokio runtime for multiple seconds (measured: 135 event-loop stalls, max 2.66s), starving the
request-plane I/O → 5s ACK timeout →
CannotConnect→ GEN worker inhibited → flap/cascade → throughputcollapse (105 → 14–30 req/s), while the GEN/CTX engines stay healthy.
The fix
Make
encode_with_timingasync and runtokenizer.encodeon the bounded blocking pool viatokio::task::spawn_blocking, mirroring the embedding path. Own the prompt + clone the tokenizerArcso the closure is
'static + Send. Propagateasyncup throughgather_tokensand its two callers.This frees the event loop so the request plane keeps getting polled → no false
CannotConnect→ no cascade.Scope
1 file, +18/−11 (
lib/llm/src/preprocessor.rs). Diff is exactly commitfbe21cc47718from PR #1,cherry-picked cleanly onto
feat/deepseek_v4_aa.