Skip to content

gpu, model, gpu-gates: keep host tier reads protected through copies and page drops - #746

Merged
juliankang4 merged 7 commits into
midagedev:mainfrom
juliankang4:fix-host-tier-copies
Oct 23, 2026
Merged

juliankang4 merged 7 commits into
midagedev:mainfrom
juliankang4:fix-host-tier-copies

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

호스트 expert 계층에서 복사 원본이 너무 일찍 풀리거나, 같은 요청의 다음 hit이 밀려나거나, prompt 분할이나 card와 host 분할 방식에 따라 heat 순위가 뒤집히는 결함 네 개를 고칩니다.

Part of #565. Tracked in #699.

What and why

This fixes four defects in the host expert tier (XStream, NvTier and the TierSlots heat counts). Each one has a test that was written first and shown to fail without its fix.

  1. Fallback copy source released early. When XStream falls back to a copy from an unpinned source, it released the source read before the copy stream finished. A reused slot could then change the bytes the copy was still reading. The fallback now keeps the read until the stream drains, on the normal path and on the path where only some copies were enqueued. If the drain itself returns an error, the source and its read stay held, so a copy in flight never reads memory that was already handed back.
  2. Queued page drop included a newer read. A queued NVMe page drop could cover an expert whose read opened after the drop was queued. The read entry, the update of the queued ranges and the page release now share the drop queue lock, and an expert with a newly opened read is cut out of the pending ranges. The synchronous drop_layer follows the same rule.
  3. Default policy evicted a hit needed later in the same claim. With the default tick policy, a miss early in a claim could evict a resident expert that a later column of the same claim needed, and that expert was then read again. Every claim kind and eviction policy now protects the claim's resident ids from its own misses.
  4. Heat ranking depended on how a prompt was split. BLOOMERY_NVTIER_EVICT=heat counted a whole union at one moment, so the same routing history split into different calls ranked experts differently. Heat now takes each selection's original column position and decays from there, and a call whose columns route no host expert still advances the clock. A routed column advances the clock once even when the card and host legs serve it separately: a host tail reuses the column its card ticket already counted, and on the CPU tier only the first per-slot call for a column counts it. A CPU-tier column whose slots all go to the host makes its empty claim only on a layer the NVMe tier covers, so a layer kept resident in RAM never asks the tier for an arena it does not have. Prompt and multi-column step claims share this through TierSlots, and gate_nvtier expects the same per-position decay.

The default tick order of routed ids, the weight bytes and the output arithmetic are unchanged. The heat option is still opt-in; only the order in which it evicts changes, so one routing history gives one ranking however it is split. Nothing depends on the rank count, and no model file gained a branch.

Release notes: Fixed: the host expert tier keeps a copy's source read until the copy lands, no longer drops pages under a newer read, keeps a claim's later hits resident, and ranks heat the same however a prompt is split.

Code shape

  • No second copy. The fixes live in the existing owners: XStream, NvTier, TierSlots and LayerCounts. The only new helper is LayerCounts::add_columns, which both the prompt and the step path call.
  • Model code holds only architecture facts. moe.rs changes only how it hands columns to the shared TierSlots owner. No model file gained a branch, flag or trait method for one model.
  • Dead code is gone. The single-call drop_marked and experts_into_resident wrappers are removed, and so is the drop queue's running flag, which no reader outside its mutex could observe. Every TierSlots implementation and caller, including gate_nvtier, follows the new signature.
  • No silent failure. Copy, drain and read-release errors are returned. An error after some copies were enqueued drains first. A read is not opened when planning the pending ranges returns an error.
  • Comments state what is true now. The module notes describe the current lock and eviction behavior.
  • No relaxed gate. No band, tolerance or lint level moved. The changed heat expectations in the gate keep a dated PIN(...) comment, and the new test-only pinned source view carries a SAFETY note and its tools/unsafe-ratchet.txt pin.
  • cargo fmt is clean on what I touched. cargo clippy has not been run on this head, so the lint count is unchecked.

Duplication found or removed (path:line): none. The duplicate scan flagged a test-local LAYER constant, which is not a copy of a shared routine.

What I ran

Fail-first, then the fix, for each defect. The test names are in crates/gpu/src/host/nvtier.rs and crates/gpu/src/host/xstream.rs.

Tier claim, queued drop and heat ranking, on a Linux host with the fix removed (only the new tests fail):

test host::nvtier::tests::a_tick_claim_keeps_hits_named_after_its_first_miss ... FAILED
test host::nvtier::tests::a_queued_drop_keeps_a_read_opened_after_the_request ... FAILED
test host::nvtier::tests::heat_counts_keep_the_same_rank_across_prompt_splits ... FAILED
test result: FAILED. 43 passed; 3 failed; 4 ignored; 0 measured; 340 filtered out; finished in 0.04s

With the fix, the same host:

test result: ok. 46 passed; 0 failed; 4 ignored; 0 measured; 340 filtered out; finished in 0.02s
test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 383 filtered out; finished in 0.00s
test result: ok. 29 passed; 0 failed; 0 ignored; 0 measured; 435 filtered out; finished in 0.09s

These are the host::nvtier, host::xstream and moe:: tests. The ignored tests need a CUDA device and are not counted here.

These runs were on an earlier head of this branch. The card and host legs were then made to count a column once. Its test, a_card_claim_and_its_host_tail_count_one_column, run against the code before that change on an x86-64 Linux host, fails on the heat value:

assertion `left == right` failed
  left: Some(0.9785720620877002)
 right: Some(1.0)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 394 filtered out; finished in 0.00s

With the change, that test, the four heat_counts_keep_the_same_rank_across_* tests (prompt splits, step splits, resident columns, card and host legs) and an_active_dropper_finishes_before_a_new_read_opens pass:

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 395 filtered out; finished in 0.00s
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 392 filtered out; finished in 0.05s
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 395 filtered out; finished in 0.10s

On a two-slot fixture holding experts [2, 7], a claim for [1, 2] misses twice on main and once with the fix, because the hit on 2 is no longer evicted by the first miss. That is one fewer refill in this fixture and says nothing about throughput or latency.

The CPU tier's empty claim, on the GPU below. hw_held_node_nvme_host_run_keeps_eager_and_captured_rows keeps layer 1 resident and pages layer 0, then sends all-host columns on both layers through the CUDA host callback, eagerly and under graph replay, for F32 and Q8 activations. Without the coverage check the callback fails on the resident layer:

called `Result::unwrap()` on an `Err` value: Shape { what: "host expert tier", detail: "layer 1 expert 4294967295: filling its slot: NvTier::ensure: the layer's arena" }
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 395 filtered out; finished in 12.53s

With the check, the output stays at its expected value on both layers and later normal service on the same executor passes:

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 395 filtered out; finished in 1.87s

Fallback copy source, on the GPU below. The test hw_held_a_fallback_copy_keeps_its_source_until_it_lands overwrites a pinned source slot while the fallback copy is in flight and checks the destination bytes. Without the fix the destination holds the overwrite:

assertion `left == right` failed: the destination keeps the source's original bytes
  left: 572662306
 right: 286331153
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 389 filtered out; finished in 0.50s

With the fix, covering the normal copy and the partial enqueue error:

test host::xstream::tests::hw_held_a_fallback_copy_keeps_its_source_until_it_lands ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 389 filtered out; finished in 0.60s

The GPU run was done before a later rebase. The final head's xstream.rs is the same blob those runs tested, so I did not rerun it.

Compile check of everything on this head, including integration tests, benches and gate binaries, on an RTX 5090 machine with the full feature list of the upstream check recipe:

cargo check --workspace --all-targets --features gpu,bloomery-gpu-gates/deepseek41,bloomery-gpu-gates/vision,bloomery-gpu-gates/glm5next,bloomery-gpu-gates/mimo2,bloomery-gpu-gates/solar2,bloomery-gpu-gates/minimaxm3,bloomery-gpu-gates/gemma-embedding2,bloomery-gpu-gates/gemma4a,bloomery-gpu-gates/clef,bloomery-gpu-gates/hf,bloomery-gpu-gates/glm5next-hf,bloomery-gpu-glm5next/hf,bloomery-decision/safetensors
Finished `dev` profile [unoptimized + debuginfo] target(s) in 28.26s

cargo fmt was run on the changed Rust files and git diff --check is clean. cargo clippy and just contrib-check have not been run on this head.

GPU Evidence

The card is a DGX Spark GB10, driver 595.84, CUDA 13.3. These lines are from nvidia-smi before the fail-first run and the fixed run:

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

Commands:

RUST_TEST_THREADS=1 bash tools/gate.sh --oxide --release -p bloomery-gpu --lib -- hw_held_a_fallback_copy_keeps_its_source_until_it_lands --ignored --nocapture
RUST_TEST_THREADS=1 bash tools/gate.sh --oxide --release -p bloomery-gpu --lib -- host::tier_cpu::tests::hw_held_node_nvme_host_run_keeps_eager_and_captured_rows --ignored --exact --nocapture --test-threads=1

The result lines are in the section above.

  • just gate-gpu-lib not run: the ignored GPU test went through tools/gate.sh on the card instead.

The change adds no kernel and touches no arithmetic, so I added no PTX comparison. Whether the page-drop and heat changes move decode speed was not measured in this PR.

What I ran into

This does not block the PR.

  • The gate_nvtier clauses for the changed heat expectations were not run on a GPU for this head. Host unit tests and the all-targets compile cover them.
  • A new drop-pending range is planned for every new read while a drop is pending, across the whole layer. Clipping the range inside the same drop owner could do less work. I have not measured how often a drop is pending or what the planning costs.

Hardware

A DGX Spark (GB10, driver 595.84, CUDA 13.3) for the GPU fail-first and fix runs, x86-64 Linux hosts for the tier tests, and an RTX 5090 machine for the all-targets compile check.

AI help

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

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 23, 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 two supported findings are non-blocking; no must-fix item remains.

Non-blocking

⚠ Measure the added synchronization: nvtier.rs:2412 adds one shared drop-queue lock per non-host expert read. While that layer has a pending drop, each read also allocates the marks, ranges and output vectors, plus any nonempty run vectors. xstream.rs:1438 adds one host drain per streamed expert on the fallback path.
These terms affect decode and prefill overlap. Attach the owning gate results and the same-lease base/head A/B required for dispatch changes. Measuring now isolates these costs before later changes obscure them.

⚠ Assert the CPU heat clock: deleting columns = 0 at tier_cpu.rs:90 advances the clock once per served slot. The CPU-tier fixture selects Tick at tier_cpu/tests.rs:262, so its output assertions do not detect that mutant.
Exercise Heat and assert routing counts after a column with two served slots and an all-HOST column. This protects the new counting rule before another callback change can regress it.

Checked

Evidence: compared the cited synchronization changes against the base and traced pending-drop planning through layer_marks and runs_of.
Silent failure: range-planning, source/enqueue, drain and read-release errors propagate. A failed fallback drain retains the source and its open read.
Tests: inspected the CPU fixture's policy, selections and assertions. The heat-clock coverage gap remains advisory under the fix-PR recurrence-prevention rule.
Escape catalog: C1–C4 do not match these findings. No ledger lessons are in force.

Notes

Validation was static; project tests were not run. The supplied GPU logs omit the tested base/head commit hashes and a timed base/head A/B.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_deepseek41_step.rs, crates/gpu-gates/src/bin/gate_hybrid.rs, crates/gpu-gates/src/bin/gate_nvtier.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)

@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 2a7005b into midagedev:main Oct 23, 2026
7 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 model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant