Round 2: every cut still copies the call's whole route history, and about 170 source lines can still go

Second size review of NVIDIA-NeMo/RL #4612, PR 8 of 11 in the prefix-recovery stack. Line counts are from git diff 3821aa8 f47c6b4 (the PR against its real base, #4583). Permalinks pin the head f47c6b48. Review comments are in a pending review; their links work once it is published.

Round 1
~573 source and ~471 unit-test lines (net). The review asked for ~450 and ~300, mainly by reading routes once per cut instead of on every token.
This round
13 of the 16 round-1 comments are fixed, and routes are now read once per cut, in the same read as the tokens. But two later commits brought the size back: ~534 source, ~747 unit-test lines.
Status
Proposed — not implemented. Each cut below is a review comment. None is applied, and none of the code on this page has been run.

Four pages on this PR. This one covers what is still too big after the author's fixes.

With router replay on, each cut saves the expert route rows for the tokens decoded since the last cut. vLLM keeps a running request's routes as a list of small pieces that it only appends to. A cut takes that list from the same read that copies the tokens. Commit 352f46c4 then adds a buffer that doubles when full, so a cut copies only the new pieces (absorb_engine_route_pieces). One function later, frozen_cut_routed_experts joins every row into a cumulative tensor that its only caller unpacks and never reads.

What one cut copies

Cut 2 of one call: vLLM holds 9 route rows · rows 1–5 were saved at cut 1 · rows 6–9 are new already saved at cut 1 new: what this cut saves copied, then never read Today buffer: copy new pieces 4 rows copied torch.cat → cumulative (unused) 9 rows copied save rows 6–9 13 rows copied to save 4 Asked here np.concatenate(pieces), no buffer 9 rows copied slice the chunk (a view, no copy) save rows 6–9 9 rows · ~75 fewer source lines Later, in #4508 (with timing numbers) buffer: copy new pieces 4 rows copied slice the chunk save rows 6–9 4 rows · only after the unused copy is gone One row = [MoE layers, experts per token]. Real size: a 16k-token call × 48 layers × top-8 × int16 ≈ 12.6 MB per full copy.

The buffer is worth having only once the unused copy is gone. Until then it adds ~55 source and ~90 test lines with no time saved. It has no timing numbers, and the PR description says this stack goes "correctness first, optimization last". So the review asks for the copy to go here, the buffer to go to #4508 (the stack's I/O speed-up PR), and timing numbers for it there. #4508 is already rebased on this PR and still carries both.

What can go

What the PR writesReplace withlines
A cumulative route tensor built on every cut and never read (frozen_cut_routed_experts)

C17 · generation_cut_capture.py:391

Return only the chunk, sliced straight from the engine rows. Checked equal to today's output on 20,000 random cases.~15 src
The buffer that doubles when full, its join helper, its 4 fields and 4 tests (commit 352f46c4)

C18 · generation_cut_capture.py:1072

One np.concatenate(pieces). The buffer comes back in #4508 with timing numbers.~70 src
~95 test
_merge_generation_cut_routed_experts runs right after _delta_align_routed_experts, unpacks the same message again, and decodes and re-encodes the same routes

C19 · vllm_worker_async.py:1987

A restored= argument on the align step~45 src
A route hash logged at restore and at completion. Both come from the same tensor in the same worker, so they can only differ if the routes were dropped.

C20 · generation_cut_capture.py:120

Log prefix_routes=kept|dropped once~30 net
A prompt_routed_experts lookup that vLLM 0.29 never fills

C21 · vllm_worker_async.py:1594

Read routed_experts only~8 src
Three checks that cannot fire, a second builder for the -1 row, and one test that folds into another

C23 · generation_cut_capture.py:692

Delete / reuse _final_route_placeholder / fold~14 src
~14 test

Worth keeping: the route read inside the token read (f47c6b48, −108 lines), the shared phase helpers in the functional scripts (the Omni test drops 124 lines), and decode_routed_experts(dtype=None), which deletes two copied dtype tables.

So what. Taking these brings source from ~534 to about 370 lines, under round 1's ~450 target, and unit tests from ~747 to about 630. Each cut then copies the call's routes once instead of twice. The PR description is also out of date: it still describes a route read and a setup check that the last commit deleted. No CI test job has run on this head yet.