Skip to content

gguf, engram, model, gpu: Qwen3.8's PLE table in F8_E4M3 rows with one tensor scale, beside IQ4_NL - #490

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-ple-f8
Oct 19, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-ple-f8

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.8의 PLE 테이블을 NVFP4 체크포인트에 들어 있는 F8 형식 그대로 읽어 쓰게 하는 작업이고, 기존 IQ4_NL 경로는 그대로입니다.

What and why

Part of #458, toward this line of its section 7: "Qwen3.8 served from the NVFP4 checkpoint on one DGX Spark, against a pinned reference".

This PR lets Qwen3.8's per-layer embedding (PLE) table come in F8_E4M3 rows with one scale for the whole tensor, beside the IQ4_NL rows the PLE host reads on main. NVIDIA's NVFP4 checkpoint of Qwen3.8-Flash-Next stores the table that way, with the scale as the BF16 0x3951 (about 1.9932e-4). Here the scale sits in the GGUF as per_layer_token_embd.scale, one F32 value beside per_layer_token_embd.weight. Nothing writes a file with the new row type yet; preparing a split from the checkpoint is a later item of #458.

What the PR adds:

  • gguf::F8E4M3_ROWS, a private row type with id 2000: one F8_E4M3 byte a value, and every value is multiplied by the one f32 of <stem>.scale. The id is in bloomery's own range, outside every ggml table. Split::open opens its shards with this type, and the new Split::block sizes it next to ggml's types. The strict Gguf::open still refuses it by the tensor's name.
  • gguf::quant::E4m3Rows decodes such rows through a 256-entry table of e4m3(byte) x scale, built once at load. E4M3 has no value for 0x7F and 0xFF (they are NaN), so a span holding one is refused as QuantError::E4m3Nan with the byte and its index, before any value is written.
  • PleHost in body38.rs picks the decode by the table's type: IQ4_NL rows through dequant_row, F8 rows through E4m3Rows at the table's scale. The scale is read by tensor_scale in weights.rs, which NVFP4 tensors already use and which is now pub(crate), so a missing, multi-value or non-finite scale is refused the same way for both. Row bytes come from Split::block.
  • SplitTable in engram sizes rows through Split::block, so the NVMe tier reads an F8 table as well.
  • The role table of qwen35moe in roles.rs gives per_layer_token_embd.scale the PLE site's layer and Role::Unread. The plan then classifies a file that carries the scale and leaves the scalar in the file, where the load reads it by name.

Existing paths: a GGUF without the private type opens, plans and decodes through the same code as on main. The IQ4_NL arm of the PLE decode is main's loop body inside a match arm. In the existing tests of gguf, engram, model and body38.rs, only the use line of the body38.rs test module changes. No kernel or launch changes, and a file without the table's scale gets the same placement plan as on main.

Release notes: Under the hood: Qwen3.8's PLE host reads its table in F8_E4M3 rows with one tensor scale, beside IQ4_NL rows.

Code shape

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

  • No second copy. The scale rule stays in tensor_scale, row sizing of a private type is Split::block for both SplitTable and PleHost, and the E4M3 decode is E4m3Rows alone, built on the existing ue4m3.
  • Model code holds only architecture facts. body38.rs gains only the choice of decode by the table's type, and roles.rs gains only the role of the table's scale.
  • Dead code is gone.
  • No silent failure. A NaN byte, a short span, a missing or non-finite scale and a table of the wrong width are refused by name.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or ratchet moves, and the PR adds no unsafe.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. cargo fmt is applied on the changed crates; clippy runs in the t0 check below.

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

What I ran

Head f68ba68f7d94b3e5b08faec8341a581ec9662e84, base b5ddb224ee9a4d4146f9ebbf74bedd685e42cfe4. A result from an earlier commit names that commit. Those commits differ from the head as follows:

  • 5e7adf75 is on the same base. From it to the head, only test code in crates/gguf changes (the test module of quant.rs and crates/gguf/tests/fixtures).
  • 24dee325 is on an earlier main, and the main commits between that base and this one touch none of the changed files. From it to the head, the change differs only in test code in crates/gguf and in the model part (the scale's role arm in roles.rs and its test).

The reference for the decode is e4m3_reference() in the tests of quant.rs. It takes the test module's f64 ue4m3, which decodes a byte from the E4M3 definition and which the NVFP4 tests already use. It adds the sign bit and the two NaN bytes, multiplies by the scale and rounds once to f32. That gives 512 entries at the two scales: 508 values and 4 NaN. Each decoded value is compared with its f32 bits:

Check Reference Result
Every byte at scale 1 and at the checkpoint's scale (0x39510000), on the head e4m3_reference() test quant::tests::e4m3_rows_decode_every_byte_to_the_reference ... ok
A split holding the table in F8 rows and its .scale, decoded row by row, at 24dee325 e4m3_reference() test quant::tests::a_split_in_f8_rows_decodes_to_the_reference ... ok

At both scales, 254 of 256 bytes decode to the reference's f32 bits; 0x7F and 0xFF, which the reference leaves as NaN, are refused by name.

The role of the scale ran at 5e7adf75, with cargo test -p bloomery-model --lib an_f8_ple_table_and_its_scale_describe: test arch::qwen35moe::place::tests::an_f8_ple_table_and_its_scale_describe ... ok. The test describes a qwen4exp header with an F8 table and its scale, and finds both on the PLE site. With the scale's arm removed from roles.rs, the same test fails with the file describes: Unclassified { names: ["per_layer_token_embd.scale"] }.

The runs below were made at 24dee325, except the last one:

  • Main with only the new split test added: Split::open refuses a one-shard split whose table is in F8 rows, with UnsupportedType { name: "per_layer_token_embd.weight", ty: Unknown(2000) } and test result: FAILED. 0 passed; 1 failed. With the change, test private_tests::bloomerys_f8_rows_open_through_a_split ... ok.
  • Host tests on a Linux machine, cargo test --release -p bloomery-gguf -p bloomery-decision: the gguf library ends test result: ok. 37 passed; 0 failed and decision ends test result: ok. 52 passed; 0 failed. Every cargo test --release -p bloomery-engram target ends ok with 0 failed.
  • The engram test for the NVMe tier, which needs a disk-backed target directory, with cargo test --release -p bloomery-engram --test engram -- --include-ignored --exact hw_engram_f8_rows_table_reads_rows_of_its_width: test hw_engram_f8_rows_table_reads_rows_of_its_width ... ok.
  • On an RTX 5090 machine with BLOOMERY_ARCH=sm_120, bash tools/gate.sh --oxide -p bloomery-gpu --release --lib: test result: ok. 239 passed; 0 failed; 52 ignored. This includes ple_rows_decode_by_the_tables_type, which checks PleHost over an F8 table against E4m3Rows, over an IQ4_NL table against dequant_row, and the refusal of an F8 table without its scale.
  • On the same machine, BLOOMERY_BOX_LOCAL=1 just gate-gpu-nvfp4: every clause PASS, rc_nvfp4=0. Its tensor_scale refusals are unchanged: want="lone.scale is not in the file" and want="not a finite value" both PASS.
  • On a DGX Spark with BLOOMERY_ARCH=sm_121, bash tools/gate.sh --oxide -p bloomery-gpu --release --lib ple_rows_decode_by_the_tables_type: test arch::qwen3moe::body38::tests::ple_rows_decode_by_the_tables_type ... ok, then test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 290 filtered out.
  • just contrib-check --tier t0 on this head: TBD(t0 /^DONE tier=/)

Not run on a DGX Spark: the full bloomery-gpu library suite and gate-gpu-nvfp4. The change is host code with no kernel, so the GB10 run covers the PLE test alone.

What I ran into

None of this blocks the PR. Nothing outside the change came up in these runs.

Hardware (if the change is for a machine)

The change is for DGX Spark, where #458 serves Qwen3.8. The new code runs on the host and adds no kernel. The GB10 run was on a DGX Spark in the CUDA 13.3.1 container. The GPU library and gate_nvfp4 ran on an RTX 5090 machine, and the host tests on a Linux machine.

AI help

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

…e tensor scale, beside IQ4_NL

gguf: F8E4M3_ROWS is bloomery's own value type (private id 2000, one byte a
value): its values are the F8_E4M3 bytes times the one f32 of <stem>.scale.
Split::open sizes it through bloomery's private table, so a model split may
carry it while the strict opens and ggml's readers still refuse the file;
Split::block answers a block's values and bytes for ggml's types and that
one. quant::E4m3Rows decodes such rows through a 256-entry table built once
from the scale; 0x7F and 0xFF, E4M3's NaNs, are refused with the byte and its
index.

engram: SplitTable sizes a row by Split::block, so the NVMe tier reads an F8
table as it reads a ggml-typed one.

model: qwen35moe's role table gives the PLE table's per_layer_token_embd.scale
the site's layer and Role::Unread, so the plan classifies a file that carries
it and leaves the scalar in the file for the load to read by name.

gpu: Body38's PLE host decodes the rows the hash names by the table's type:
IQ4_NL by dequant_row as before, F8 rows by E4m3Rows at the table's scale,
read by weights' tensor_scale (now also for that type).

The oracle is the existing f64 ue4m3 test reference in quant.rs, signed:
every byte decoded from the E4M3 definition times the scale, at scale 1
and at the checkpoint's BF16 0x3951, rounded once to f32. All 254 bytes
that hold a value decode to its bits, from memory and from a split file;
the PLE host's rows over an F8 and an IQ4_NL fixture equal E4m3Rows and
dequant_row on the rows the hash names.

A qwen4exp header with an F8 table and its scale describes through
PlanInputs::describe_in with both on the PLE site.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset 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 Oct 19, 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 reachable failure or proven quality defect was found in the changed code.

Checked

Duplicates: 16 new function, type and constant definitions checked; none duplicated. Dryer reported no candidate pairs.

Complexity: PleHost::new rises 17 → 23 through type and scale validation; those error paths were traced. roles::role rises 16 → 19 through a scale-name match arm; this is harmless table growth.

Silent failure: 5 sites followed. Three PLE size defaults reach named refusals. Skipped NaN lookup entries are rejected before consumption. Ignored fixture removal affects cleanup only.

Tests: Source mutation audit of all six new tests:

Gates: No existing gate, test, clause, tolerance or pin was relaxed or removed. The body supplies FAIL-first results for split opening and scale classification.

Escape catalog: C1–C4 have no matching changes.

Adversarial checks: Short rows, NaN bytes, malformed scales and incompatible table shapes are refused before PLE upload. Failed decoding leaves committed hash history unchanged. The host decode/prefill path adds no per-token allocation, launch, device copy or synchronization; the lookup table is built at load.

Notes

Repository tests and hardware gates were not run here. An independent arithmetic check matched all 508 finite byte/scale cases at scales 1 and f32 bits 0x39510000.

The reported GPU runs omit the nvidia-smi card/driver line, so GPU evidence is incomplete.

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

@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 host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset 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