Skip to content

hf, model-hf: an FP8 or unquantized stack normalizes from bounded input batches into one output reserved at its length, as an NVFP4 stack does - #1101

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-cmn-load-bounded
Nov 1, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-cmn-load-bounded

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

FP8과 비양자화(BF16, F32) expert stack도 NVFP4 stack처럼 입력을 batch로 나눠 읽고 출력을 한 번만 잡게 하고, load 기록에 읽기 시간과 메모리 최대치를 더한 PR입니다.

What and why

Only an NVFP4 stack of expert tensors was read in bounded batches and accumulated into one output reserved up front. An FP8 or unquantized (BF16 or F32) stack held its whole input and grew its output as it went. This PR moves that rule into one shared hf::modelopt::Stack that every stack format uses. Input is read in bounded batches, and the output is reserved once at its final length. The folder Checkpoint in crates/model-hf/src/part.rs reads every tensor this writer handles that way. A single FP8 tensor goes through the same Stack, so its planned read peak is counted once instead of three times.

The load phases record gains three optional fields: read_s (wall time of the part reads), read_peak (the planned host peak of those reads) and rss_peak (the process's peak resident set). The checked-in record schemas are updated.

Release notes: Under the hood: FP8 and unquantized expert stacks load from bounded input batches into one output reserved at its length, and the load record reports read time and peak memory.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": Nvfp4Stack, Nvfp4, nvfp4(), fp8() and plain_stack() in crates/hf/src/modelopt.rs are replaced by the one Stack. A single plain tensor and a plain stack write through the same plain_values. The per-format scratch accounting that part.rs kept for the read peak now comes from Stack::scratch.

What I ran

The upstream base is 39ed53b875a0811cdaf587dd19963da24a650c48 and the PR head is f551c541f85a2c7342c54ad5f0a5690f85945d31.

Card and driver (raw output):

$ nvidia-smi
Sun Nov  1 20:14:46 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |
| N/A   47C    P8              4W /  N/A  | Not Supported          |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+
$ nvidia-smi --query-gpu=name,driver_version --format=csv,noheader
NVIDIA GB10, 595.84

Model: nvidia/Qwen3.8-Flash-Next-FP4-Local, revision b9ce18a6887e18c089fdea8509a33e63429a3300. SHA-256 of each file:

README.md                                   b0ad2a8a314ca96618e21e40d50c0af6e181e6060f9cdd1996c7074d19284c1a
chat_template.jinja                         c3cf9e34abf4f9e36c2d72165aa9c132d3e2a725b6c2586aaa3a8af9d7a81041
config.json                                 b50dbc52a0c83b0cd2a44a372c1fb6b5e0e6827d22f2611c97d4d030f92f6b28
generation_config.json                      e70c136c1b78ddc1fb0905bac8e733a4dc448d4f852a5dd75143fffc70be550e
merges.txt                                  a9d356d7bdf1ef4949e3e748e95b8e10ad9d4e2e838eddc38a0a7b6b94d1db8d
model.safetensors.index.json                5fa166bbb1cf25adda455117563efa72a2072272001f459eedece131ffc913e1
preprocessor_config.json                    27225450ac9c6529872ee1924fcb0962ff5634834f817040f444118116f4e516
tensors/model-00001-of-00021.safetensors    ebf3648c5f4cd1f24e79789e7803498dc4e74cb52515cc515b2d22cf8161953b
tensors/model-00002-of-00021.safetensors    79a643fc5c024089cecd32ca27dc43e671cbec70ff3628b728909b7656ac43ec
tensors/model-00003-of-00021.safetensors    c45f942203db4c7f5a1071700b93b908495cc790271acddfff39091c2b953923
tensors/model-00004-of-00021.safetensors    071ab9cf963ca0f1a6a194b4cec485f5de18ef9804da915b2e6abd0eb0c707af
tensors/model-00005-of-00021.safetensors    f80d17870eb1d36917257494770984953476583c57737f61fdbd341c957b9715
tensors/model-00006-of-00021.safetensors    3e9183d4ebb267fa92429184d5132d302cb1a98fd049149e5d01dccd4ca65795
tensors/model-00007-of-00021.safetensors    aa1ad959c4d62e0bc4600fd0b57cc2939b463e9fb53dc01020e188552b52ce5a
tensors/model-00008-of-00021.safetensors    0b18844027be74b84b240f23bf3a744bc29b35de0bd384f41c40cd85e6339326
tensors/model-00009-of-00021.safetensors    2d0b6c66790c17f8b1fdcf442f541778c8f0a381aca26c11b9d7cfcf7c96f2f0
tensors/model-00010-of-00021.safetensors    3ed9bd73745aebf6dc136f437b67d6b9fc3d38d25ad84300b399164bc87a72b7
tensors/model-00011-of-00021.safetensors    4936ff28c6cc8b66653ddb9cae28bc284569a1a2f7116819a017dc1a0e517ed8
tensors/model-00012-of-00021.safetensors    dd7df5a6ff73e9960412243f744eab9ec35f4be40da5bb158dc4ba8796b33742
tensors/model-00013-of-00021.safetensors    28a455c8ea4ebaa847fb4cbed2bc1de9eff0b501dd3f848a3a3cfc38778e8500
tensors/model-00014-of-00021.safetensors    6941676e685abf9817d9c48a17fdeda20b2b72d16217555252aa4c602b7f98b8
tensors/model-00015-of-00021.safetensors    2a1129b5acfc24a45bf402aa63dcef08b531aedfdaf5233c65fd3d12dc303fdd
tensors/model-00016-of-00021.safetensors    635e97fbad78fa988647d407e2b58e55d551ef94d798c9b6fb5550de25e86429
tensors/model-00017-of-00021.safetensors    bf60d564d89a805b67f8be5f2847a1b1567a70dbc23d19754395c127568474ad
tensors/model-00018-of-00021.safetensors    c5bde22f9364e82eb25973456795592fdcb4b158bc2095898979a2566bf4c562
tensors/model-00019-of-00021.safetensors    da3dc3b4f428f5b9dd53362691043d0242f48d03adca9b7b553bd9f3a1e96350
tensors/model-00020-of-00021.safetensors    4978bb6b8480cfc02d3c8bc84ba86202889f5f10d090bb17c21fee663cea7683
tensors/model-00021-of-00021.safetensors    48203838f2c76921bddbf1cc51d20a23858c128821a21add55fa1778e5e25283
tokenizer.json                              0997f410c57a1f4e53b09e4be8f4a172d90edd9564368fb0847030937229b9f3
tokenizer_config.json                       b11349aafa7cdc6a320767cf7ceb29ed82f7eda5d65e8e0819e76f0ce947bf27
video_preprocessor_config.json              7768af27c1fafa9cc9011c1dc20067e03f8915e03b63504550e11d5066986d13
vocab.json                                  ce99b4cb2983d118806ce0a8b777a35b093e2000a503ebde25853284c9dfa003

Build the PR head and start bloomery-serve on the model above. The server prints its load record when the model is up:

(cd head && cargo oxide build --arch "$(bash tools/arch.sh)" -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve)
env BLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G ./head/target/release/bloomery-serve -m "${MODEL_FP4L}" --host 127.0.0.1 --port 18731 --parallel 1 --ctx-size 16896
load phases open_s=0.28 context_s=0.02 upload_s=16.66 derive_s=0.01 host_set_s=0.00 body_s=0.37 head_s=0.00 other_s=0.09 read_s=16.36 read_peak=12857090252 rss_peak=11030953984

GB10 gates for the changed gpu parts code:

bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- parts::
running 11 tests
test parts::tests::parts_stage_in_order_as_their_reads_arrive ... ok
test result: ok. 9 passed; 0 failed; 2 ignored; 0 measured; 472 filtered out; finished in 0.20s
bash tools/gate.sh --gpu --oxide -p bloomery-gpu --release --lib -- parts::tests::hw_ --ignored
running 2 tests
test parts::tests::hw_a_parts_load_refuses_a_short_host_before_reading ... ok
test parts::tests::hw_a_parts_load_releases_its_parts_only_under_release ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 481 filtered out; finished in 20.53s

The clippy ratchet on the PR head (cargo clippy --workspace --all-targets with the workspace feature set):

chain-clippy: lint rc 0 (^warning: 0, the ratchet 0 in tools/lint-ratchet.txt)

Hardware (if the change is for a machine)

GPU Driver CUDA
NVIDIA GB10 595.84 13.3

AI help

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

…ost peak, and every load the process's peak resident set
…ut batches into one output reserved at its length, as an NVFP4 stack does
@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 Nov 1, 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 was proved in the changed code.

Non-blocking

⚠ Validate the reviewed revision: crates/model-hf/src/part.rs:1775.
The body names base 39ed53b8 and head f551c541; this review has base d748b6e0 and head 16876378. Attach gate output tied to this head and the hf/model-hf test commands and output, including the FP8 and BF16 batch cases.

Checked

Duplicates: 12 new or renamed items checked; no actionable duplicate. Dryer reported 0 pairs. GPU owners were searched manually. The byte append avoids the temporary value vector that safetensors::f32_values returns.
Complexity: crapper flagged no function. The added format arms select writers; no kernel body changed.
Silent failure: 5 fallback/error sites followed. Unsupported stack writers use the normal reader; malformed input returns a named error. An empty read plan reports zero duration. An RSS error omits the optional field.
Tests: static mutation audit, test line → production line and mutant below; each is caught by an assertion or test failure by inspection.

  • crates/gpu/src/parts.rs: 858 → 261, return zero read duration; 1121 → 243, skip release.
  • crates/hf/src/modelopt.rs: 1865 → 1554, swap packed nibbles; 1884 → 1559, drop an expert scale; 1951 → 1381, swap BF16 bytes; 2330 → 1156, use the wrong scale index; 3219 → 1493, apply the input scale; 3252 → 756, drop the shape guard.
  • crates/model-hf/src/part.rs: 1421 → 266, reverse expert order; 1523 → 644, retain every shard handle (direct reads supported); 1668 → 264, read all experts in one batch.

Gates: no pin, tolerance or gate was relaxed or removed.
Escape catalog: no C1–C4 pattern matched.
Adversarial checks: non-finite values, mismatched shapes, out-of-order read completion and an expert larger than the batch limit are handled by existing checks or the single-source batch rule. Changes affect loading; no decode or prefill cost changed.

Notes

Rust and GPU tests were not executed here. Independent arithmetic checks covered finite BF16 widening, final-length reservations and read-span aggregation. GPU evidence is marked unverified because the supplied commit hashes differ from the reviewed revisions.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/record.rs, crates/gpu/src/arch/qwen3moe/mtp38.rs, crates/gpu/src/host/node.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.

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