Repository navigation
model-hf: an NVFP4 matrix read whole bounds its read by what the read holds - #923
Conversation
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.
There was a problem hiding this comment.
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_bytes20 → 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;
sizeis never 0 for a stored dtype. - Bound: the branch needs
ty == NVFP4, so cut or stepped parts keep the general bound.blocksholds exactlywhole.nbytes; widened parts are transient per weight, somaxis right. - Stack reserve: expert
iasks forlen + per * (n - i), which the first call already holds. A later expert of another shape errors after itsappend. - Tests: the peak test turns red on the three mutants in the PR body. The
wordsmutant stays green (⚠ above). The test allocator'sunsafeblocks carry aSAFETYline. - Gates:
tools/unsafe-ratchet.txtrose 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, sogpu.jsonhasevidence: false.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
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_bytescounted several times what the read holds, so a load ofnvidia/Qwen3.8-Flash-Next-FP4-Localread 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 ofDirectFile::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.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.txtmovesmodel-hffrom 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
Folder::file_range,Folder::raw,Dtype::sizeandDIRECT_ALIGN.cargo fmtandcargo clippyare clean on what I touched.Duplication found or removed (
path:line), or "none": none.What I ran
Start time on one DGX Spark, base
49d84ecc10a7and head53a0a338a43f, each built withjust release-build 0.3.10and installed withtools/release/install.sh --version v0.3.10 --prefix <dir>. Modelnvidia/Qwen3.8-Flash-Next-FP4-Localatb9ce18a6887e18c089fdea8509a33e63429a3300,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.Median of three starts, range in parentheses.
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:
cf.weight: 2373660 < 2434960.cf.weight: 8415304 passes 2434960 by more than 77824.bf.weight: 14344 < 21155.a_routed_stack_keeps_one_scale_an_expert.Not run:
just gate-gpu-liband the tests that need an RTX 5090 machine, which run on the maintainers' workstation.Hardware
One DGX Spark, Linux aarch64.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.