Skip to content

qwen38: the seat takes -ub/--ubatch-size over BLOOMERY_QWEN3_UBATCH, one size for its plans and its load - #881

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-ubatch-qwen38
Oct 27, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-ubatch-qwen38

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8 서버가 -ub/--ubatch-size와 LLAMA_ARG_UBATCH를 받아서, 카드 메모리를 줄이려고 ubatch 크기를 낮출 수 있게 합니다. 이 값을 주지 않으면 동작은 그대로입니다.

Part of #565.

What and why

On upstream main, bloomery-serve refuses -ub and --ubatch-size for a Qwen3.8 checkpoint with unknown argument "--ubatch-size", and LLAMA_ARG_UBATCH ends in the same refusal. The seat reads its prompt ubatch only from BLOOMERY_QWEN3_UBATCH. A user who wants to lower the ubatch to free card memory has to know that lever.

This change makes the Qwen3.8 seat take -ub/--ubatch-size (and LLAMA_ARG_UBATCH, which the launcher already maps to --ubatch-size). The flag wins over BLOOMERY_QWEN3_UBATCH; with neither set, the size stays 4096. The seat resolves the size once, right after the flags, and hands it to its plans, the placement offer, the vision cost plan and the engine thread's load, so the plan and the load always use the same size. A value that is not a number, 0 or above 4096 is refused by name before the model opens, with the same text as the Qwen3 seat.

The rule "flag over BLOOMERY_QWEN3_UBATCH" now lives in one shared function, ubatch_rule in crates/gpu-gates/src/bin/shared/ubatch_rule.rs. It moved out of qwen3moe_place.rs, and the copy of the same two lines in serve_seats/decide.rs calls it. The BLOOMERY_QWEN3_UBATCH registry doc and the -ub paragraph in docs/serving.md now name the Qwen3.8 seat.

Release notes: Added: bloomery-serve takes -ub/--ubatch-size (and LLAMA_ARG_UBATCH) for a Qwen3.8 checkpoint, so the prompt ubatch can be lowered to free card memory.

Code shape

  • No second copy. ubatch_rule has one owner. The Qwen3 placement file defined it and serve_seats/decide.rs repeated its two lines; both now call the shared file, and the Qwen3.8 seat calls it too.
  • Model code holds only architecture facts. No model file changed. The change is in the serve seat and the shared rule.
  • Dead code is gone. The moved definition and the repeated lines are removed.
  • No silent failure. A non-number, 0 and 4097 are each refused by name before the model opens.
  • Comments state what is true now. No dates or issue numbers.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt and cargo clippy on what I touched: cargo clippy on bloomery-gpu-gates and bloomery-levers finished with no warnings. I did not run cargo fmt separately.

Duplication found or removed (path:line): the copy in crates/gpu-gates/src/bin/shared/serve_seats/decide.rs of the flag-over-lever rule, now a call to ubatch_rule.

What I ran

Head 2718786cb7f3e5f7bdcf626f04e1eea90a79f9a3, base 7908410cc846333bbbbf6a521257aaab0652e74a. The change is host-side flag handling, so I ran the plan and the load, not a timed measurement. The GB10 runs below used the same code before the later rebases and before ubatch_rule moved to its own file; the body and the values its callers pass are the same. The RTX 5090 checks ran on 5d961f208e442c33e031fee7f4d62d56e4cd2255, an earlier base. The head adds the tools/model-tax.tsv rows for the moved rule and a rebase, and python3 tools/model_tax.py check is ok on it. I did not rerun the GPU and compile checks on the head itself.

Model: nvidia/Qwen3.8-Flash-Next-FP4-Local at revision b9ce18a6887e18c089fdea8509a33e63429a3300. The MTP arms used mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf from unsloth/Qwen3.8-Flash-Next-GGUF at 766911a6. Each arm is bloomery-serve -m <folder> --host 127.0.0.1 --port <port> plus the arguments named below.

Plan (--plan), card bytes from the need line:

--plan                               cards=[GB10:87079362176]
-ub 48 --plan                        cards=[GB10:83680187760]
BLOOMERY_QWEN3_UBATCH=64 --plan      cards=[GB10:83693623232]
BLOOMERY_QWEN3_UBATCH=64 --ubatch-size 48 --plan    cards=[GB10:83680187760]
LLAMA_ARG_UBATCH=48 --plan           LLAMA_ARG_UBATCH is read as --ubatch-size 48

The lever alone is read, the flag beats the lever (the last plan equals the flag alone), and LLAMA_ARG_UBATCH reaches the seat.

Refusals, each before the model opens:

bloomery-serve: --ubatch-size 0 is not a ubatch size in 1..=4096
bloomery-serve: --ubatch-size 4097 is not a ubatch size in 1..=4096
bloomery-serve: --ubatch-size "4k": invalid digit found in string

Load, one slot, default against -ub 48; the load line names the size the arena was opened with:

default   load ... resident_bytes=87953641128 ... ubatch=4096
-ub 48    load ... resident_bytes=84650035808 ... ubatch=48

The plan's card bytes fall from 87079362176 to 83680187760 and the loaded resident bytes from 87953641128 to 84650035808, so the plan and the load follow the same size. Every serve arm loaded.

Greedy output, default against ubatch 48, temperature 0, every request returned its ids: identical in all seven requests. They were a single 4200-token prompt; a 4097-token prompt followed by a 4300-token continuation with the prompt cache on; and, with the MTP draft, 4 slots, --ctx-size 16896, two 4150-token prompts sent together and two 3600-token windows sent staggered whose decode crosses position 4097.

Unit and compile checks on 5d961f208e442c33e031fee7f4d62d56e4cd2255, on an RTX 5090 machine: just check (workspace, all targets, all features), just gate-q38-serve-rules and just gate-gpu-gates-lib:

test qwen38::tests::the_ubatch_flag_is_read_and_its_size_refused_outside_the_engines ... ok
test result: ok. 23 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 187 passed; 0 failed; 3 ignored; 0 measured; 0 filtered out

The new test reads -ub 48 and refuses sizes at 4096 plus one, so removing the flag arm or moving the range edge turns it red.

Not run: a timed A/B (the change adds no work at a given size) and any measurement of how much prefill time a small -ub costs.

Hardware

NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

…one size for its plans and its load

The qwen38 seat refused -ub and --ubatch-size as unknown arguments, so
LLAMA_ARG_UBATCH, which the launcher passes as --ubatch-size, was refused
too, and the ubatch size could only come from BLOOMERY_QWEN3_UBATCH. The
seat now reads the flag through ubatch_rule, the flag over the variable,
once with its flags; every plan it asks and the load's arena take that
one size, each clipped to its context. A size outside 1..=4096 is refused
by name before the model opens.

ubatch_rule moves from qwen3moe_place to its own shared file, which the
qwen3 seat's dense loads, the decide seat's backbone probe and the qwen38
seat include; the decide seat's copy of it is gone.
@github-actions github-actions Bot added documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 27, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: the Qwen3.8 seat reads one ubatch size and every former ubatch_for site now takes it; I found no unrefuted failure path.

Non-blocking

⚠ The unit test does not pin the plan/load wiring: qwen38.rs:3192. The test covers parse_args and ubatch_rule. Two mutants stay green: ubatch_rule(a.ubatch) at line 1362 changed to ubatch_rule(None), and a.ubatch.min(a.ctx) at line 2231 changed to UBATCH.min(a.ctx). Either one makes the plan and the load disagree. Only the manual GB10 runs in the PR body catch this. The direction of a fix is a hw_ gate that compares the need line and the load line's ubatch= at -ub 48. This is its own piece of work.

⚠ The test's refusal half repeats a rule that Rule::of owns: qwen38.rs:3205. The 0 and UBATCH + 1 cases pin the range of ubatch_pick.rs:60, which a test in ubatch_pick.rs already refuses at 0 and at 8192. Keep the -ub and --ubatch-size parse cases and the 4k case. Drop the rest if the maintainers want one test per contract.

⚠ Question: sizes below 9 were not run. The body ran -ub 48 only. The seat's prompt path walks the GEMM route from 9 rows (qwen38.rs:315). -ub 1 is accepted by Rule::of and was already accepted through the env lever. Please run one prompt at -ub 1 or -ub 8, or state the lowest size that is supported.

Checked

  • Duplicates: 3 new items checked (ubatch_rule file, Args::ubatch, Plans::ubatch), none duplicated. The moved ubatch_rule and the two repeated lines in decide.rs are removed. dryer did not search crates/gpu-gates; I grepped ubatch_rule, ubatch_for, ubatch_size and ubatch_asked by hand. The remaining ubatch_for callers are qwen4exp gates and routed_legs/qwen38.rs, not this seat.
  • Complexity: parse_args 32 → 34, one match arm and one default field, even growth. No finding.
  • Silent failure: 4 sites followed. Flag 0 and 4097 end in Rule::of's named error. 4k ends in serve::flag::number. An invalid env value ends in ubatch_asked. With neither set, the seat takes UBATCH, which equals the old ubatch_size() default.
  • Tests: the new test fails when the flag arm is removed or the range edge moves. It passes on the two wiring mutants listed above.
  • Gates: no band, tolerance or lint moved. The tools/model-tax.tsv PIN row is dated and gives its reason.
  • Performance: host-side flag handling at load. No hot path touched.
  • Escape catalog: no pattern matched (no shell or tool script changed).

Notes

  • The GPU runs in the PR body used earlier heads. The body says the head itself was not rerun on a card. The unit and compile checks ran on a different machine (RTX 5090) than the nvidia-smi line (GB10).
  • crapper ran; dryer did not search crates/gpu-gates.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/shared/qwen3moe_place.rs, crates/gpu-gates/src/bin/shared/serve_seats/decide.rs, crates/gpu-gates/src/bin/shared/serve_seats/qwen38.rs … and carries a gate run on the author's card, which counts as verified.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@github-actions github-actions Bot added gpu-evidence Verified on the author's card: the pull request carries the gate run and its output and removed needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 27, 2026
@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit d063884 into midagedev:main Oct 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app gpu-evidence Verified on the author's card: the pull request carries the gate run and its output host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant