Skip to content

levers, gpu, model, gpu-gates: BLOOMERY_NVTIER_EVICT=heat takes the NVMe arena's coldest routing count (tierengine S6) - #650

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:nvtier-heat-eviction
Oct 22, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:nvtier-heat-eviction

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

NVMe expert 계층이 slot을 비울 때 쓰는 규칙을 옵션 BLOOMERY_NVTIER_EVICT=tick|heat로 고르게 합니다. 기본값은 기존과 같은 tick이고, heat는 RTX 5090에서 decode 중 NVMe 읽기를 줄입니다.

Part of #565.

What and why

This adds the option BLOOMERY_NVTIER_EVICT=tick|heat. It picks which slot the NVMe expert tier evicts when it has to read a missing expert from NVMe. Unset means tick, the current rule: the slot with the oldest last-use tick goes first. With tick the tier behaves as on main, down to its counters. heat evicts the slot whose expert has the lowest decayed routing count. The default stays tick; turning heat on is the maintainers' call.

On the plan I measured, heat cuts the decode NVMe fills per token by 6.58 % and leaves the output unchanged. The numbers are under "What I ran". The change has three commits: the option, the gate plan that opens the RTX 5090 by name, and a lazy tie-break in the heat comparator.

Background: when routed experts do not fit on the card or in host memory, the NVMe tier keeps them on NVMe and reads the ones a step needs into a fixed arena of pinned host slots. A read that finds no free slot evicts a victim. heat changes only the choice of victim.

  • Option (crates/levers/src/registry.rs, crates/levers/src/lib.rs): the row BLOOMERY_NVTIER_EVICT takes the words tick and heat, and unset reads as tick. Any other word is refused by name. NvTierLevers.evict carries the choice to NvTier::of_paged (crates/gpu/src/model.rs).
  • Counts (crates/gpu/src/host/nvtier.rs): RouteCounts holds one score per layer and expert, sized at load, so a decode step allocates nothing. Under tick the table does not exist. A score grows by 2^(since/H) per counted column with H, the half-life, set to 32 columns (HEAT_HALF_LIFE), and is rescaled once per 64 half-lives. Comparing two scores therefore needs no decay arithmetic.
  • Where counts are written: a successful step claim counts each named id once and moves the layer's clock by one column. A step union, which spans several columns, counts each expert once per column that routed it and moves the clock by the number of columns. Both of its prefetch paths do this, the reused step slot and the allocating fallback; before this fix a step union counted one column. A prompt union (TierSlots::note_union in crates/model/src/moe.rs, which now takes the column count) counts each id once per column and moves the clock by that many. A victim read counts one column and leaves the clock alone. The counting sits inside the books lock the claim already holds.
  • Victim order under heat (pick_slot): a free slot first, then an unpinned transient slot, then the lowest score, with the last-use tick breaking ties. The comparator reads the tie-break keys only when the earlier keys tie, and the order is the same as when it read them all. A call never evicts an id it is itself reading. tick keeps main's (tick, seq) order.
  • Gate (crates/gpu-gates/src/bin/gate_nvtier.rs): the new clause evict checks the victim order for tick and for heat, and the stepunion clause checks the counts of a four-column step union. The trait that crates/model/tests/alloc.rs implements gained the column arguments, so that test file follows the new signature.
  • Docs: docs/serving.md describes the option. docs/research/tierengine.md records the S6 row, and crates/runtime/src/swaprule.rs gets one doc line. SwapRule keeps its own counts, because it counts only decode rows, blends streams, decays on its own schedule and plans card slots. The arena's counts also cover prompt columns and decay by layer clock, so the two do not share one owner.

Release notes: Added: BLOOMERY_NVTIER_EVICT=heat makes the NVMe expert tier evict the expert with the lowest decayed routing count, which lowers NVMe fills per decoded token on an RTX 5090. The default tick is unchanged.

Code shape

  • No second copy. Routing counts for the arena have one owner, Books.counts in nvtier.rs, read through NvTier::route_count. The gate reads that count and does not recompute it. SwapRule's decayed counts differ in input, schedule and scope, as described above, so they are not a copy.
  • Model code holds only architecture facts. The option lives in the common tier code and the levers registry. No model file gained a branch.
  • Dead code is gone. The test helper that one test used moved into that test, and eight_tier holds the body card_tier had.
  • No silent failure. An unknown option word is a named refusal. The gate reads a count that is missing as a named error and no longer defaults it to zero.
  • Comments state what is true now. The comments describe the code as it is, with no dates or measured numbers.
  • No relaxed gate. No band, tolerance or lint level moved.
  • cargo fmt --all passes. 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 reported no candidates.

