Repository navigation
hf: normalize NVFP4 expert stacks from bounded input batches - #981
Merged
juliankang4 merged 2 commits intoOct 29, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Verdict: CLEAN: The changed loading paths preserve the normalization and error contracts.
Checked
- Duplicates: normalization and bounded reads share
Nvfp4Stack; direct-read fallbacks shareCheckpoint::raw. Dryer reported no pairs. - Complexity:
append_plain(24) moves the existingappendbody unchanged.Checkpoint::read(34 → 37) adds the streaming branch.Config::declared(18 → 20) replaces the prefix scan with ancestor traversal. No complexity finding. - Silent failure: missing tensors, malformed scales and byte-count overflow retain named errors. Unsupported direct reads use the mapping.
- Tests, static mutation check: removing the extra-expert refusal at crates/hf/src/modelopt.rs:710 makes the new
unwrap_errfail. Removing ancestor traversal at crates/hf/src/quant_config.rs:434 fails the descendant lookup assertions. - Tests, memory mutations: changing
>to>=at crates/model-hf/src/part.rs:209 fails the exact-limit assertion. Dropping decoded-scale scratch at crates/model-hf/src/part.rs:380 fails the measured-peak bound. Replacing the maximum with the last batch at crates/model-hf/src/part.rs:383 fails the three-expert case. Other test edits adapt fixtures or comments. - Gates: no tolerance, pin, lint level or existing assertion was relaxed or removed. The PR supplies FAIL-first output for the scratch bound.
- Escape catalog: no C1–C4 pattern matched.
- Adversarial checks: oversized single experts, missing or mismatched experts, invalid compressed scales and unsupported direct reads have explicit paths. Ancestor traversal checks complete module prefixes; batch ranges preserve source order.
Notes
Rust suites were not executed in this source-only review. The PR includes load checks, but no nvidia-smi line or just gate-* output; GPU evidence is false.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Collaborator
Author
|
The review is done and the contribution check passed, so I'm merging this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Qwen3.8 폴더 로드에서 ModelOpt 선언 조회와 NVFP4 expert stack 정규화를 고쳐 최대 host 메모리를 26.23%와 27.58% 줄였습니다.
What and why
Loading an NVIDIA ModelOpt checkpoint folder did two wasteful things on the host. Every weight was checked against all 545 (or 50) quant declarations, and NVFP4 expert stacks were normalized with the whole input held at once next to the result.
This PR indexes the declarations in a
BTreeMapand looks up the module and its dot-separated ancestors, so the longest complete module prefix still wins. It also reserves the stack result once and reads the inputs in batches of at most 32 MiB (a single expert larger than that is read whole), releasing the CSF scale of each expert after use.read_bytesnow counts the input batch, the current expert's scratch and the result stack. The direct-read and mapping paths shareCheckpoint::raw.The measured gain is host memory, not time: the two real folders load with identical resident bytes and identical output, and peak host RSS drops by 26.23% and 27.58%. This PR claims no start-up speedup.
Release notes: Under the hood: lower peak host memory when loading ModelOpt NVFP4 checkpoint folders.
Code shape
The review reads these first. A box left unticked needs one line of why.
copying it (
AGENTS.md"Common code first",docs/rust-quality.mdR14). Where I found an existing copy, Inamed it below.
(tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
tools/check-comments.sh).PIN(YYYY-MM-DD):and its reason.
cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none":crates/model-hf/src/part.rs:223 ~ crates/model-hf/src/part.rs:408reused. The two direct-read lookups now go throughCheckpoint::raw.What I ran
Real folder load on a DGX Spark GB10 (NVIDIA GB10, driver 595.84), base
4c549a477835d471929aa3c04718062488864d3bagainst head5a771d7ed191ec33ab9900ea93ad67fb618df617. Base and head were built into separate target directories and each arm ran once, FP4-Local first, then NVFP4:Folders:
nvidia/Qwen3.8-Flash-Next-FP4-Localatb9ce18a6887e18c089fdea8509a33e63429a3300andnvidia/Qwen3.8-Flash-Next-NVFP4atfc694b54fb0174e0913e6adf86691ef85a4ead47. Peak host RSS is the server processwait4rusage, including one short completion and shutdown. Start to health is process spawn to the first HTTP 200 on/health.Each arm ran once, so no timing difference is claimed.
All four arms completed
The capital of France is(n_predict=8 temperature=0 seed=42) with the same text,Paris. The capital of Germany is Berlin.Host unit tests for the changed code, on macOS:
The new scratch bound was written to fail first: with the assertion added to base,
cf.weight: 2504732 > one expert's scale bound 2439196andFAIL-FIRST PASS: base exceeds one expert scale scratch; on the head it passes.cargo fmt --allis clean andgit diff --checkpasses.Hardware (if the change is for a machine)
Card: NVIDIA GB10, 595.84, built with
--arch sm_121a --release.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.