Repository navigation
qwen38: route a whole ubatch in one run so each routed expert is read once - #740
Conversation
… once The card route ran a 4,096-position ubatch in two runs of 2,048 tokens, so each card expert's weights were read twice a ubatch and the routed GEMMs launched twice a layer. A plan that has room for the wider run now gives the card route one run of the whole ubatch: widen_card_route plans the machine again with that run's extra bytes as a named stage-card reserve (route_unit_bytes, 348,897,280 B at 4,096 positions) and keeps the reserve only when that plan places every tensor where the first one did. A card the experts fill, a unified pool whose PLE table would leave the host, a host-routed plan and the tier's block route keep runs of 2,048 tokens, so their plans do not move. The load reads its run from the reserve (card_route_run) and refuses a reserve of other bytes by name. GEMM_MAX_SLOTS rises to 40,960 so one route table takes a 4,096-token run at ten slots a token.
There was a problem hiding this comment.
Verdict: CLEAN: No reachable behavior failure or proven quality defect survived the checks.
Non-blocking
⚠ Complete the GPU verification: crates/gpu/src/gemm/mod.rs:82. The capacity increase changes both route kernels, while the expanded GEMM gate and whole-ubatch end-to-end gate have not completed. Attach passing just gate-gpu-gemm and just gate-gpu-qwen4exp-e2e output, including FAIL-first for the new whole-run clause, and compare PTX resource columns. The launch-count/geometry class requires the owning gates; a fixture-budget check does not exercise these kernels.
⚠ Identify the measured build: crates/model/src/arch/qwen35moe/place.rs:1288. The A/B tables identify base commits but leave the executed head unnamed; the body says it predates this head. Attach that commit hash, exact model paths, and the commands with their output so the speed claim can be reproduced. Keep the results separated by card.
Checked
Duplicates: 13 new named functions, types, constants and tests checked; no duplicate found. Dryer reported zero pairs in model; GPU and gate paths were searched manually.
Complexity: run_case 1→30 incorporates the existing run_case_at body; Body38::open_with 21→23 adds reserve validation; card_whole 30→31 adds the whole-run check. No complexity-only finding.
Silent failure: 9 candidate sites followed. Failed optional replanning retains the valid original plan; malformed reserves return RouteUnitReserve; gate probes turn errors into failed premises.
Tests: Static mutation checks: drop placement equality or reserve-size validation → placement assertions fail; discard MTP in plan_target → plan comparison fails; restore the old route clamp → expanded route-table checks fail; force the loaded run to 2,048 → whole_run fails. These checks were not executed here.
Gates: No band or tolerance relaxed. Route capacity and exercised token counts increase; no dated gate pin moved.
Escape catalog: C1–C4 do not match the changed code.
Notes
This was a static review. No builds or GPU gates were executed here. The attached evidence does not identify both executed commits for a completed GPU gate run.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu-gates/src/bin/gate_qwen38_serve.rs, crates/gpu-gates/src/bin/gate_qwen4exp_e2e.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8의 4K prompt prefill에서 routed expert의 weight를 ubatch마다 두 번 읽던 것을 가능한 경우 한 번만 읽게 해서 속도를 올리는 작업입니다.
Part of #565.
What and why
Qwen3.8 runs a 4,096-token ubatch through its routed experts in two runs of 2,048 tokens, so every expert's weights are read twice per ubatch. This PR lets the placement plan give the card route a run of the whole ubatch, so each expert is read once.
The plan widens the run only when nothing else has to move for it. It plans the machine a second time with the extra run buffer held as a named reserve on the stage card: 2,048 more tokens at 170,360 B a token, which is 348,897,280 B. If both plans place every tensor the same way, the reserve stays and the load runs the whole ubatch. If the card is too full, or the second plan does not fit, the run stays at 2,048 tokens and the plan is the one main makes. That keeps small-card and mixed placements as they were.
qwen35moe/place.rs:widen_card_routedoes the second plan and the comparison,tensor_placeslists where every row piece sits (device, format, expert list), andcard_route_runreads the run width and arena bytes back from the reserve at load, naming a malformed reserve asPlaceError::RouteUnitReserve.PlanInputs::plan_targetis the one place that picks the plain plan or the MTP target plan;tier_expertsand the serve seat both use it.reserve_rowsis shared withcheck_draft_reserve.body38.rs,wide38.rs,qwen38_open.rs:open_placedtakes the run width fromcard_route_runand hands it toWide38::newandCardRoute38::new.serve_seats/qwen38.rsandqwen38_place.rs: the serve seat and the shared gate plan call the widening. Other gates keep the 2,048 run. Both serve planning paths andgate_qwen38_serve.rsnow take the plain or MTP plan fromplan_targetinstead of choosing it themselves.gemm/mod.rs:GEMM_MAX_SLOTSgoes from 36,864 to 40,960, so a run of 4,096 tokens at ten slots a token fits one route table.scratch38.rs,ubatch.rs: a new const assert ties the default ubatch at ten slots a token toGEMM_MAX_SLOTS, and the qwen3moe assert becomes<=because its nine slots a token now fit inside the cap.gate_gemm.rs: theroute_tablecase gains a Qwen3.8 stack of 512 experts at ten slots a token up to 40,960 slots, and theq38cases run up to 4,096 tokens, which removesQ38_TOKENSandrun_case_at.gate_qwen4exp_e2e.rscompares a whole-ubatch run against the split walk bit for bit on the fixture plan.tools/model-tax.tsv: thegate_gemm.rsqwen count drops from 32 to 30.Release notes: Changed: Qwen3.8 prompts of 4,096 tokens read each routed expert once per ubatch when the plan has room, which prefilled FP4-Local 11.8% to 18.7% faster on one DGX Spark in one sitting.
Code shape
plan_target,reserve_rows).CARD_ROUTE_ROWSstill mirrors the GPU run length because the model crate cannot read the GPU crate, and its value is unchanged.Q38_TOKENSandrun_case_atare removed.model-tax.tsvcount went down.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": the two copies named above were removed. The helper-wrapper shape ofplan_targetalso appears indeepseek41/place.rsandplace_hybrid.rs, where eachplanwraps only its ownplan_with_slots;plan_targetadditionally chooses the MTP target plan, so I left those alone.What I ran
Speed A/B
One DGX Spark, clock cap lifted around each arm, one server load per arm, arms alternating main and head, draft off, one request at a time, greedy. Each arm sends two prompts of 4,096 tokens with
n_predict128. Server:bloomery-serve -m <model folder> --host 127.0.0.1 --port 18671 --parallel 4 --ctx-size 16896withBLOOMERY_DRAFT=offandBLOOMERY_HOST_ROOM=96G, built forsm_121. Main is upstream648dd751.Delta (head against main): FP4-Local prefill +18.7% (1079.0 to 1280.3 tok/s), NVFP4 prefill +3.6% (1134.7 to 1175.7 tok/s).
Each arm is one load with two requests, so these are single observations with no significance claim. The first FP4-Local request on main prefilled at 995.1 tok/s, a warm-up value. On main, the second FP4-Local request prefilled at 1162.9 tok/s. On the head, it prefilled at 1300.3 tok/s. For NVFP4, the second request prefilled at 1142.3 tok/s on main. On the head it prefilled at 1162.9 tok/s, so the NVFP4 gain may lie inside the spread between requests. Decode is not touched by the change, and the two decode differences above are within what one pair of requests shows.
In every arm the plan puts all 24,576 routed experts on the card, so the widened run costs no expert placement.
Output is unchanged: the greedy output of the head equals main's on both 128-token requests of each checkpoint.
Mixed placement on an RTX 5090 machine
Placements that split experts between the card and the host are the ones a widened run could have hurt, so I compared main (upstream
1287fad5) and the head on the Qwen3.8UD-Q4_K_XLGGUF (unslothQwen3.8-Flash-Next-GGUFat766911a6), run order main, head, main, head, one load each with two requests. Server:bloomery-serve-qwen38 --host 127.0.0.1 --port 0 --place gate --ctx-size 4096withBLOOMERY_DRAFT=off BLOOMERY_RESIDENCY=off, a 2,701-token prompt,n_predict64, temperature 0.The plan is the same on both: 4,439 card experts and 20,137 host experts. Resident bytes are 23,152,430,044 in all four loads, and the greedy tokens are equal across arms. Medians over the four requests of each arm:
This card is full of experts, so the widening does not apply and the run stays at main's 2,048 tokens.
Tests, FAIL-first and gates
The placement unit tests pass on macOS, 27 passed. The new tests fail on the defect first: I broke the rule five ways, one at a time (dropped the comparison of the widened plan, dropped the stage-card experts condition, dropped the tier deduction, dropped the guard on the reserve size, compared only expert counts instead of every tensor place), and the new test failed each time:
The first line is the unbroken tree; the next five are the five breakages in the order listed. On an RTX 5090 machine, the whole-workspace
cargo check --all-targetspasses with rc 0, and the fixture budget gate passes:Hardware
The A/B ran on one DGX Spark and the mixed placement and gate runs on an RTX 5090 machine. GPU, driver and CUDA lines from
nvidia-smiof the same jobs:The DGX Spark container reports CUDA 13.3.1. Models: Qwen3.8 FP4-Local (
b9ce18a6) and NVFP4 (fc694b54) for the A/B, and the GGUF above for the mixed placement.What I ran into
None of this blocks the PR.
ubatch.rsandscratch38.rsand some comment wording added. The executed code of the change is the same, and I did not rerun the measurements on the PR head. The placement unit tests and the workspacecargo checkalso ran on macOS at a head with the same executed code (check rc 0, 27 tests passed); the gate and check runs on the RTX 5090 machine were on an earlier build.gate_qwen4exp_e2e(the new whole-ubatch comparison on the fixture plan) did not run to the end here. On the RTX 5090 machine it got through the load and structure checks and stopped for want of the fixture oracle. On the DGX Spark machines it stopped at the recorded fixture budget check, because their copy of the Qwen3.8 fixture is older than the recorded budget. Main stops at the same budget check on those machines.just gate-gpu-gemmwith its new 40,960-slot cases was not rerun on this head.GEMM_MAX_SLOTSis the clamp inside thegemm_routekernel, so that entry's PTX changes by one constant. I did not compare the cc 12.1 PTX pins.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.