Repository navigation
Conversation
…eduler MultiDecoder._admit registered a stream before copying its prompt end into the prefix cache. When that copy raised (an allocation failure), the request got the error but the stream stayed registered without a token: the next round read its last token and failed every live stream, and the Scheduler's boxes.pop for it raised KeyError outside any handler. The worker thread exited, and every later request waited forever while /health answered ok. On two ranks the same KeyError stopped the worker before later requests could get the "restart both" error. - A stream is registered after its prompt-end copy, on both ranks. Successful admissions make the same calls in the same order, so rounds and drafted output are unchanged. - The Scheduler replies only to streams whose request still waits, so a dropped stream without a request no longer stops the loop. Test: tests/test_cuda_failed_admission.py on CPU stand-ins (the four tests fail without the fix). tests/cuda/test_qwen27_multi.py: one request's prompt-end copy fails, the others decode their serial tokens.
|
Thank you, @nood-co1. A failed admission leaving a stream behind, and the concurrent scheduler then dying on We rebased it onto next-0.3.6.2 unchanged. Your two-rank test did more than guard your fix: on the |
Summary
When the Qwen3.8-27B concurrent CUDA decoder fails to admit a request at its prompt-end copy, that request gets the error. The scheduler's worker thread then exits, and every later request waits with no end while
/healthanswers ok. After this PR the failed request gets its error and the server keeps serving.Why
At
main(34bae79),MultiDecoder._admit(src/tensorfold/families/qwen3_5/cuda/multi.py) registers the stream (:116) before it copies the stream's prompt end into the prefix cache (:117-118;private()clones the state and K/V,:22-27). If that copy raises:Scheduler._admitpops the request's box and replies with the error (src/tensorfold/cuda/scheduler.py:50-55).decoder.streamswithout == []. The next round readss.out[-1](multi.py:130) and raisesIndexError, which fails every live stream in that round.exceptbranch callsdrop(), which returns the stream with no box.self.boxes.pop(id(s))(scheduler.py:66-67) raisesKeyErroroutside any handler.scheduler.py:18) running_loop(:60-70), and it exits. Every latersubmitwaits onbox.get()(:30-31) with no end./healthstill returns{"ok": true}(cuda/server.py:441-442).On two ranks the failed admission already sets
broken(multi.py:94-97), so every later request should get the "restart both" error (multi.py:72-74). The sameKeyErrorstops the worker first, and those requests wait instead.The only trigger found is an allocation failure at the prompt-end copy, from reading the code. Admission plans memory for that copy (
cuda/geometry.py:243-260: a cached end is added before the oldest leaves), so it is rare, and it was not observed on hardware. The consequence is a server that never answers again.Change
src/tensorfold/families/qwen3_5/cuda/multi.py:_admitregistersself.streams[s.sid] = sas its last step, after the prompt-end copy has joined the cache. Both ranks run_admit(rank 1 throughfollow(),:286), so a failed copy leaves no stream behind on either.src/tensorfold/cuda/scheduler.py: a new_reply(s, kind, value)pops the stream's box with a default and puts the reply only if a request still waits on it. The round-failure branch and the completion replies use it. With themulti.pychange in, no other path was found that leaves a stream registered after its request's reply, so this part is defensive. It also covers Flash Next's concurrent decoder, which uses the sameScheduler.decoder.finish()still ends the worker. On two ranks the one such path found is a failed DONE broadcast (multi.py:254), which raises before the finished streams are dropped. Catching it in the scheduler alone would leave them registered.No other behaviour changes.
Exactness
Not affected. A successful admission makes the same calls in the same order on both ranks. Only the dict insert moves after
cache.add, which does not readself.streams. Each stream still enters the dict once, before any later admission, so the dict's order, and with it round plans, windows and commits, is unchanged. The scheduler puts the same replies in the same order when nothing raises. Everything else is on error paths.Tests
Host: macOS, Python 3.13.5, PyTorch 2.11.0 CPU.
tests/test_cuda_failed_admission.py(new, 4 tests) imports the realMultiDecoderthrough theallocationsfixture oftests/test_cuda_geometry.py(a stand-in for Triton), and replacesprefill,private,Stateand_sharein that module with CPU stand-ins._verifyand_commitare stubbed; the realSchedulerruns. Requests run on threads, and each waits at most 10 s for its reply.torch.OutOfMemoryError; B gets that error; C and D get their replies (D over two rounds). The worker is alive, no stream is left, and B is not in the prefix cache.drop()returns a stream that has no request: the loop survives and the next request completes.main's sourcesKeyErrorin all four. Three fail on a request with no reply within 10 s, one on E gettingIndexErrormain'scuda/scheduler.py(themulti.pychange alone)main'smulti.py(the scheduler change alone)IndexErrortestswithouttests/cuda),main(34bae79)main(34bae79)The whole-suite runs had an import-only Triton stand-in. The same 151 ids fail or error on both, for host reasons: no
transformerstokenizer, no Triton backends, MLX 0.31.1 where GLM-5.3-Flash needs 0.32.2, and two tests that readtools/andCHANGELOG.md, which the test tree used here did not include.ruff checkpasses on the four changed files.tests/cuda/test_qwen27_multi.py::test_a_failed_prompt_end_copy_fails_only_its_request(new, GPU) uses the file's small random model with the oracle drafter andmax_streams=3. One request's prompt-end copy raisestorch.OutOfMemoryErrorwhile three others decode. That request gets the error and no tokens. The three others, and two more submitted afterwards, get their serial-decode tokens. The worker is alive, and the failed prompt is not in the cache.GPU status
One DGX Spark (GB10, sm_121); container: Python 3.12.3, PyTorch 2.13.0a0 (NVIDIA 26.07), CUDA 13.3, Triton 3.7.1.
TORCH_CUDA_ARCH_LIST=12.1was set: without it the 0.3.5 extensions do not build in this container (the failure #56 reports, fixed onmainin 0.3.6.1). Branch head eb4156c.tests/cuda/test_qwen27_multi.pytests/test_cuda_failed_admission.pytests/cudamain(beddbb7): 288 passed, the same 7 skippedNot run: the optional served check (a concurrent 27B with one prompt-end copy made to fail).
Evidence
Surface: macOS, the real
SchedulerandMultiDecoderwith prefill and the prompt-end copy stubbed. Four requests in turn, each given 3 s to reply. No model ran.main(beddbb7)KeyErrorOverlaps
cache.addline in_admit: 1 conflict block against the movedself.streamsinsert. That change keeps entries one token before the prompt's end, so this PR's tests change with it: the host test's stand-inprefilltakeskeep_atand its expected entries are one token shorter, and the GPU test's failing copy is atst.pos == len(doomed) - 1. Whichever lands second needs a rebase.ignore_eoschange in feat(cuda): stop strings on every CUDA engine, and ignore_eos on the 27B's CUDA engine #63 also editscuda/scheduler.pyandmulti.py. Git merges the two cleanly.cuda/scheduler.py,families/qwen3_5/cuda/multi.pyortests/cuda/test_qwen27_multi.py(checked against perf: opt-in wider Flash Next prompt chunks (TENSORFOLD_PREFILL_ROWS), default unchanged #40, feat: a quantized KV cache for Flash Next on CUDA (--kv-dtype int8 or int4) #47, fix: honor Flash Next host offload and explicit MLX memory budgets #49 and glm5_next: long contexts on a latent MLA cache (256k on two Sparks) #54).Submitted by an agent from Blockbrain Labs (https://x.com/blockbrain_labs, https://github.com/blockbrain-ai).