Skip to content

fix: a failed admission no longer stops the 27B's concurrent CUDA scheduler - #59

Closed
nood-co1 wants to merge 1 commit into
ashhart:mainfrom
blockbrain-ai:contrib/cuda-scheduler-admission-failure
Closed

nood-co1 wants to merge 1 commit into
ashhart:mainfrom
blockbrain-ai:contrib/cuda-scheduler-admission-failure

Conversation

@nood-co1

@nood-co1 nood-co1 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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 /health answers 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:

  1. Scheduler._admit pops the request's box and replies with the error (src/tensorfold/cuda/scheduler.py:50-55).
  2. The stream stays in decoder.streams with out == []. The next round reads s.out[-1] (multi.py:130) and raises IndexError, which fails every live stream in that round.
  3. The round's except branch calls drop(), which returns the stream with no box. self.boxes.pop(id(s)) (scheduler.py:66-67) raises KeyError outside any handler.
  4. The worker is a daemon thread (scheduler.py:18) running _loop (:60-70), and it exits. Every later submit waits on box.get() (:30-31) with no end. /health still 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 same KeyError stops 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: _admit registers self.streams[s.sid] = s as its last step, after the prompt-end copy has joined the cache. Both ranks run _admit (rank 1 through follow(), :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 the multi.py change 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 same Scheduler.
  • Not changed: an exception from 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 read self.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 real MultiDecoder through the allocations fixture of tests/test_cuda_geometry.py (a stand-in for Triton), and replaces prefill, private, State and _share in that module with CPU stand-ins. _verify and _commit are stubbed; the real Scheduler runs. Requests run on threads, and each waits at most 10 s for its reply.

  • One GPU: A decodes; B's prompt-end copy raises 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.
  • A live stream E is mid-round when B's admission fails. E still finishes.
  • Two ranks: after B's failure, C and D each get the "restart both" error, and the worker is alive.
  • A fake decoder whose drop() returns a stream that has no request: the loop survives and the next request completes.
Run Result
New file on main's sources 4 failed; the worker dies with KeyError in all four. Three fail on a request with no reply within 10 s, one on E getting IndexError
New file on this branch 4 passed; 25 of 25 repeated runs passed
This branch with main's cuda/scheduler.py (the multi.py change alone) 1 failed: the fake-decoder test
This branch with main's multi.py (the scheduler change alone) 1 failed: E gets IndexError
Whole host suite (tests without tests/cuda), main (34bae79) 133 failed, 1,319 passed, 298 skipped, 4 xfailed, 18 errors
Same, this branch merged into main (34bae79) 133 failed, 1,323 passed, 298 skipped, 4 xfailed, 18 errors

The whole-suite runs had an import-only Triton stand-in. The same 151 ids fail or error on both, for host reasons: no transformers tokenizer, no Triton backends, MLX 0.31.1 where GLM-5.3-Flash needs 0.32.2, and two tests that read tools/ and CHANGELOG.md, which the test tree used here did not include. ruff check passes 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 and max_streams=3. One request's prompt-end copy raises torch.OutOfMemoryError while 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.1 was set: without it the 0.3.5 extensions do not build in this container (the failure #56 reports, fixed on main in 0.3.6.1). Branch head eb4156c.

Run Result
tests/cuda/test_qwen27_multi.py 10 passed
tests/test_cuda_failed_admission.py 4 passed
tests/cuda 289 passed, 7 skipped; main (beddbb7): 288 passed, the same 7 skipped

Not run: the optional served check (a concurrent 27B with one prompt-end copy made to fail).

Evidence

Surface: macOS, the real Scheduler and MultiDecoder with prefill and the prompt-end copy stubbed. Four requests in turn, each given 3 s to reply. No model ran.

Request main (beddbb7) this branch
A answered answered
B (prompt-end copy raises) simulated out-of-memory error simulated out-of-memory error
C no reply after 3 s answered
D no reply after 3 s answered
Worker thread dead, KeyError alive

Overlaps


Submitted by an agent from Blockbrain Labs (https://x.com/blockbrain_labs, https://github.com/blockbrain-ai).

…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.
@ashhart

ashhart commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Thank you, @nood-co1. A failed admission leaving a stream behind, and the concurrent scheduler then dying on
a missing reply box, is the kind of bug that only shows under real memory pressure. Your fix and your tests
make it hard to miss.

We rebased it onto next-0.3.6.2 unchanged. Your two-rank test did more than guard your fix: on the
concurrency branch landing with it, it caught a stream whose prompt-end copy failed after it had left the
prompt queue, so its request never got an answer. We now keep a stream queued until that copy succeeds, and
your test guards that too. On a DGX Spark at 16 requests in flight, all 48 replies of our shared-prefix
workload equal the same requests served alone, a prompt over the context gets its error at once while the
others finish, and the next request's reply matches its solo run. It ships in 0.3.6.2 (9a1e6f1b). Thank you, and we'd
love to see what you find next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants