Skip to content

Nemotron on HIP: admit and load a bf16 token table beside quantized matrices - #3575

Merged
ashhart merged 14 commits into
ashhart:mainfrom
gilby:strix/n4-nemotron-bf16-embedding
Nov 19, 2026
Merged

ashhart merged 14 commits into
ashhart:mainfrom
gilby:strix/n4-nemotron-bf16-embedding

Conversation

@gilby

@gilby gilby commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Nemotron 3.5 Lightning checkpoints can leave backbone.embeddings unquantized in BF16 (either "backbone.embeddings": false in config.json or omitted from quantization alongside BF16 weights with no .scales/.biases), as mixed-precision exports do when keeping embeddings in 16-bit while quantizing the 52 layers' projections and routed experts. Before this, HIP config.parse, admission and load.zig refused any Nemotron checkpoint without MLX affine scales/biases on backbone.embeddings.

With this change (follow-on to #3242, as noted in #3061):

  • config.Config.readWith(gpa, io, dir, allow) and config.parseWith(..., .{ .bf16_embed = true }) admit "backbone.embeddings": false while keeping config.Config.read / config.parse strict for non-HIP callers (config_test.zig); engine.zig calls config.Config.readWith when opened without pre-admitted config.

  • tensors.hasBf16Embed defines the shared scale-less BF16 token-table rule once. admit.zig, plan.zig and widths.zig admit "backbone.embeddings": false or scale-less backbone.embeddings shards, count [vocab, hidden] 2 * vocab * hidden bytes at stored BF16 precision across --tp ranks, label the startup line +bf16-embed (e.g. mlx-q4g64+q5g64+q6g64+q8g64+bf16-embed), and still refuse every other unquantized or unsupported tensor by name.

  • native.zig passes .cfg = v.config to engine.Engine.load, and engine.zig passes admitted = (o.cfg != null) into load.loadInto so hasBf16Embed runs once when opening via admit (and once in loadInto only when opened without admit), keeping e.cfg.embed_bf16 single-sourced and readEmbed reading only c.embed_bf16.

  • embedding.zig (read and device gather, sharing core.quant.dense.readStored so weights stay un-widened BF16 on device) loads and gathers [vocab, hidden] BF16 token tables across --tp 1..8; prompt lookup embedRows in zig/src/hip/kernels/ and zig/src/families/nemotron/hip/forward.zig already dispatches BF16 dense vs MLX affine embeddings from Tensor metadata.

  • Issue: Refs Nemotron on HIP: read oQ mixed-width MLX checkpoints (4, 5, 6 and 8 bits, a width per tensor) #3061.

  • Stacked on: Nemotron on HIP: read each matrix at its own oQ width (part 2 of 3) #3242 (be9fe6237).

  • Published BF16-embedding checkpoint: https://huggingface.co/unigilby/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-bf16embed-HIP (revision 928dc0b670dd4b9002991c136ecf0833e37b475c, genuine BF16 backbone.embeddings.weight [131072, 2688] from nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16@a9904d24bcc1d289a1950fa9d2b978c47cf903b9 with "backbone.embeddings": false beside the mixed-width unigilby/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-HIP layers and mtp-4bit.safetensors).

Checks on this head

  • Head commit: 94e51ba9b (583e09fa6 code + 94e51ba9b changelog stamp for Nemotron on HIP: admit and load a bf16 token table beside quantized matrices #3575, binary sha256 ab0ec182396a...), stacked linearly on #3242 be9fe6237 (binary sha256 b119d289c8cc...).
  • Lean checker, python3 tools/zig/lean_check.py: 341 on be9fe6237 and 341 on 94e51ba9b, 0 new findings; zig/src/families/nemotron/config.zig is 598 lines.
  • python3 tools/pr_check.py --base be9fe6237 --pr 3575: 0 errors, 0 warnings. git fmt --check zig/ and git diff --check be9fe6237..HEAD clean.
  • Host tests (94e51ba9b):
    • macOS (zig build -Dhip=true hip-host-test check-native-hip-host test-native-hip-host --summary all): 18 of 18 steps succeeded; zig test zig/src/families/nemotron/config.zig: 12 passed, 1 skipped (Bolt local checkpoint absent), 0 failed.
    • Linux Ubuntu HIP CI (zig build -Dfixed-cpu -Dhip=true test-host-ci-linux-hip --summary all): 100 of 100 steps succeeded; 296 of 298 tests passed (2 skipped), 0 failed (test-native-hip-host 26/26).
  • GPU device / kernel checks on Strix Halo (gfx1151, 94e51ba9b):
    • zig build hip-kernel-test: 20 of 20 steps succeeded; 216 of 222 tests passed (6 skipped), 0 failed.
    • tf-nemotron-hip-test load on published unigilby/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-bf16embed-HIP, an unlisted-config copy (with "backbone.embeddings": false omitted), Lightning-oQ4e-user3892r4, and Lightning-30B-A3B-MLX-4bit: all four load cleanly (18.41 GiB in 768 buffers for oQ4e-bf16embed-HIP, 18.14 GiB in 770 buffers for user3892r4, 17.34 GiB in 770 buffers for MLX-4bit), pass the 128-row attention split check (0e0 diff, finite true), and produce top logits 13.813 at token 3267 (bf16embed / unlisted), 13.625 at token 3267 (user3892r4), and 14.438 at token 44184 (MLX-4bit).
    • Base #3242 (be9fe6237) refuses NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-bf16embed-HIP by name: tensorfold: config.json leaves backbone.embeddings unquantized; the native Nemotron kernels read it only as an MLX affine matrix (exit 1).
  • New host tests and what fails without the change:
    • config_test.zig: "a bf16 token table (false) is read only where a backend allows it, by its own name" (fails under default config.parse).
    • admit.zig: "a bf16 token table beside quantized projections is admitted, its bytes counted as stored" and "with a bf16 token table, every other unquantized or unread tensor is still refused by name".
    • plan.zig & widths.zig: "the plan counts a bf16 token table at the bytes its header gives, in both modes and on every rank" and "a bf16 token table has no width: its matrix is unnamed, never unserved, and its label says so".
    • embedding.zig & load.zig: "the gathered rows are the file's bytes, first row and last, widened exactly; an id past the table is refused", "a table that is not bf16 [vocab, hidden] is refused", and "Config.readWith admits backbone.embeddings false on disk while Config.read and parseWith reject invalid heads; readEmbed reads bf16 once decided".
  • Not run: other HIP architectures (no hardware available; only gfx1151 tested), multi-rank GPU serve (tp=2 plan byte split is checked by unit tests in plan.zig and tf-nemotron-hip-test load), and hip-kernel-contract on 94e51ba9b (kernels unchanged from be9fe6237).

Receipt

  • Machine and GPU: one Strix Halo (Radeon 8060S, gfx1151, 128 GiB unified RAM, performance power mode), HIP 7.1, Zig 0.17.0. Raw receipts and sanitized summaries: https://gist.github.com/gilby/1bf33a7d9434cfaba703afd620189c32.
  • Each served arm ran on a fresh server with Linux page cache dropped first, TENSORFOLD_MEMORY_RESERVE_GIB=4 --context 131072 --parallel 4 --prompt-cache-gib 0, running bench_cache --require-cold at 2K (2,048 tokens), 8K (7,099 tokens), and 32K (28,333 tokens), bench_concurrent --levels 1,2,4 --tokens 256 --reps 2 --alone --serial --temperatures 1.0,0, and bench_openai --tokens 256 --reps 2, preceded by a discarded warm-up.

Receipt A — Same checkpoint (Lightning-oQ4e-user3892r4 with 8-bit embeddings): base #3242 (be9fe6237) vs this PR (94e51ba9b) (B1 = oq8-b1, T1 = oq8-t1, T2 = oq8-t2, B2 = oq8-b2, tok/s except TTFT in s):

cell B1 (#3242) T1 (n4) T2 (n4) B2 (#3242) mean diff verdict (#2984)
bench_concurrent T=0.0 L=1 117.30 117.20 117.30 117.20 +0.00% tie / within spread
bench_concurrent T=0.0 L=2 142.40 142.40 143.10 143.10 +0.00% tie / within spread
bench_concurrent T=0.0 L=4 170.40 169.90 170.10 169.90 -0.09% within [B_min, B_max]
bench_concurrent T=1.0 L=1 118.60 118.60 118.70 118.50 +0.08% within / above spread
bench_concurrent T=1.0 L=2 130.50 130.60 131.20 131.20 +0.04% within / above spread
bench_concurrent T=1.0 L=4 162.30 161.50 162.60 162.20 -0.12% within spread (T2 > B1)
bench_openai fibonacci-raw T=0.0 112.37 112.27 112.36 112.30 -0.01% within [B_min, B_max]
bench_openai gpu-chat-no-think T=0.0 90.28 90.84 90.98 90.88 +0.36% within / above spread
bench_openai fibonacci-raw T=1.0 101.70 100.36 100.12 100.21 -0.71% within spread (100.21..101.70)
bench_openai gpu-chat-no-think T=1.0 82.58 82.07 82.81 82.91 -0.37% within [B_min, B_max]
bench_cache 2K (2,048) cold ttft_s 0.737 0.740 0.740 0.741 +0.11% within [B_min, B_max]
bench_cache 2K cold 16-tok decode 48.69 48.59 48.53 48.66 -0.24% within noise (< 0.3%)
bench_cache 8K (7,099) cold ttft_s 2.671 2.683 2.692 2.700 +0.07% within [B_min, B_max]
bench_cache 8K cold 16-tok decode 63.10 63.28 63.12 62.96 +0.27% beats base (T1, T2 > B1, B2)
bench_cache 32K (28,333) cold ttft_s 13.165 13.283 13.318 13.353 +0.31% within [B_min, B_max]
bench_cache 32K cold 16-tok decode 50.60 50.48 50.68 50.64 -0.08% within [B_min, B_max]
  • Exactness on Receipt A: across all 4 arms on Lightning-oQ4e-user3892r4, every request's token_sha256 / token_sha matches oq8-b1 (28/28 bench_concurrent, 8/8 bench_openai, 3/3 bench_cache cold/repeated/concurrent rows, 28/28 concurrent-vs-alone, 24/24 alone-vs-"draft": false per arm, 0 unequal, 0 failed). Planned weight memory is 18.14 GiB (27,043,627,008 B = 25.19 GiB idle GTT) in all 4 arms.
  • Additional stock 4-bit check (Lightning-30B-A3B-MLX-4bit, mlx-b #3242 vs mlx-t #3575): identical 17.34 GiB planned (26,223,607,808 B = 24.42 GiB idle GTT), 28/28 bench_concurrent (28/28 alone, 24/24 serial), 8/8 bench_openai, and 3/3 bench_cache hashes equal.

Receipt B — Published BF16-embedding checkpoint unigilby/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-bf16embed-HIP (928dc0b670dd4b9002991c136ecf0833e37b475c, bf16-t1, bf16-t2, plus smoke-unlisted):

  • Startup plan & device memory: 19,771,766,528 B (18.41 GiB in 768 buffers, labeled mlx-q4g64+q5g64+q6g64+q8g64+bf16-embed), idle GTT 27,316,260,864 B (25.44 GiB). Unlisted config.json smoke also loads at 18.41 GiB +bf16-embed and produces matching prefix text (fibonacci-raw, gpu-chat-no-think).
  • Exactness on published checkpoint: bf16-t1 and bf16-t2 match each other 28/28 on bench_concurrent (14/14 T=0, 14/14 T=1.0), 8/8 on bench_openai, and 3/3 on bench_cache (qualified: true), with 28/28 concurrent-vs-alone and 24/24 alone-vs-"draft": false serial equal in each arm (0 unequal, 0 failed).
  • Speed on published checkpoint (bf16-t1 / bf16-t2): bench_concurrent T=0 L=1,2,4 122.5 / 134.2-135.0 / 167.3-168.0 and T=1.0 L=1,2,4 106.7 / 110.3-111.2 / 144.6-146.0 tok/s; bench_openai fibonacci-raw 121.85-121.87 (T=0) / 103.54-103.60 (T=1.0) and gpu-chat 94.14-94.93 (T=0) / 82.72-83.48 (T=1.0); bench_cache cold TTFT (2K / 8K / 32K) 0.744-0.750 / 2.710-2.722 / 13.366-13.427 s.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than base on the same checkpoint at one stream and across the tested concurrency levels, greedy and sampled.

gilby added a commit to gilby/TensorFold that referenced this pull request Nov 16, 2026
@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby for this, and for the careful refusal tests around it.

What's good:

Must fix:

  1. load.zig readConfig copies config.Config.read (config.zig:202-212) except for the allow argument, and it adds an @import("builtin").is_test branch to production code only so its own test doesn't log. Please give Config a readWith(gpa, io, dir, allow) that read calls with .{}, call it from engine.zig, and have the refusal test go through config.parseWith on the text. Then no test switch is needed.
  2. Please name a published checkpoint that ships this layout: bf16 backbone.embeddings beside MLX affine matrices. Receipt B uses a table you derived by dequantizing. That shows the path is exact, but we'd like the device check to run on files someone actually publishes.

Optional:

Device cells: Strix Halo gfx1151 (HIP): the stock checkpoint unchanged against main plus #3242, and a bf16-table checkpoint loading and serving the same tokens. We will run the device check on our side.

  • Synthena

gilby added a commit to gilby/TensorFold that referenced this pull request Nov 18, 2026
@gilby
gilby force-pushed the strix/n4-nemotron-bf16-embedding branch from 50487b4 to 94e51ba Compare November 18, 2026 15:49
@gilby

gilby commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Updated #3575 on head 94e51ba9b (stacked cleanly on #3242 be9fe6237) to address every review item:

  • Must-fix 1 (Config.readWith / no test branch in load.zig): Added Config.readWith(gpa, io, dir, allow) and parseWith in zig/src/families/nemotron/config.zig (598 lines total), with Config.read / config.parse calling them with .{}. Replaced load.readConfig and @import("builtin").is_test in zig/src/families/nemotron/hip/load.zig with config.Config.readWith in zig/src/families/nemotron/hip/engine.zig, and drove the refusal test through config.parseWith on the text.
  • Must-fix 2 (published BF16-embedding checkpoint): Published https://huggingface.co/unigilby/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-bf16embed-HIP (revision 928dc0b670dd4b9002991c136ecf0833e37b475c), pairing the unquantized BF16 backbone.embeddings.weight ([131072, 2688], "backbone.embeddings": false) from nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16@a9904d24bcc1d289a1950fa9d2b978c47cf903b9 with the mixed-width layers and mtp-4bit.safetensors from unigilby/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-HIP. Base #3242 refuses it by name (backbone.embeddings unquantized), while tf-nemotron-hip-test load and serve admit and serve it (18.41 GiB, +bf16-embed, 0 unequal across alone / "draft": false / cross-arm runs).
  • Optional 1 (single-decision embed_bf16): Extracted tensors.hasBf16Embed shared by admit.zig and load.zig; native.zig passes .cfg = v.config to engine.Engine.load, which passes admitted = (o.cfg != null) to load.loadInto so the scale-less fallback only runs when opened without admit, and readEmbed reads only c.embed_bf16.

Re-verified on 94e51ba9b: zig fmt --check zig/, lean_check.py (0 new findings), tools/pr_check.py --base be9fe6237 --pr 3575 (0 errors, 0 warnings), macOS host checks (18/18 + config.zig 12/13), Linux test-host-ci-linux-hip (100/100 steps, 296/298), hip-kernel-test (20/20 steps, 216/222), 4-arm oq8 parity (0 #2984 losses, 100% token equality), 2-arm MLX-4bit check, and 2-arm published oQ4e-bf16embed-HIP check. Updated receipts in the gist (https://gist.github.com/gilby/1bf33a7d9434cfaba703afd620189c32).

@ashhart
ashhart force-pushed the strix/n4-nemotron-bf16-embedding branch from 94e51ba to 5af5d05 Compare November 19, 2026 02:46
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. To get this moving, we rebased it onto current main ourselves, keeping every one of your commits as it was (author and message) and fitting it to the code main has gained since; no behaviour changes. It is in the landing queue now, and if anything else is needed from you we will say so here.

  • Synthena

ashhart and others added 14 commits November 19, 2026 10:28
Gates 1-4 run the relu^2 stream tile at every width Nemotron's oQ
checkpoints store it (4, 5, 6 and 8 bits in groups of 64), each wider
width with a planted control that reads its codes as 4-bit and goes red
at gate 3. Gate 5 records the 24 launches at 5, 6 and 8 bits on the four
RDNA chips. The 1x8 tile at those widths spills to scratch on gfx1100;
the records name it as a known finding and a host test holds the list
to the records.
The loader, the memory plan and admission read config.json's per-module
widths: MLX affine 4, 5, 6 and 8 bits in groups of 64, one width per
tensor. Routed stacks are checked against their stated width. Other
widths, unquantized projections and an MTP head inside the model's
shards are refused by name. The uniform 4-bit checkpoint reads as before.

The MTP head file is still read at the model's own width, so admission
refuses it by name beside a model not stored 4-bit in groups of 64.
@ashhart
ashhart force-pushed the strix/n4-nemotron-bf16-embedding branch from 5af5d05 to 7a6d3af Compare November 19, 2026 10:28
@ashhart
ashhart merged commit 174010e into ashhart:main Nov 19, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @gilby. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants