Skip to content

model-hf: an NVFP4 matrix read whole bounds its read by what the read holds - #923

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-startup-3
Oct 28, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-startup-3

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

DGX Spark(GB10)에서 bloomery-serve -m <폴더>로 FP4-Local 체크포인트를 띄울 때, NVFP4 expert 묶음 하나를 읽는 데 드는 host 메모리를 실제에 맞게 세어 같은 공간에서 더 많은 묶음을 함께 읽게 해서 서버가 health를 열기까지의 시간을 줄이는 PR입니다.

Part of #565.

What and why

A folder load reads as many parts at once as their read bytes (Source::read_bytes) fit in the host room the plan reserves. For an NVFP4 matrix read whole, Checkpoint::read_bytes counted several times what the read holds, so a load of nvidia/Qwen3.8-Flash-Next-FP4-Local read fewer expert stacks at once than the room allows.

  • crates/model-hf/src/part.rs: an NVFP4 matrix read whole now counts its stored tensors in one direct buffer, its decoded block scales, one weight's scale parts widened to u32, its output and one tensor scale per expert. Every part's bound also counts the direct buffer's alignment block and the shard probe of DirectFile::open. Other parts keep the general bound.
  • crates/hf/src/modelopt.rs: a routed stack reserves its blocks once, at their length, instead of growing per expert.
  • The part:: tests count each thread's allocations through a test-only global allocator and check every fixture part's peak against its read bytes. tools/unsafe-ratchet.txt moves model-hf from 1 to 3 blocks, 0 to 2 fns and 0 to 1 impl for this allocator, with a dated PIN.

Release notes: Changed: a DGX Spark server loading an FP4-Local folder reads more expert stacks at once, so it starts sooner.

Code shape

  • No second copy. The bound reuses Folder::file_range, Folder::raw, Dtype::size and DIRECT_ALIGN.
  • Model code holds only architecture facts.
  • Dead code is gone.
  • No silent failure. Every product and sum in the bound is checked and refused by name.
  • Comments state what is true now.
  • No relaxed gate. The unsafe ratchet rose with a dated PIN for new test code only.
  • cargo fmt and cargo clippy are clean on what I touched.

Duplication found or removed (path:line), or "none": none.

What I ran

Start time on one DGX Spark, base 49d84ecc10a7 and head 53a0a338a43f, each built with just release-build 0.3.10 and installed with tools/release/install.sh --version v0.3.10 --prefix <dir>. Model nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300, bloomery-serve -m <folder>. Three rounds of base cold, head cold, base warm, head warm; cold drops the page cache and the driver JIT cache. The metric is spawn to a 200 from /health.

# cold: a fresh HOME, so ~/.nv/ComputeCache starts empty, and posix_fadvise(DONTNEED) on every checkpoint file
env -i HOME=<home> PATH=/usr/bin:/bin <prefix>/bin/bloomery-serve -m <folder> --host 127.0.0.1 --port <port>
curl -fsS -m 2 http://127.0.0.1:<port>/health   # polled until it returns 200
RELEASE-BUILD arm=base rc=0 seconds=519
RELEASE-BUILD arm=head rc=0 seconds=492
INSTALL arm=base rc=0
INSTALL arm=head rc=0
GREEDY-SAME=1 replies=24

Median of three starts, range in parentheses.

Metric Base Head Difference Ranges overlap
Start to health, cold 36.94 s (36.94 to 37.16) 27.69 s (27.42 to 38.04) -9.25 s (-25.0%) yes
Start to health, warm 36.73 s (36.65 to 36.94) 27.44 s (27.18 to 27.71) -9.29 s (-25.3%) no
Checkpoint upload, cold 26.58 s (26.50 to 26.69) 17.56 s (17.14 to 27.90) -9.02 s yes
Checkpoint upload, warm 26.52 s (26.51 to 26.56) 17.34 s (17.26 to 17.64) -9.18 s no

Cold start to health is 9.25 s shorter (36.94 s to 27.69 s); warm start is 9.29 s shorter (36.73 s to 27.44 s).

Unit tests and the mutant each must catch, on an Apple Silicon Mac:

$ cargo fmt -p bloomery-hf -p bloomery-model-hf -- --check
FMT rc=0
$ cargo test -p bloomery-hf --lib modelopt
test result: ok. 19 passed; 0 failed; 0 ignored; 0 measured; 96 filtered out; finished in 0.11s
$ cargo test -p bloomery-model-hf --lib part::tests
test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 89 filtered out; finished in 0.08s
  • Dropping the decoded scales from the NVFP4 bound: cf.weight: 2373660 < 2434960.
  • The general bound for an NVFP4 matrix: cf.weight: 8415304 passes 2434960 by more than 77824.
  • One alignment block instead of three: bf.weight: 14344 < 21155.
  • Reserving each expert's blocks as it is appended fails a_routed_stack_keeps_one_scale_an_expert.

Not run: just gate-gpu-lib and the tests that need an RTX 5090 machine, which run on the maintainers' workstation.

Hardware

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

One DGX Spark, Linux aarch64.

AI help

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

Each expert's append reserved its own blocks, so the output grew by doubling
and a stack of three experts held room for four. append now reserves the
blocks of the experts left from the first, and the stack is one allocation
of exactly its bytes.
… holds

A folder part's read bytes size the parts a load reads at once. For an NVFP4
matrix read whole they counted each weight thrice, each compressed scale part
seven times and the output four times, about seven times the payload of a
compressed-scale stack. The read holds its stored tensors in one direct
buffer, each decoded block scale (an eighth of its weight), the words of one
weight's compressed parts widened to u32, and its blocks, reserved once.
The bound now counts those, with the direct reads' alignment, so a load
reads more expert stacks at once in the same room.

Every part's bound also counts the direct buffer's alignment block and the
two-block probe a shard's direct open allocates while that buffer is held;
a small BF16 matrix read whole held twice its bound without them.

The part tests count each thread's allocations, and every part of the fixture
is read within its read bytes; an NVFP4 matrix's bound passes its measured
peak by at most its alignment. The fixture gains a csf stack whose decoded
scales outweigh that alignment.
@github-actions github-actions Bot added the model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja label Oct 28, 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 NVFP4 whole-read bound covers each term the read holds, the stack reserve is correct, and I found no failure path I could not refute.

Non-blocking

⚠ read_bytes grew a second job: crates/model-hf/src/part.rs:261. Complexity went 20 → 41 (crapper). A nested loop with its own accumulators and an early return sit before the general bound. Direction: move lines 261 to 291 into nvfp4_whole_bytes(&self, name, &placed, compressed, whole_nbytes) -> Result<u64, Error>. The branch itself is correct.

⚠ The widened-words term has no fixture that exercises it: crates/model-hf/src/part.rs:284. Mutant: drop words from the final sum (line 290). The fixtures widen about 44 bytes, far below the 4096-byte alignment slack, so read_peaks_cover_the_owned_inputs_and_results stays green. Direction: give one cs expert a csf32_exceptions larger than DIRECT_ALIGN, or say in the PR body that words is unpinned.

⚠ A reserve_exact per expert would pass the new capacity check: crates/hf/src/modelopt.rs:1685. capacity == len also holds if each expert reserves only its own blocks with try_reserve_exact. Only the try_reserve mutant in the PR body turns it red. Low cost to leave; say so if intended.

⚠ The cold-start claim is not shown: PR body table. Cold ranges overlap (base 36.94 to 37.16 s, head 27.42 to 38.04 s); only the warm rows separate. Write the cold gain as "not distinguished from noise in three rounds", or add rounds.

Also 1 minor: (2 * DIRECT_ALIGN) as u64 is written 3 times in read_bytes; one let would name it.

Checked

  • Duplicates: 9 new items checked, none duplicated. The bound reuses file_range, raw, Dtype::size, DIRECT_ALIGN. dryer: 0 pairs.
  • Complexity: read_bytes 20 → 41, a branch added to an existing function (⚠ above). No kernel body changed.
  • Silent failure: 6 sites followed. Each checked product and sum refuses by name; size is never 0 for a stored dtype.
  • Bound: the branch needs ty == NVFP4, so cut or stepped parts keep the general bound. blocks holds exactly whole.nbytes; widened parts are transient per weight, so max is right.
  • Stack reserve: expert i asks for len + per * (n - i), which the first call already holds. A later expert of another shape errors after its append.
  • Tests: the peak test turns red on the three mutants in the PR body. The words mutant stays green (⚠ above). The test allocator's unsafe blocks carry a SAFETY line.
  • Gates: tools/unsafe-ratchet.txt rose for test-only code with a dated PIN. No band moved.
  • Hot path: load time only. Escape catalog: no match.

Notes

  • No just gate-* output in the PR body, so gpu.json has evidence: false.

🔨 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 4be577d into midagedev:main Oct 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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