Skip to content

hf, model: prepare reads Qwen3.8-Flash-Next-FP4-Local, its compressed expert scales decoded, its PLE table in NVFP4 rows and its MXFP8 weights as stored - #543

Merged
juliankang4 merged 4 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-fp4local-prepare
Oct 20, 2026

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

NVIDIA의 Qwen3.8 FP4-Local 체크포인트를 prepare가 읽도록 하고, MXFP8 가중치는 값을 바꾸지 않고 MXFP8 블록으로 옮기는 작업입니다.

What and why

Part of #493, toward #458's "Qwen3.8-Flash-Next-FP4-Local served on one DGX Spark". It belongs to the shared format layer of #495 and does not touch the host types of the open IQ1_S round.

prepare could not read nvidia/Qwen3.8-Flash-Next-FP4-Local end to end. The checkpoint stores each routed expert's NVFP4 block scales compressed (weight_scale_encoding csf, and csf_32x2_v1 in its sibling GLM checkpoint), the PLE table as NVFP4 parts of 160-value rows with one shared tensor scale, attention and the shared experts in MXFP8, and the rest in BF16. After this PR every one of its 1,224 mapped tensors gets a GGUF type, and the MXFP8 tensors keep their bytes. The PR adds table lines to the ModelOpt prepare path:

  • hf::csf reads the two compressed encodings back as the plain weight_scale bytes and refuses each structural rule of the encoders' published decoders by name.
  • normalize decodes csf and csf_32x2_v1 scales first and then repacks as NVFP4 does. NVFP4 read as a row table becomes gguf::NVFP4_ROWS (from the PLE row PR): each 16-value group is its scale byte then its code bytes, and the tensor scale is the shared weight_scale_2.
  • normalize refuses a row table whose tensor lists anything but exactly one source, and names the tensor.
  • normalize writes an MXFP8 matrix (F8_E4M3 values, one U8 E8M0 scale per 32 values along k) as GgmlType::MXFP8 blocks byte for byte, with no requantization. It reuses check_mxfp8 for each row.
  • prepare --keep-bf16 writes a BF16 matrix as stored instead of Q8_0.

Inputs that would overflow or exceed a size are refused by name instead of read:

  • Nvfp4Rows::decode refuses any non-finite scaled value (a code times its group scale times the tensor scale) before it writes the destination. modelopt::nvfp4_rows calls this one decoder for every stored group, so there is no second validator, and the error names the scale tensor, the row and the group.
  • Row width, weight and scale byte counts, packed row bytes, the MXFP8 combined byte count, compressed scale element counts and the compressed decoders' slab, tile, block and offset counts use checked arithmetic. Zero rows are refused too.
  • --shard-gib values whose byte count does not fit in u64 are refused, for example 17179869185. The refusal table is the one already on main, and a_shard_size_out_of_range_is_refused covers it.
  • The test fixture writer for compressed scales is the existing modelopt_nvfp4.write, not a copy.

Release notes: New: prepare reads NVIDIA's FP4-Local checkpoint of Qwen3.8-Flash-Next, and its MXFP8 weights keep their stored values.

Code shape

  • No second copy. The compressed scales feed the existing linear and experts. The row type is the PLE row PR's, and the product check lives in the one existing row decoder.
  • Model code holds only architecture facts. The Qwen3.8 map does not change. The new lines are format lines of the table.
  • Dead code is gone.
  • No silent failure. Every refusal names the tensor, and size products are checked.
  • Comments state what is true now.
  • No relaxed gate.
  • cargo fmt and cargo clippy -D warnings are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": the compressed-scale fixture writer is removed in favor of crates/hf/tests/fixtures/modelopt_nvfp4.py's write.

What I ran

Head ac72792857c7e30bc8cc97a9e1d63f2cc2774c07, base 654f1b0e. The branch sits on upstream's move of the checkpoint map and the prepare binary into bloomery-model-hf, so this PR's changes are in crates/model-hf/src/arch/qwen35moe.rs and crates/model-hf/src/bin/prepare.rs. The bloomery-hf result below ran on this head. The other test results ran on the earlier head ef1fdafd; the later commits changed only the fixture generator, the row-table guard and the rebase.

The reference for the MXFP8 check is the OCP MX rule computed independently from the raw checkpoint bytes: E4M3 value times 2^(E8M0 scale - 127) in f64, rounded once to f32. The two tensors were read from nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300 by HTTP range requests.

Check Reference Result
Layer 0 in_proj_a, 122,880 values, dequantized from the split MXFP8 blocks OCP MX rule, f64 0 differing bits
Layer 3 k_proj, 1,310,720 values, dequantized from the split MXFP8 blocks OCP MX rule, f64 0 differing bits

The two tensors together are 1,433,600 values. This check ran on 38d228b4; the later fixes on this branch change only the NVFP4 row checks, size arithmetic and test fixtures.

  • Header typing of the FP4-Local folder: MAP-OK ... mapped=1224 with_gguf_type=1224 untyped=0. Of these, 396 are MXFP8: 300 with the Q8_0 role, 72 with the F32 role and 24 with the BF16 role.
  • The split plan for the folder is 2 shards, 102,117,585,696 bytes in total (95.104 GiB). The next step is serving FP4-Local on one DGX Spark.
  • On a Linux machine, cargo test --release --locked -p bloomery-hf: test result: ok. 88 passed; 0 failed. It includes compressed_scales_and_row_tables_take_their_lines, a_compressed_scale_breaking_a_rule_is_refused_by_name and a_row_table_of_two_sources_is_refused. Replacing the guard with a read of the first source only makes the last one fail.
  • cargo test --release --locked -p bloomery-gguf --lib: test result: ok. 41 passed; 0 failed. It includes nvfp4_rows_refuse_by_name.
  • cargo test --release --locked -p bloomery-model-hf --bin prepare: test result: ok. 3 passed; 0 failed; 1 ignored. It includes a_shard_size_out_of_range_is_refused.
  • cargo test --release --locked -p bloomery-model --lib qwen35moe: test result: ok. 99 passed; 0 failed.
  • On an RTX 5090 machine (driver 595.99.02, compute capability 12.0), cargo oxide test --arch sm_120 -- -p bloomery-gpu --release --lib -- ple_rows_decode_by_the_tables_type an_mxfp8_site_reads_the_f32_rows_and_is_a_gemv: test result: ok. 2 passed; 0 failed.
  • cargo fmt --all -- --check and cargo clippy --release --locked --all-targets -p bloomery-hf -p bloomery-tokenizer -p bloomery-gguf -p bloomery-placement -p bloomery-model -- -D warnings pass on the same machine.

Failing first:

  • Before the finite-product check, an NVFP4 row table whose scaled values overflow was accepted: called \Result::unwrap_err()` on an `Ok` value: Normal { type_id: 2002, dims: [160, 2], ...`. With the check, the same input is refused.
  • With the original unchecked compressed-scale arithmetic, the same synthetic input panics: capacity overflow.
  • Disabling each of six checks in turn (the decoder's product check, the caller's row check, the row-size check, the weight-size check, the row-capacity check and the checked compressed-scale arithmetic) fails its test. The run ends with FAIL-FIRST: PASS.

The two CSF32 blocks of crates/hf/tests/fixtures/csf_scales.py are now one loop. Regenerating csf-scales.safetensors gives sha256 214330ee31bda945074a4967cc54d696a6b0bc53c84c52daa674319d9f07b055, the same as the committed file.

GPU evidence

On a DGX Spark (GB10), just gate-gpu-nvfp4 passed with exit code 0 in 9 s, and all 40 clause lines pass:

NVIDIA GB10, driver 595.84, CUDA 13.3
just gate-gpu-nvfp4
gate_nvfp4 ran 9 s (exit 0)

It ran on 48554e24d605dcb4ed2746f869f405d521133888. Later rebases changed no GPU file of this PR.

The gate loads synthetic NVFP4 tensors with their scales through Weights::load_where, so it covers the NVFP4 row scale read in weights.rs. The PLE decode in body38.rs is covered by the unit test ple_rows_decode_by_the_tables_type.

just gate-gpu-qwen4exp-e2e could not run on this card: the gate refused with the visible card NVIDIA GB10 is none of this workstation's cards (A6000, 3090).

What I ran into

None of this blocks the PR.

Hardware (if the change is for a machine)

The change is for DGX Spark. prepare is host-only Rust, and the RTX 5090 run covers the GPU tests that read these types.

AI help

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

@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 placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 20, 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: MUST_FIX: The fixture generator duplicates the CSF32 part schema.

Must fix

1. Generate both CSF32 fixtures through one loop

crates/hf/tests/fixtures/csf_scales.py:142 and crates/hf/tests/fixtures/csf_scales.py:147 repeat the same five part names, dtypes, byte widths and serialization. This is one format fact with two owners (kind B; R14).
One loop removes the obligation to update both copies when the fixture format changes. Replace the two generation blocks at lines 139–148 with:

    for stem, rows, cols in (("syn_csf32", 384, 43), ("syn_csf32k", 64, 8)):
        m = scales(rng, rows, cols)
        parts = csf32(m)
        tensors.append((f"{stem}.weight_scale", "F8_E4M3", [rows, cols], bytes(v for r in m for v in r)))
        for part, dtype, size, raw in zip(("bases", "codes", "page_bases", "offsets", "exceptions"), ("U8", "U8", "U32", "U16", "U16"), (1, 1, 4, 2, 2), parts):
            tensors.append((f"{stem}.weight_scale.csf32_{part}", dtype, [len(raw) // size], raw))

Checked

Both cited loops are added by the diff and contain the identical schema. The replacement reduces ten lines to six without adding a helper. It parses, produces the same 12 tensor records, and preserves the random generator state.
This is a full review; the PR is neither a revert nor a no-merge mirror. No ledger lessons apply. Escape catalog C1–C4 do not match the finding.

Notes

Rust and GPU tests were not rerun during validation. The PR body lacks the nvidia-smi line and just gate-* output required for GPU evidence.

Card check: needs-gpu. This pull request changes crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/site.rs, crates/gpu/src/weights.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)

…ups with one tensor scale, beside IQ4_NL and F8

gguf: GgmlType::NVFP4_ROWS (2002) is bloomery's own value type beside the F8
rows and MXFP8, with its row in qtype::OWN_ROWS: a group of 16 values in 9
bytes, its UE4M3 scale byte then its 8 code bytes in ModelOpt's order (value
2i in the low nibble of byte i, 2i + 1 in the high), its values e2m1 x scale
x the one f32 of <stem>.scale. A row of any multiple of 16 values is whole
groups; GGUF's NVFP4 block needs 64, and the FP4-Local checkpoint's PLE rows
are 160 values (2.5 blocks). Every exhaustive table over GgmlType decides it
(dequant_row refuses it, as it does the F8 rows, since it has no tensor
scale; no card format or kernel entry takes it), and a split opens it as it
opens the other own types. quant::Nvfp4Rows decodes such rows: the group's
product e2m1 x scale is exact, so the tensor scale is the one rounding. A
scale byte with bit 7 set or 0x7F is refused naming its group and the byte
before any value is written. GgmlType::reads_scale names the types read with
a <stem>.scale (NVFP4 and the F8 and NVFP4 rows), the one list the writer
and the loader ask.

gpu: Body38's PLE host takes the type as a third arm beside IQ4_NL and the
F8 rows, its scale read by weights' tensor_scale, which asks reads_scale.

The oracle is the ModelOpt rule computed from the checkpoint's own layout
(codes [rows, k/2], one E4M3 scale a 16 values, the tensor scale), from the
f64 e2m1 and UE4M3 test references: every scale byte that is a scale with
every code at every place of its group, at scale 1 and at the table's
weight_scale_2, and the first four rows of PLE parts 0 and 101 of
nvidia/Qwen3.8-Flash-Next-FP4-Local b9ce18a6 (range-read), decode to the
reference's f32 bits. The PLE host's rows over an NVFP4-row fixture equal
Nvfp4Rows on the rows the hash names, and a table without its scale is
refused by name, as for the F8 rows.
… as the plain weight_scale

FP4-Local checkpoints store each routed expert's NVFP4 block scales in one
of two encodings that weight_scale_encoding names: a row's base byte plus a
4-bit code, with the bytes the 16-wide window misses stored apart. hf::csf
reads either back as the R x C F8_E4M3 bytes a plain checkpoint stores, by
the rules of the encoders' published decoders (FlashInfer's _csf_blocks.py,
vLLM's csf_scales.py), and refuses by name every part a rule does not allow.

The fixture holds the real csf scales of layer 0 expert 0 gate_proj of
nvidia/Qwen3.8-Flash-Next-FP4-Local, which decode to the sha256 of the plain
weight_scale of the same weights in local-inference-lab's NVFP4 copy, and
seeded csf and csf_32x2_v1 scales beside the bytes they encode;
csf_scales.py regenerates it.
… PLE table in NVFP4 rows

The table gains the lines nvidia/Qwen3.8-Flash-Next-FP4-Local needs:

- NVFP4 with csf or csf_32x2_v1 scales: each weight's block scale is
  decoded (hf::csf) from the parts its place names, and the weight repacks
  as plain NVFP4 does, a linear or a routed stack, with the tensor scale
  its own place names.
- NVFP4 read as a row table: GgmlType::NVFP4_ROWS, each 16-value group its
  scale byte then its 8 code bytes as stored, the tensor scale the one its
  place names; a scale byte that is no UE4M3 scale is refused by row and
  group, and a tensor scale that is not finite by name.

prepare sizes and writes a .scale tensor from the type
(GgmlType::reads_scale) rather than from the format, and each type's row
sizes the tensor. prepare --keep-bf16 writes a BF16 matrix the map would
make Q8_0 as stored.

A normalized stack of two real ModelOpt experts, written as a split, opens
through Split::open and decodes by dequant_row to the ModelOpt rule's rows:
the path existing GGUF files take is unchanged.
…FP8 block as stored

nvidia/Qwen3.8-Flash-Next-FP4-Local stores its full and linear attention,
shared experts and indexer as MXFP8: F8_E4M3 values with a U8 E8M0
weight_scale, one byte a 32 values along k. The table writes such a
weight as GgmlType::MXFP8 whatever plain type its role names: each row's
blocks in order, each its scale byte then its 32 value bytes, so no value
changes and splitting the blocks gives back the checkpoint's bytes. Every
row is checked by gguf::quant::check_mxfp8 (E8M0 and E4M3 NaN, a product
past f32) and refused naming its row; a stack, a weight that is not whole
32-value blocks and a scale of the wrong shape are refused by name.

The MXFP8 row sizes the tensor in the shard plan (33 bytes a 32 values),
and it reads no .scale. The V-head moves take whole MXFP8 blocks, as the
row's block size already bounds them.
@juliankang4
juliankang4 force-pushed the dgx-spark-q38-fp4local-prepare branch from eace666 to ac72792 Compare October 20, 2026 10:25

@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 behavior or proven quality defect survived the input and consumer checks.

Checked

Duplicates: 48 new items checked; all five dryer pairs read. They use different error types or dispatch contracts. No duplicate warrants extraction.

Complexity: csf32 (29): validation/page walk/block decoding. nvfp4_rows (21): validation/packing. plain (23): moved code. PleHost::new (25) and prepare::run (63): format/CLI branches. as_u32/from_u32: harmless match arms.

Silent failure: four sites followed. Scale guards block invalid lookup entries; safetensors validation blocks partial words; missing PLE scales and unsupported format/role pairs return errors.

Tests: Static mutation review of new and changed tests:

Fixture assertions cover all four compressed inputs. Rust and GPU suites were not rerun during validation.

Gates: Replaced unsupported-pair cases carry PIN(2026-10-20) and supported-path tests. No tolerance was relaxed.

Escape catalog: C1–C4 have no matching changes.

Card check: gpu-evidence. This pull request changes crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/site.rs, crates/gpu/src/weights.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 20, 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 7c7a3e9 into midagedev:main Oct 20, 2026
6 checks passed
@midagedev

Copy link
Copy Markdown
Owner

화이팅이요!!

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 gpu-evidence Verified on the author's card: the pull request carries the gate run and its output model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants