Skip to content

gpu: a split pick is a function of the prompt: the expert stream prices its lane by where the probe's experts sit (lane_rate), its probe's timing printed beside it, and an admit's return by the walk's last card layer alone; gate_nvtier's sittings clause loads the paged plan twice, once beside a host copy load - #647

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-residency-deterministic
Oct 22, 2026

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

기본 설정에서 같은 prompt의 greedy 출력이 load마다 달라지던 결함을 고칩니다. 분할 expert stream이 load 때 잰 copy 속도 대신, expert의 바이트가 놓인 곳(host 메모리 또는 NVMe tier)으로 정한 속도로 값을 매기게 합니다.

Fixes the token item in #637.

What and why

With BLOOMERY_RESIDENCY and BLOOMERY_XSTREAM unset (residency mid-p0-s1, stream split under --place a), the same build and the same greedy command give different tokens on different loads of Qwen3.8 UD-Q4_K_XL. Tokens are equal within one load. After this change the split pick depends only on the prompt and the plan, and every load gives the same tokens.

Cause: XStream::new times a probe copy at load and keeps its rate as the lane rate (x.lane_b_per_us = x.probe()? in crates/gpu/src/host/xstream.rs). admit_walk in crates/runtime/src/xsplit.rs prices every admit at that rate. The probe rate moves with the page cache and other memory traffic, so the floor per layer, the set of admitted experts and the set summed on the card change from load to load. A second read of the same kind sits in return_cost (crates/gpu/src/host/prompt_stream.rs): it prices an admit's return as exposed when the copy lane still owes returns, and that depends on how far the lane has got. I never saw it change output in my runs, but it reads the same kind of state, so it goes out with the first.

Introduced by: 5012cc05bbe746f0b8abc7d43d05eddb81275b77 (2026-10-08, xsplit::admit_walk). The timed rate itself came earlier with 156125b22 (2026-10-07). There it priced only units at least m_min wide, and narrower units admitted from the fixed STREAM_FLOOR. 5012cc05b priced every split pick at a probed layer through admit_walk, so prompts of any width read the timing. The return_cost read came with ffa9f9203 (2026-10-09).

What changed:

  • crates/gpu/src/host/xstream.rs: lane_rate prices each probed expert's bytes at a fixed rate for where they sit, LANE_HELD_B_PER_US (20,410 B/µs) for host memory and LANE_PAGED_B_PER_US (3,600 B/µs) for the NVMe tier. It is a function of the plan only. The timed probe stays as probed_b_per_us, printed beside the priced rate: the load line keeps xstream_lane_gbs= as the measured value and gains xstream_priced_gbs=.
  • crates/gpu/src/host/swap.rs, crates/gpu/src/host/swap_source.rs: SwapSource::paged says whether the NVMe tier serves an id. FileSwap answers it with the existing tier_serving.
  • crates/gpu/src/host/prompt_stream.rs: return_cost marks a return as exposed only at the last card layer of the call's last walk. HostTier::call_returns_owed, which had no other caller, is gone.
  • crates/gpu-gates/src/bin/gate_nvtier.rs: a new sittings clause loads the paged plan twice in child processes, the second beside four threads copying 256 MiB. It compares the stream mode, the priced rate, every pick (unit, layer, admitted set, floor, counts), 106 greedy tokens and 106 logits rows bit for bit. The probe value is printed and not judged. The load part of arm moved into open_arm, which arm and the children share.
  • Doc updates in xsplit.rs, body38.rs, wide38.rs, registry.rs (the BLOOMERY_XSTREAM row), gate_xstream.rs and the justfile description of gate-gpu-nvtier.

The two rates are fixed numbers. LANE_PAGED_B_PER_US is the quiet probe value of the paged Qwen3.8 plan on an RTX 5090, so a quiet load on main and on this head give the same tokens. On a machine whose real lane differs from these numbers, picks may fit the copies less well. I did not round the probe into bands, because loads on either side of a band edge would still split.

Release notes: Fixed: under the default expert stream, the same prompt no longer gives different greedy tokens on different loads, because the stream prices its lane by where the experts sit and not by a timed probe.

Code shape

  • No second copy. The new items reuse existing owners: tier_serving for the paged test, shared/xstream_rule.rs for the unset stream rule, spawn_helper for the copy threads and one open_arm for the load.
  • Model code holds only architecture facts. The change is in the common stream, swap and gate code. No model file gained a branch.
  • Dead code is gone. HostTier::call_returns_owed had one caller and is removed. SwapMachine::returns_owed stays because gate_swap reads it, and only its doc changed.
  • No silent failure. A sitting child that prints no stream mode, no sitting line or a missing field stops with a named error. A panicking copy thread is an error.
  • Comments state what is true now. No dates, issue numbers or measured values were added to code comments, and check-comments passed in the contribution check below.
  • No relaxed gate. No band, tolerance or lint level moved. The new clause shows FAIL on the old rule first.
  • cargo fmt is clean on this tree. cargo clippy was not run on this head, so the lint count is unchecked.

Duplication found or removed (path:line):

  • crates/gpu-gates/src/bin/gate_nvtier.rs:1793 resembles crates/gpu-gates/src/bin/gate_clef_serve.rs:567 and crates/gpu-gates/src/bin/gate_glm5next_serve.rs:622. It is this gate's own grant_field reader, renamed for a second clause. Each gate is its own crate root with no shared owner for it.
  • crates/gpu-gates/src/bin/gate_nvtier.rs:1984 resembles crates/gpu-gates/src/bin/shared/q38_history.rs:47. The child keeps one digest per logits row, as arm in this gate does. q38_history::step stores whole rows, and including that module would pull its unused verify and window helpers into this gate.

What I ran

The PR head is c69d73f949e91ebf6483967abe6accc51b76bb1d, one commit on upstream main be69eb0ce882dcddd318adb8ab7082c79e39afd1. Everything below ran on this head, except the main and older-commit rows, which ran on the commits they name.

Unit tests:

test result: ok. 28 passed; 0 failed; 0 ignored; 0 measured; 346 filtered out; finished in 0.00s
test result: ok. 27 passed; 0 failed; 0 ignored; 0 measured; 254 filtered out; finished in 0.06s

The first line is cargo oxide test --arch sm_86 -- -p bloomery-gpu --release --lib -- xstream prompt_stream swap. The second is cargo test -p bloomery-runtime --release --lib -- xsplit. The first added test, the_lane_prices_each_copy_at_its_sources_rate, fails when a paged expert is priced at the held rate.

Reproduction, on an RTX 5090 machine with the Qwen3.8 UD-Q4_K_XL GGUF on local NVMe, run the same way on main and on this head:

BLOOMERY_DRAFT=off BLOOMERY_CARD_BUDGET=12G BLOOMERY_HOST_ROOM=28G generate_qwen3moe --tokens <first 512 ids of the qwen4exp prose corpus> -n 1024 --ctx 3072 --place a

BLOOMERY_RESIDENCY and BLOOMERY_XSTREAM are unset. The md5 is the first 12 hex digits of grep -a '^tokens ' <log> | md5sum. A warm load runs with the model in the page cache. "Page cache dropped" runs after the model files were evicted with POSIX_FADV_DONTNEED. "Beside a copy load" runs with a four thread memory copy loop on the host. The probe column is the printed timing of the lane probe.

Build Load Probe GB/s Tokens md5 Admitted experts
main 58356c003 warm 3.59 a06a8cdd9980 507
main 58356c003 warm, second load 3.65 eeaf52667d5f 515
main 58356c003 page cache dropped 3.68 93f6dbf1fedd 519
main 58356c003 beside a copy load 2.23 d83de78d0bb0 349
head c69d73f94 warm 11.42 a06a8cdd9980 507
head c69d73f94 warm, second load 3.52 a06a8cdd9980 507
head c69d73f94 page cache dropped 3.65 a06a8cdd9980 507
head c69d73f94 beside a copy load 2.79 a06a8cdd9980 507

On main the tokens first differ from the first load at index 102 for the second load and for the dropped page cache, and at index 85 beside the copy load, counting from 0. On the head, all four loads give the same tokens and the same picks, whatever the probe reads. The head's first load gives the same tokens as main's first load.

Two other settings give the same tokens on main and on the head. With BLOOMERY_XSTREAM=admit no probe is read, and with BLOOMERY_HOST_ROOM=100G the plan has no NVMe tier:

Build Run Probe GB/s Tokens md5 Admitted experts
main 58356c003 BLOOMERY_XSTREAM=admit none dcffff709f55 605
head c69d73f94 BLOOMERY_XSTREAM=admit none dcffff709f55 605
main 58356c003 BLOOMERY_HOST_ROOM=100G, first load 12.32 dcffff709f55 605
main 58356c003 BLOOMERY_HOST_ROOM=100G, second load 11.43 dcffff709f55 605
head c69d73f94 BLOOMERY_HOST_ROOM=100G, first load 12.21 dcffff709f55 605
head c69d73f94 BLOOMERY_HOST_ROOM=100G, second load 10.31 dcffff709f55 605

To place the introducing commit, I ran the same command on its parent and on it. The parent 6ec3b939 gave the same tokens cfc3ae1e001c on three loads with probes of 3.75, 11.98 and 7.94 GB/s. 5012cc05b gave 19f2e3fe4318 on loads with probes of 11.50 and 11.94 GB/s, and c1fde2f88857 on a load with a 7.82 GB/s probe.

Contribution check on the head, tier t0, on an x86_64 Linux machine:

DONE tier=t0 total=107 red=0 wall=653s

GPU Evidence

The card is an RTX 5090, driver 595.99.02, CUDA 13.2. These lines are from nvidia-smi on the machine that ran the tests, the reproduction and the gates:

| NVIDIA-SMI 595.99.02              Driver Version: 595.99.02      CUDA Version: 13.2     |
|   0  NVIDIA GeForce RTX 5090        Off |   00000000:01:00.0 Off |                  N/A |
NVIDIA GeForce RTX 5090, 595.99.02, P1, 44

The gate plan on main opens its card census only for the A6000 and the 3090 by name. On this machine each gate run added one line to crates/gpu-gates/src/bin/shared/gate_card.rs so the census also names the 5090, and the file was restored after each run. That line is not part of this PR.

With the old pricing rule restored (x.lane_b_per_us = x.probed_b_per_us; set again after the constants are built in XStream::new), the new sittings clause fails. The probe reads 11.85 and 2.01 GB/s and the priced rate follows it, so the picks and the logits rows differ:

BLOOMERY_BOX_LOCAL=1 just gate-gpu-nvtier
sittings: the paged plan under mid-p0-s1 and the unset stream rule (split / split, the same true), loaded alone and beside a host copy load: the lane probed 11.85 / 2.01 GB/s (printed, not judged) and priced 11.85 / 2.01 GB/s, the same false; 96 / 96 picks the same false; 106 greedy tokens equal true, 106 logits rows bit for bit false: FAIL
gate_nvtier: FAILED: one or more checks above did not pass

On the PR head the same command passes. The probe reads 11.40 and 2.21 GB/s, the priced rate is 3.60 GB/s in both sittings, and the picks, tokens and logits rows are equal:

BLOOMERY_BOX_LOCAL=1 just gate-gpu-nvtier
sittings: the paged plan under mid-p0-s1 and the unset stream rule (split / split, the same true), loaded alone and beside a host copy load: the lane probed 11.40 / 2.21 GB/s (printed, not judged) and priced 3.60 / 3.60 GB/s, the same true; 96 / 96 picks the same true; 106 greedy tokens equal true, 106 logits rows bit for bit true: PASS
gate_nvtier: every clause passed

What I ran into

This does not block the PR.

  • cargo clippy was not run on this head.
  • just gate-gpu-xstream and just gate-gpu-swap reported PASS on this change before the final rebase onto main. The files they cover did not change in that rebase, and I did not rerun them on the final head.
  • The other gates that read the split pricing are A6000 and 3090 workstation gates, and I could not run them here. gate_qwen38_residency is one of them. It repeats its split sitting inside one load, so its probe stays the same and it cannot see this defect.
  • On a card with no ring slot, such as a 3090, the sittings children follow the unset rule into admit and print their mode. The new clause then does not exercise the split pricing on that card.
  • I did not time decode or prefill. The change adds no kernel, launch, copy, sync or lock to either path. lane_rate runs once per load over the 32 probe experts.

Hardware

An RTX 5090 32 GB machine, x86_64 Linux, driver 595.99.02, CUDA 13.2, about 125 GB of available host memory, with the model on local NVMe. A 28 GB host room makes the plan page routed experts through the NVMe tier.

AI help

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

…es its lane by where the probe's experts sit (lane_rate), its probe's timing printed beside it, and an admit's return by the walk's last card layer alone; gate_nvtier's sittings clause loads the paged plan twice, once beside a host copy load
@github-actions github-actions Bot added 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 22, 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: Split pricing uses fixed source rates, and return pricing uses walk position.

Non-blocking

⚠ Provide a timed prefill A/B: crates/gpu/src/host/prompt_stream.rs:418 removes the backlog-dependent return charge from earlier card layers in a returning call's final walk. An admit that adds a restore contributes 2 × expert_b lane bytes [derived: admission plus restore]. Fixed lane pricing also changes the selected sets. Attach a same-lease base/head prefill comparison on the contributor's card, as required for dispatch changes; token equality does not establish unchanged throughput.

Checked

Return pricing: traced the prefill caller through PromptStream::pick, admit_walk, and queued restore copies.
Lane pricing: source classification selects fixed rates; the measured probe remains separate. An empty or zero-byte probe is rejected before lane pricing.
Tests: lane assertions reject source-rate and count-weighting mutants; the sitting-record test rejects missing fields. The PR body reports FAIL-first for restored probe pricing. These were checked by inspection, not Rust execution.
Gates: no existing threshold, tolerance or case relaxed.
Escape catalog: C1–C4 do not match the changes.

Notes

The attached RTX 5090 gate run identifies c69d73f94; the reviewed head is 186be362c. Current-head hardware evidence is absent. No builds or hardware gates ran during this review.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_nvtier.rs, crates/gpu-gates/src/bin/gate_xstream.rs, crates/gpu-gates/src/record.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 22, 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 3828101 into midagedev:main Oct 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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