What I ran

The PR head is 4ede92943ec3c0ec2aa58e16f840f56c4dc273eb, three commits on main f02460d1604567d123a9210ffa8f33485cfceca2: the option, the gate plan and the lazy comparator. The A/B, the gates, the PTX comparison and the nvtier tests below ran on the same three commits on main 6b0a82f91818bd1213b79a3e1d3ac59a1fb9c7a0. The rebase onto f02460d16 touches none of their files.

Fail-first for the step union fix: with the two count calls set back to one column, the new unit test fails on the reused step slot (allocating=false: column clock) and on the allocating fallback (allocating=true: column clock), the model test of the step claim fails (the step claim carries each id's routed columns, including host ids), and the gate clause stepunion counts Heat fails. With the code restored, the unit tests and the gate pass.

Unit tests:

test result: ok. 47 passed; 0 failed; 4 ignored
test result: ok. 138 passed; 0 failed
test result: ok. 45 passed; 0 failed

These are the nvtier tests in bloomery-gpu, the moe:: tests in bloomery-model and the bloomery-levers tests. The four ignored tests need a CUDA device.

A/B against main, on an RTX 5090 machine. The plan is S12: --place a BLOOMERY_CARD_BUDGET=12G BLOOMERY_HOST_ROOM=28G. Each arm runs generate_qwen3moe --tokens <ids> -n 1024 --ctx 3072 --time --logits --place a on the same fixed 512-token prompt (ids below) with BLOOMERY_DRAFT=off BLOOMERY_RESIDENCY=off, so it decodes 1,024 tokens after a 512 token prompt. The model is Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf from unsloth/Qwen3.8-Flash-Next-GGUF (revision 766911a6), with one slot and a context of 3072. main is a build of upstream main, tick is this branch with the option unset, and heat is the same binary with BLOOMERY_NVTIER_EVICT=heat. The three arms ran three times each, in rotating order after one discarded warm-up, and the table shows medians. The run started after the host's load stayed quiet for 30 s.

Shape Main decode fills/step Heat decode fills/step Change [derived] Output differences
S12 17.428 16.281 -6.58% 0

All nine measured S12 runs have identical generated tokens and reported logits digests. Heat reduces decode NVMe fills by 6.58% against main (17.428 to 16.281 fills/step) [derived].

Arm Runs Decode median tok/s Decode range tok/s Prompt median tok/s Decode fills/step
main 3 26.822 26.784 to 26.858 135.74 17.428
tick 3 26.787 26.763 to 26.825 135.96 17.428
heat 3 26.999 26.958 to 27.004 136.48 16.281
  • The fills per step divide the decode step fills (17,829 for main and tick, 16,655 for heat in every run) by 1,023 decode steps. tick matches main in its counters, so tick is main's behavior.
  • Paired by round, heat is +0.730 % faster than tick (95 % interval +0.220 % to +1.240 %) and +0.618 % faster than main (+0.180 % to +1.056 %). tick against main is -0.111 % (-0.639 % to +0.418 %).
  • The intervals come from three paired rounds (Student t) and describe this sitting only. I read the speed change as small and not settled. The fill reduction and the identical outputs are the evidence for the change.
The 512 prompt ids
10218,19305,9141,10369,26,271,269,11,3067,8234,24106,13,271,1311,58206,10657,7669,271,22587,42427,271,66070,10218,49700,13,271,3152,39748,50,318,9751,3330,539,264,3593,12,3036,7869,10349,8555,553,271,84424,220,16,13,436,4053,793,13,271,84424,220,17,13,561,68791,7428,346,13,271,84424,220,18,13,561,2989,2589,30463,77,13,271,84424,220,19,13,561,19133,24520,13,271,84424,220,20,13,41767,13,271,84424,220,21,13,561,6476,13,271,84424,220,22,13,561,51571,13,271,84424,220,23,13,561,387,12472,275,13,271,84424,220,24,13,561,7987,1588,13,271,84424,220,16,15,13,357,27065,315,11254,13,271,84424,220,16,16,13,12458,70,754,13,271,84424,220,16,17,13,11756,30157,13,271,84424,220,16,18,13,31275,2185,633,13,271,84424,220,16,19,13,443,505,10828,13,271,84424,220,16,20,13,71442,1071,13,271,84424,220,16,21,13,561,25946,13,271,84424,220,16,22,13,561,78987,13,271,84424,220,16,23,13,5133,4246,13,271,84424,220,16,24,13,561,35416,13,271,84424,220,17,15,13,1942,19500,396,13,271,84424,220,17,16,13,33714,357,2402,13,271,84424,220,17,17,13,74078,9777,13,271,84424,220,17,18,13,561,11723,43236,13,271,84424,220,17,19,13,561,76301,13,271,84424,220,17,20,13,3746,2208,13,271,84424,220,17,21,13,38264,321,326,17168,13,271,84424,220,17,22,13,38264,321,326,17168,13,271,84424,220,17,23,13,357,10259,13,271,84424,220,17,24,13,10925,357,10259,26,310,19803,11,769,20057,13,271,84424,220,18,15,13,561,26902,13,271,84424,220,18,16,13,15780,238190,13,271,84424,220,18,17,13,174177,2369,13,271,84424,220,18,18,13,561,11954,14134,47598,13,271,84424,220,18,19,13,561,23981,12,2473,13,271,84424,220,18,20,13,561,35277,12,11993,13,271,84424,220,18,21,13,561,33252,12,38064,13,271,84424,220,18,22,13,60577,13,271,84424,220,18,23,13,414,31693,13,271,84424,220,18,24,13,5339,12458,12630,730,13,271,84424,220,19,15,13,61432,11,7950,33946,13,271,84424,220,19,16,13,380,26148,21857,13,271,84424,220,19,17,13,561,1190,14247,425,314,279,92684,13,271,84424,220,19,18,13,462,812,0,271,84424,220,19,19,13,561,20613,13,271,84424,220,19,20,13,561,214833,41688,13,271,84424,220,19,21,13,7828,76,4750,13,271,84424,220,19,22,13,561,6653,5084,4263,13,271,84424,220,19,23,13,561,5339

cargo fmt --all passes. cargo clippy, just contrib-check and the pre-push check set have not been run on this head.

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 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, 32607 MiB, 32110 MiB, 12.0

just gate-gpu-nvtier passes with the option unset and with BLOOMERY_NVTIER_EVICT=heat. The evict clause checks both victim orders, and the step union clause is green:

just gate-gpu-nvtier
evict Tick: layer 0 of 37 slots, id 0 stepped three times then 36 ids once: the transient's miss took Some(0) (PASS), the first id gone (PASS); the next step's miss took the transient (PASS); the one after took Some(1) (PASS); counts none (PASS): PASS
evict Heat: layer 0 of 37 slots, id 0 stepped three times then 36 ids once: the transient's miss took Some(1) (PASS), the first id kept (PASS); the next step's miss took the transient (PASS); the one after took Some(2) (PASS); counts kept (PASS): PASS
stepunion counts Heat: four columns route one id four times and another once, the third decays four columns: PASS
gate_nvtier: every clause passed
gpu-gate.sh: gate_nvtier ran 138 s (exit 0)

The PTX against main is unchanged (just canon-check):

canon-check: 3 bins, 1066 entries: 1066 identical, 0 reordered-only, 0 differs, 0 only-on-one-side; rows equal (jit columns not compared: no-jit both)

With the two count calls set back to one column, the step union clause fails, and so does the gate:

stepunion counts Heat: four columns route one id four times and another once, the third decays four columns: FAIL
GPU GATE RED: gate_nvtier (exit 1)

Two more fail-first checks ran on an earlier tree that has the same victim order and gate plan. Without the second commit the gate plan did not open this card, so just gate-gpu-nvtier refused it and exited with code 1:

gate_nvtier: the visible card NVIDIA GeForce RTX 5090 is none of this workstation's cards (A6000, 3090): the gate plan opens its card by name
GPU GATE RED: gate_nvtier (exit 1)

With the count comparison removed from the heat victim order, BLOOMERY_NVTIER_EVICT=heat just gate-gpu-nvtier fails on the evict Heat clause:

evict Heat: layer 0 of 37 slots, id 0 stepped three times then 36 ids once: the transient's miss took Some(1) (FAIL), the first id gone (FAIL); the next step's miss took the transient (PASS); the one after took Some(1) (FAIL); counts kept (PASS): FAIL
gate_nvtier: FAILED: one or more checks above did not pass

The change adds no kernel and no launch, copy or synchronize on the decode path. The new work is an addition into a table sized at load, inside a lock the claim already holds, so the timed A/B above is the performance evidence.

What I ran into

This does not block the PR.

  • Only the S12 plan was measured on this head.
  • When the three hw_a_ allocation tests in bloomery-model ran together, hw_a_one_column_miss_allocates_nothing failed with one allocator call. The tests count allocations process-wide, so a parallel test can add a call. The same test passes alone (test result: ok. 1 passed; 0 failed).
  • cargo clippy and just contrib-check have not been run on this head.

Hardware

An RTX 5090 machine (Ryzen 9 9950X, 121 GiB RAM, Samsung 9100 PRO), driver 595.99.02, CUDA 13.2, for the unit tests, the gate and the A/B.

AI help

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

…VMe arena's coldest routing count (tierengine S6)

Once no slot is free, a miss of the NVMe tier's arena took the least
recently used hot slot (after the transients). BLOOMERY_NVTIER_EVICT=heat
ranks the hot slots by a decayed routing count instead, the least recently
used among equal counts; tick, the unset word, is the rule as it stands.

The tier's books own the counts (RouteCounts): per paged layer and expert,
the columns that routed it, halved every 32 columns the layer serves. A
step's claim counts each id it names once and moves the layer's clock one
column; a prompt's union call counts each id by its columns
(TierSlots::note_union now carries the call's columns) and moves the clock
by them; a residency victim's fill counts one column and moves no clock.
Counts are held as scores scaled by the clock, so a pick compares them with
no decay. Under heat a call's own ids are never its victims.

The card's residency rule keeps its own counts: they are a stream's kept
decode rows, blended across streams and decayed at its plans, where the
arena's take every column it serves, a prompt's included. swaprule.rs and
tierengine's S6 row say so; docs/serving.md names the lever.

gate_nvtier's clause 14 (evict) drives two floor-arena tiers, one each
rule, through the same claims and reads which slot each miss took.
@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 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 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: No must-fix behavior or quality defect found.

Checked

  • Duplicates: 25 new definitions checked, including local constants. The one dryer pair maps different levers, so it shares structure only. SwapRule counts kept decode rows per stream; arena counts cover different inputs and clocks.
  • Complexity: evict_clause is a new gate with sequential setup, claims and assertions (29). Existing-function growth: stepunion_arm 42→48 adds a count check; run 150→152 adds clauses; of_paged 34→36 initializes heat; claim_fill 23→24 protects own ids; read 46→47 extends scope membership.
  • Silent failure: 5 optional-count and filtering sites followed to victim selection, statistics and assertions. No Result becomes a default. Poison recovery retains the books.
  • Tests, static mutation review: selector assertions reject removing the score comparison at crates/gpu/src/host/nvtier.rs:448. Own-hit eviction assertions reject removing heat's own-id protection at crates/gpu/src/host/nvtier.rs:644.
  • Tests, counts: both prefetch-path assertions reject advancing one column instead of four at crates/gpu/src/host/nvtier.rs:1787. Routing-count assertions reject counting duplicate ids twice, advancing the victim clock, or dropping rescaling at crates/gpu/src/host/nvtier.rs:1833.
  • Tests, model: prompt-note assertions reject replacing the column count with one at crates/model/src/moe.rs:1790. Step-union assertions reject dropping the full ids or offsets at crates/model/src/moe.rs:3240; updated overlap and refusal tests retain pin-lifetime assertions.
  • Tests, levers: accessor and scope assertions reject mapping heat to Tick at crates/levers/src/lib.rs:1151. The dedicated test also rejects changing the unset default or accepting unknown words.
  • Gates: no existing pin, tolerance or clause relaxed. The PR supplies fail-first output for tick-only heat eviction and one-column step-union counting.
  • Performance: heat adds count updates, miss scans and one books lock per prompt union/layer. Storage is preallocated; no device launch, copy or wait is added. The PR supplies a timed main/tick/heat comparison on RTX 5090.
  • Escape catalog: C1–C4 do not match.

Notes

Review was static; tests were not rerun here. The supplied card runs preceded the rebase. The PR states that clippy and contrib-check were not run on this head.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_nvtier.rs, crates/gpu-gates/src/bin/shared/gate_card.rs, crates/gpu/src/host/nvtier.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 3be38cd 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

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 model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant