Repository navigation
Nemotron 3.5 Bolt (nemotron_h_puzzle) on Metal — serves end to end - #1038
trickyfalcon wants to merge 19 commits into
Conversation
|
Thanks @trickyfalcon. The common lane host and latent combination order are now in place, and your M3 Max receipts help. Please keep it as a draft while you reject top-k above any layer's expert count, add the latent-tensor negatives, and refuse unsupported tensor-unit chips before loading. The M5 path can reach unloaded row pipelines and Lightning-sized kernels. Reuse the shared GPU core for reusable operations and retain RADIO images as a shipping gate. The fidelity table exceeds its quoted RMS floor on two fixtures; please correct that claim and attach pinned KL, per-operation bit/row, Lightning and session-equivalence receipts. Drafting is correctly marked inapplicable without MTP weights. Posted by Ash's AI Assistant Synthena |
|
Thanks. All of that is in, and it stays a draft.
Receipts, on the M3 Max with the pinned checkpoint:
I corrected the fidelity claim. Native RMS is above mlx-lm's chunk spread on two fixtures. Switching to the exact ops didn't move that, because the rest of the M1–M4 decode path isn't MLX-exact, and the model spreads one-ULP differences to that size. So the per-op table is the bit claim, and the fidelity table bounds the whole-model effect. Details are in the updated description. |
|
Thanks @trickyfalcon. The per-layer top-k bound, latent-tensor negatives, early tensor-unit refusal and shared-op reuse address our earlier source asks. Please also make Model.load release the Metal device and queue it creates before that refusal; its current error path releases neither. Keep this draft for RADIO images and the full numerical/session gate. Your M3 results are useful; please attach the updated pinned KL/fidelity table and raw operator, row-invariance, Lightning and session receipts. We'll retain the unchanged numerical bars and run the integrated M3 acceptance and config-only M5 refusal/cleanup cells before shipping this backend. Posted by Ash's AI Assistant Synthena |
|
Thanks. It stays a draft for RADIO and the full gate. The raw receipts are below, all from the M3 Max on the pinned checkpoint. The fix only touches the load error path, so these runs still stand. Per operator and row invariance: check_mlx_ops.py --ops bolt_gemv,bolt_route,bolt_combine (236/236)Pinned KL / fidelity: nemotron_fidelity.py --hash-weights (the model path is shortened to its folder name){
"mlx": "0.32.3",
"mlx_lm": "0.32.0",
"pins": {
"model": "NVIDIA-Nemotron-3.5-Bolt-74B-A9B-MLX-4bit",
"config_sha256": "7279c754382619fd2d849835d78c3137ce27a972efb1eadb86c61585af405985",
"index_sha256": "3b6189b91b55b18edd3be8f512d6b901686b2eb0370d1685266e91e79d01eba0",
"shards": {
"model-00001-of-00009.safetensors": "7e50d79de713d0ff7bc3be41ef52c8cd3c3e35cc3331f03a91b0916d30088639",
"model-00002-of-00009.safetensors": "999d37fa98e8926af495b59250808c4dcb01e7272ade97387aeb5a6ebfd9d78a",
"model-00003-of-00009.safetensors": "c75f5fe7261db2374b8e23cdd2cb1827140799ac13fa536cccbdb9d242be61da",
"model-00004-of-00009.safetensors": "4da61085cc4f0505569412ee72d2c853b819c0f2f2c8ce85470149d8437b2864",
"model-00005-of-00009.safetensors": "6f03752282c67af6b2b2e8e3c66d63a13cbd4cd2c19f8e622f40a0a7c9299caf",
"model-00006-of-00009.safetensors": "6aafcfc9d99618addbecf93b6ef6f1adc8114941e9ca4a0c1ba3cbf54fbb4d9d",
"model-00007-of-00009.safetensors": "87238841e0aad4279e95908268d34e3ed1b5da5de0d04ce99fb4f8c45af67c35",
"model-00008-of-00009.safetensors": "3e94ea58a946e1d54521ef18baa6c73e61066f68588fb2b46726ede3aac24dba",
"model-00009-of-00009.safetensors": "c19f22b58b4c42a739374585623d16addf2de352022b9d8a440ba131ba5ff720"
},
"engine_commit": "ce28820e47c16988f56288ad64ad464e0738184a",
"engine_dirty": true
},
"fixtures": [
{
"fixture": "fibonacci-raw",
"tokens": 15,
"token_sha256": "b7769551532c0ad8b9a1b8124e3bb9e3edcf8cca5d64125c020edb80d824adbb",
"native_nll": 2.8919690871110246,
"mlx_serial_nll": 2.8406177388455425,
"mlx_chunk32_nll": 2.8742868031743534,
"mlx_full_nll": 2.8742868031743534,
"native_vs_serial": {
"top1_agreement": 0.9333333333333333,
"max_abs": 1.5,
"rms": 0.2695379667229362,
"finite": true,
"kl_mean": 0.003982284659141044,
"kl_p99": 0.009924088716917365,
"kl_max": 0.010204187780618004
},
"native_vs_chunk32": {
"top1_agreement": 0.9333333333333333,
"max_abs": 4.125,
"rms": 0.6525186847388184,
"finite": true,
"kl_mean": 0.006040667485176172,
"kl_p99": 0.01711581182153379,
"kl_max": 0.01742250315447551
},
"mlx_chunk32_vs_serial": {
"top1_agreement": 1.0,
"max_abs": 3.125,
"rms": 0.4436320970441915,
"finite": true,
"kl_mean": 0.006796612407219586,
"kl_p99": 0.019070950104862386,
"kl_max": 0.01995933719745038
},
"mlx_full_vs_serial": {
"top1_agreement": 1.0,
"max_abs": 3.125,
"rms": 0.4436320970441915,
"finite": true,
"kl_mean": 0.006796612407219586,
"kl_p99": 0.019070950104862386,
"kl_max": 0.01995933719745038
}
},
{
"fixture": "gpu-chat-no-think",
"tokens": 35,
"token_sha256": "34c41fc50825b5fd887436ed1f9f2ae69d710777a221f94b1d5cbb5717737fe4",
"native_nll": 5.716686995554169,
"mlx_serial_nll": 5.724390312130104,
"mlx_chunk32_nll": 5.765810753377128,
"mlx_full_nll": 5.717642529948139,
"native_vs_serial": {
"top1_agreement": 0.9428571428571428,
"max_abs": 1.25,
"rms": 0.1893557441630768,
"finite": true,
"kl_mean": 0.010642203432166349,
"kl_p99": 0.08333138989714994,
"kl_max": 0.10881155142696898
},
"native_vs_chunk32": {
"top1_agreement": 0.9714285714285714,
"max_abs": 1.375,
"rms": 0.21460021831939105,
"finite": true,
"kl_mean": 0.00901477917118718,
"kl_p99": 0.04355610256285816,
"kl_max": 0.047731224040055864
},
"mlx_chunk32_vs_serial": {
"top1_agreement": 0.9714285714285714,
"max_abs": 1.75,
"rms": 0.19092943749106223,
"finite": true,
"kl_mean": 0.007755403077574087,
"kl_p99": 0.030876112146067048,
"kl_max": 0.03177423913459955
},
"mlx_full_vs_serial": {
"top1_agreement": 0.9714285714285714,
"max_abs": 1.75,
"rms": 0.23128675328521206,
"finite": true,
"kl_mean": 0.0072931219236618315,
"kl_p99": 0.031277037836049904,
"kl_max": 0.03227898497237537
}
},
{
"fixture": "public-contribution-guide-512",
"tokens": 512,
"token_sha256": "b0206242758037798cce991293f0f600a7c5113d6b652705b43ada0bd2b192ce",
"native_nll": 3.2981265319963677,
"mlx_serial_nll": 3.306361377972774,
"mlx_chunk32_nll": 3.2939761279482083,
"mlx_full_nll": 3.3011254621412025,
"native_vs_serial": {
"top1_agreement": 0.91796875,
"max_abs": 8.25,
"rms": 0.4013358564352756,
"finite": true,
"kl_mean": 0.010945506139855322,
"kl_p99": 0.04042149809126025,
"kl_max": 0.09108781051450346
},
"native_vs_chunk32": {
"top1_agreement": 0.921875,
"max_abs": 9.4375,
"rms": 0.39862855150561066,
"finite": true,
"kl_mean": 0.010753584871592985,
"kl_p99": 0.047534459930563815,
"kl_max": 0.1400134702895854
},
"mlx_chunk32_vs_serial": {
"top1_agreement": 0.947265625,
"max_abs": 4.25,
"rms": 0.26151797632237317,
"finite": true,
"kl_mean": 0.009838347827565704,
"kl_p99": 0.03959047257870294,
"kl_max": 0.05834875115422212
},
"mlx_full_vs_serial": {
"top1_agreement": 0.9453125,
"max_abs": 8.8125,
"rms": 0.4033499529019144,
"finite": true,
"kl_mean": 0.010674325096614975,
"kl_p99": 0.042492825393599755,
"kl_max": 0.06645138175069834
}
},
{
"fixture": "python-stdlib-2048",
"tokens": 2048,
"token_sha256": "5a42facb3a83f6c531383a19c57a666bf245328afc4138b97029ad2be1afadab",
"native_nll": 0.36548583462730677,
"mlx_serial_nll": 0.36374177519935724,
"mlx_chunk32_nll": 0.36367116087373574,
"mlx_full_nll": 0.36616538895453143,
"native_vs_serial": {
"top1_agreement": 0.986328125,
"max_abs": 11.0625,
"rms": 0.557423203819268,
"finite": true,
"kl_mean": 0.005274513941993687,
"kl_p99": 0.06450120232168344,
"kl_max": 0.875234221777027
},
"native_vs_chunk32": {
"top1_agreement": 0.98974609375,
"max_abs": 10.5,
"rms": 0.5284347706154673,
"finite": true,
"kl_mean": 0.004072006140364548,
"kl_p99": 0.0500922697477258,
"kl_max": 0.11082624491880542
},
"mlx_chunk32_vs_serial": {
"top1_agreement": 0.9873046875,
"max_abs": 11.875,
"rms": 0.4840688789466054,
"finite": true,
"kl_mean": 0.0051351756370919535,
"kl_p99": 0.06548356509049968,
"kl_max": 0.6026136509687315
},
"mlx_full_vs_serial": {
"top1_agreement": 0.98828125,
"max_abs": 11.1875,
"rms": 0.5309294850846997,
"finite": true,
"kl_mean": 0.005368460118554758,
"kl_p99": 0.06725235402622899,
"kl_max": 0.5935126875951473
}
}
]
}concurrent == solo: xpu_concurrent_receipt.py, 2 and 4 streamsresumed == fresh: xpu_resume_receipt.py, cached server then --prompt-cache-gib 0# cached
{"sampling": "greedy", "turn1": {"sha": "8351ea926665", "prompt": 1508, "cached": 0, "prefill_s": 14.557032}, "turn2": {"sha": "e54437d714b4", "prompt": 1580, "cached": 1502, "prefill_s": 0.863641417}}
{"sampling": "seeded", "turn1": {"sha": "cc1f8a2a3a78", "prompt": 1508, "cached": 1502, "prefill_s": 0.086221167}, "turn2": {"sha": "235fa147bcc0", "prompt": 1606, "cached": 1502, "prefill_s": 1.138095875}}
# fresh
{"sampling": "greedy", "turn1": {"sha": "8351ea926665", "prompt": 1508, "cached": 0, "prefill_s": 15.623639125}, "turn2": {"sha": "e54437d714b4", "prompt": 1580, "cached": 0, "prefill_s": 13.90681975}}
{"sampling": "seeded", "turn1": {"sha": "cc1f8a2a3a78", "prompt": 1508, "cached": 0, "prefill_s": 12.926058917}, "turn2": {"sha": "235fa147bcc0", "prompt": 1606, "cached": 0, "prefill_s": 13.742770125}}Lightning 30B-A3B (d9d758fb): main vs this branch, token_sha per request (32/32 equal)# main
{
"p0-greedy-chat": "5ae8a877bf7a",
"p0-greedy-raw": "434cb488a3e9",
"p0-seeded-chat": "ca84ce37feaf",
"p0-seeded-raw": "154bb8b237f1",
"p1-greedy-chat": "b18a343f6d01",
"p1-greedy-raw": "2ca4bcfac5c6",
"p1-seeded-chat": "75ad7305d004",
"p1-seeded-raw": "994dfa915cf0",
"p2-greedy-chat": "2f212f7460d7",
"p2-greedy-raw": "6ce81e25bb38",
"p2-seeded-chat": "4aac7cb43ab7",
"p2-seeded-raw": "11ccbd49c519",
"p3-greedy-chat": "ebd63876f10b",
"p3-greedy-raw": "866008e96b3a",
"p3-seeded-chat": "bb7b0f3e6107",
"p3-seeded-raw": "ae3c33a23e79",
"p4-greedy-chat": "99f683d98b2a",
"p4-greedy-raw": "eb0c21a3d01c",
"p4-seeded-chat": "80d51dfae249",
"p4-seeded-raw": "341615eefe95",
"p5-greedy-chat": "15ffafbac276",
"p5-greedy-raw": "878d1d439cda",
"p5-seeded-chat": "6a59107e2c89",
"p5-seeded-raw": "bbf7d21d4f9e",
"p6-greedy-chat": "689eaf56d4b3",
"p6-greedy-raw": "b269199162ce",
"p6-seeded-chat": "92fbbb26fe47",
"p6-seeded-raw": "4fcf8b6c20b4",
"p7-greedy-chat": "104a1428c2f1",
"p7-greedy-raw": "fbf60b9de08e",
"p7-seeded-chat": "e8ce18600195",
"p7-seeded-raw": "3f7c0c8cec66"
}
# this branch
{
"p0-greedy-chat": "5ae8a877bf7a",
"p0-greedy-raw": "434cb488a3e9",
"p0-seeded-chat": "ca84ce37feaf",
"p0-seeded-raw": "154bb8b237f1",
"p1-greedy-chat": "b18a343f6d01",
"p1-greedy-raw": "2ca4bcfac5c6",
"p1-seeded-chat": "75ad7305d004",
"p1-seeded-raw": "994dfa915cf0",
"p2-greedy-chat": "2f212f7460d7",
"p2-greedy-raw": "6ce81e25bb38",
"p2-seeded-chat": "4aac7cb43ab7",
"p2-seeded-raw": "11ccbd49c519",
"p3-greedy-chat": "ebd63876f10b",
"p3-greedy-raw": "866008e96b3a",
"p3-seeded-chat": "bb7b0f3e6107",
"p3-seeded-raw": "ae3c33a23e79",
"p4-greedy-chat": "99f683d98b2a",
"p4-greedy-raw": "eb0c21a3d01c",
"p4-seeded-chat": "80d51dfae249",
"p4-seeded-raw": "341615eefe95",
"p5-greedy-chat": "15ffafbac276",
"p5-greedy-raw": "878d1d439cda",
"p5-seeded-chat": "6a59107e2c89",
"p5-seeded-raw": "bbf7d21d4f9e",
"p6-greedy-chat": "689eaf56d4b3",
"p6-greedy-raw": "b269199162ce",
"p6-seeded-chat": "92fbbb26fe47",
"p6-seeded-raw": "4fcf8b6c20b4",
"p7-greedy-chat": "104a1428c2f1",
"p7-greedy-raw": "fbf60b9de08e",
"p7-seeded-chat": "e8ce18600195",
"p7-seeded-raw": "3f7c0c8cec66"
} |
2667794 to
3a3a599
Compare
|
Rebased onto main (da275a3), so it merges cleanly again. It stays a draft. The only conflict was Re-run on the M3 Max after the rebase:
|
|
A reference point for this work, not a competing PR: we have served Nemotron 3.5 Bolt 74B-A9B 24GB on Metal since 1.0.12 through a different route, a Metal port of MiaAI-Lab's DGX Spark engine ( On an M5 Ultra, with that checkpoint's packed weights (IQ2_XXS experts, NVFP4 Mamba projections, Q8_0 attention):
Happy to run your branch on the same prompts and post the comparison, if that would help. |
|
Review of the current head rebased onto main e9b69ed. It applies cleanly. We added one small fix-up:
Weights are read as stored and M5 is refused before loading, both good. RADIO images are deferred, so please don't list the multimodal checkpoint as qualified yet. |
3a3a599 to
8ce648a
Compare
|
Thanks for the review. All four are addressed, and the branch is rebased onto current main ( 1. Kernel contract (6e45558).
Gate 4 stresses each kernel with integer inputs that are exact in fp32 in any order. There are eight planted controls, each a one-line mutation of the kernel's own source, and each is red at the gate it targets:
Gate 5 records live in On the generator: there isn't one for these. The add-norm instantiations at The one limit problem is upstream's own 2. Fidelity (8ce648a).
On
Errors in bf16 ulps of the row's RMS. Route picks: prompt 1 of 10,240 differ, decode 0 of 1,280.
On python-stdlib, mlx-lm's own chunk32 run flips 26 positions, the largest at 6 ulps (position 22). The native flips 28, 17 of them the same positions, also at most 6 ulps. Every differing token, with its margin, is in 3. Shape admission (f78f745). Expert counts off the router gemv's 4-row tile are refused before load ( 4. Lightning stays byte-identical (d197480).
The multimodal checkpoint stays unlisted: the text backbone only here, with RADIO still a shipping gate. receiptstf-kernel-contract --only bolt --offline DIR (gates and controls): Route pick that differs from float64 (nemotron_stages.py): layer 1, row 73, native 32 vs float64 44, float64 gap 5.1e-8, fp32 keys tie (4.820835590). Every differing teacher-forced token, position:margin in bf16 ulps (prompt rows; decode rows are bit-identical), * = mlx-lm's own chunk32 run flips there too: |
|
Thanks @trickyfalcon, and for mirroring the On the generator: thanks for the offer, but there's no need to send the parameters. Keep the Bolt instantiations as they are. The branch now conflicts with main in |
8ce648a to
5a5c696
Compare
|
Thanks. I've rebased onto current main (
Six controls, each red at its gate:
Gate 5: both launches are 256 threads with no threadgroup memory, and M1/M2 take 1024 each, as recorded in No kernel source or engine code changes in this commit. |
|
Thanks @trickyfalcon for the rebase and for registering the Bolt-width tree conv and scan with their six controls. The branch applies cleanly to main again, and the contract summary (10 kernels through gates 1-4, 14 controls red) covers what we asked for. Next we will run the integrated M3 acceptance and the config-only M5 refusal and cleanup cells on our side. RADIO images stay deferred, so the multimodal checkpoint stays unlisted for now. We'll follow up here once those runs are in. |
|
Hi @trickyfalcon, a status note: this is waiting on us. Your rebase and the Bolt-width kernels with their six controls |
|
Hi @trickyfalcon, our M5 Ultra cell is in, along with a trial rebase of your 18 commits onto today's main. On the M5 (config files only, no weights):
The rebase onto today's main: the conflicts are only registration lists (
If you'd like our rebase as a starting point, with the conflicts already settled, say so and we'll push it to a branch for you. After that, what's left on our side is the integrated M3 acceptance run, which we'll do once the rules above pass.
|
Part 1 of the native Metal backend for nemotron_h_puzzle (Nemotron 3.5 Bolt 74B-A9B), opened early per ashhart#962 so the loader can be reviewed before the latent kernels harden. v1.1.0 already parses the Puzzle config (bolt, per-layer moe[]) and serves it on CUDA; this is the Metal weight loader for it. weights.zig: the Metal MoE loader now reads each layer's own expert count and width (per-layer in nemotron_h_puzzle, uniform otherwise), runs the routed experts in the moe_latent_size latent rather than hidden, and carries the two bf16 latent projections fc1/fc2_latent_proj (new Moe.into and .out, a plain-bf16 Dense referenced in place; the Lightning path keeps them null and is unchanged). moe() takes the layer's experts, width and latent; its two callers pass the per-layer values for bolt, the globals otherwise. config.zig: checkShapes gains a bolt branch (checkBoltShapes) for Bolt's dimensions (hidden 4096, 1024 latent, 5376 shared expert, top-k 9, per- layer expert counts 240-496 and widths 1536-2560). weights_test.zig: a two-layer puzzle block loads per layer - each keeps its own expert count and width, the experts read the latent, and both latent projections are present. No forward or kernels yet; those follow as commits on this branch. The Lightning path is byte-for-byte unchanged (zig build test test-golden: 0 unexpected golden differences).
The latent path for Nemotron 3.5 Bolt, mirroring cuda_latent.zig run(): the normed input projects into the moe_latent_size latent, the routed experts run up/down in the latent, each pick projects back to hidden, then add_norm combines the picks by weight with the shared expert (kept in hidden) and the residual. Per-pick out-projection is valid because the projection is linear. Hand-authored (the nemotron kernel generator is not in the public repo). state.zig: two latent-width scratch buffers (x_lat, ey_lat). weights.zig: the routed experts load through the runtime-dim row kernels for the Puzzle (latent > 0), which read each layer's own expert count and width at K = latent; the baked 4/64 lane kernels serve only the Lightning inner width. New Metal kernels (zig/kernels/metal/nemotron): - route_bolt: the router top-k at runtime NE and K, so one kernel serves every Puzzle layer's own expert count. Same scoring as route.metal (sigmoid of the gate logit plus the correction bias, normalised and scaled) but the per-lane slices are ceil(NE / 32) with an e < NE guard, so the last partial slice is kept (every Bolt expert count is NE % 32 == 16, which the baked route.metal would drop). - dense_bf16: a bf16 write-matmul (y = x R^T, no accumulate) for the gate and the two full-precision latent projections fc1/fc2_latent_proj. - add_norm_moe_xs_bolt: the combine + shared + residual + next-norm kernel at <4096, 512, 9> (896 does not divide 4096; 512 does). layers.bolt_moe + forward dispatch (c.bolt): gate (dense_bf16) -> route_bolt -> shared up/down (hidden, the Lightning path) -> into (dense_bf16) -> routed experts up/down in the latent (indexed row kernels) -> out per pick (dense_bf16) -> add_norm_moe_xs_bolt. Lightning is unchanged: the dispatch takes bolt_moe only when c.bolt, and zig build test test-golden holds 0 unexpected golden differences. Remaining to RUN end to end: Bolt-dim variants of the shared up_relu2 and the mamba kernels, and the GPU kernel-contract tests (route_bolt first).
…t slice tf-metal-tests now dispatches route_bolt at a real Bolt expert count (NE=240, NE % 32 == 16) and checks its picks and weights against a CPU reference. Row 0 plants its top nine logits on experts 224..232 - in the last partial slice [224,240) that the baked NE/32 striping dropped - and the kernel returns exactly those, so the pad-to-32 fix is proven on device. Weights match the reference (sigmoid + bias, normalised, scaled) within 1e-3. route_bolt.metal and dense_bf16.metal join the metallib source list, which compiles and validates their MSL at build time (the engine still loads them from the runtime kernel registry).
dense_bf16: the bf16 write-matmul (gate and latent projections) checked against an fp32 CPU reference over the same bf16 inputs, to a bf16 output tolerance. add_norm_moe_xs_bolt: the <4096, 512, 9> instantiation, checked on the case with no routed picks (WE = 0) and no shared expert (SH = 0), where the block reduces to OUT = rmsnorm(H) * W with W = 1; HN is unchanged and XS is the per-group sum of OUT. add_norm_moe_xs.metal joins the metallib source list so the instantiation compiles at build time and tf-metal-tests can load it. tf-metal-tests: 9 of 9 pass on an M-series Mac.
The Metal engine now opens, loads and serves the published Bolt checkpoint
(bytebunker/NVIDIA-Nemotron-3.5-Bolt-74B-A9B-MLX-4bit, 40.3 GiB) on an
M-series Mac without tensor units, where every projection runs on the
runtime-dim row kernels. On an M3 Max (128 GB) it loads in 6.3 s and decodes
at ~41 tok/s.
Checked on that build:
- greedy tokens are identical to mlx_lm 0.32.3 (token_sha256 equal) on the
prompts tried;
- concurrent == solo at two and four streams;
- resumed == fresh: a chat turn resumed from the prompt cache (at 915 of 959
tokens) equals the same turn prefilled on a fresh server.
What Bolt needed beyond the latent MoE:
- metal.zig: register the nemotron_h_puzzle family and open it.
- weights.zig / forward.zig: a full-precision bf16 lm_head (MLX quantizes a
module only where {path}.scales exists, and Bolt's lm_head has none) is
read in place and projected by dense_bf16.
- Mamba at Bolt's widths (inner 128 x 64 = 8192, in_proj 18560): the tree
conv and scan instantiated at <8192, 8, 128, 4, 18560, 8192> and
<128, 64, 8, 128, 8192, 18560, 18432, 1048576>, and the gated group norm
at XD 8192 / GS 1024 (group_norm_xs_bolt.metal, one per padded row count).
- add_norm_xs at <4096, 512>, and the hidden row sums at the model's width.
- backend.zig: prompts run through the decode kernels in fused_rows chunks;
the fused prefill kernels are not yet built for the latent MoE.
All Bolt kernels are hand-authored instantiations of the generated ones (the
generator is not in the public repo). Lightning is unchanged: zig build test
test-golden holds 0 unexpected golden differences; tf-metal-tests 9 of 9.
…does bolt_moe now follows mlx_lm's NemotronHMoE order and roundings: the picks are summed by weight in the latent ((y * scores).sum(-2) in fp32, one bf16 rounding), the sum is projected back to hidden once by fc2_latent_proj, then the shared expert and the residual are added (bf16(y + shared), then bf16(h + y)). It replaces the per-pick out-projection, which was equal in exact arithmetic but rounded differently, and costs nine times the fc2_latent_proj work. - combine_latent.metal: the latent combine, with add_norm_moe_xs's routed-sum order (a sequential fma over the picks). - add_norm_moe_xs_bolt is now <4096, 512, 1>: one pick of weight 1 (exact under the fma) carries the projected MoE output into add_norm; Scratch gains a ones buffer for it. - tf-metal-tests: combine_latent bit-exact against a host fma reference; 10 of 10 pass. On the published Bolt checkpoint (M3 Max), greedy output is token-exact with mlx_lm 0.32.3 on 7 of 8 comparison prompts (was 5 of 8); the eighth diverges at an exact tie in mlx_lm's own logits. concurrent == solo (x2, x4) and resumed == fresh still hold; decode ~42-43 tok/s. Lightning unchanged (test-golden 0 unexpected).
…orward) Nemotron had no fidelity tool; this adds one on the qwen35/lfm2 pattern. - tf-nemotron-forward MODEL TOKENS.npy OUT.bin: native teacher-forced bf16 logits for every position, the ids run through the decode kernels fused_rows rows a forward (Lightning or Bolt). - tools/zig/nemotron_fidelity.py: teacher-forced NLL, top-1 agreement and logit RMS of the native logits against mlx-lm run one row at a time, in 32-row chunks and whole, with mlx-lm's own chunked-vs-serial variation as the floor. Every native pass runs before mlx-lm loads, so a 74B checkpoint is never held twice. The long fixture is the running Python's json.decoder and argparse sources (public, deterministic). Bolt on an M3 Max (mlx 0.32.3, mlx-lm 0.32.0), native vs mlx-lm serial, with mlx-lm's own chunk32-vs-serial floor in brackets: fixture tokens top-1 logit RMS NLL native / mlx fibonacci-raw 15 0.933 (1.000) 0.181 (0.444) 2.890 / 2.841 gpu-chat-no-think 35 0.971 (0.971) 0.179 (0.191) 5.715 / 5.724 contribution-guide-512 512 0.922 (0.947) 0.322 (0.262) 3.293 / 3.306 python-stdlib-2048 2048 0.988 (0.987) 0.494 (0.484) 0.362 / 0.364
A config refused after the device opens (Bolt on a tensor-unit chip, a bad shape, a time-step clamp) returned without releasing either. A test counts the device's references across a refused load.
The flag was silently ignored on this path; Bolt is now refused like Nemotron, before any load, with the refusal test extended.
…load At E = 241 the gemv's last tile (237) clamps back over 236..239, so those rows would be written twice. Counts not a multiple of 4 are refused before the device opens; Bolt's own counts (240-496, all multiples of 16) pass.
…combine are Bolt's own - x_lat, ey_lat and ones are allocated for nemotron_h_puzzle only (null otherwise). - A bf16 lm_head without scales is read as a dense head for Bolt only; every other family keeps the quantized head it always loaded and is refused without one, as before (weights.denseHead, tested both ways). - tf_moe_combine_at is back to upstream's order for every caller. Bolt's col_reduce_small order past 8 picks is a new tf_moe_combine_rows_lanes8 (bit-equal to the shared one at k <= 8); bolt_combine still 236/236 bit-identical with the gemv and route cases.
…rols and M1/M2 records tests/contract/metal_bolt.zig registers Bolt's Metal kernels with the canonical runner, at the shapes nemotron/bolt.zig serves them: - tf_gemv_bf16_bm4_tm4 and _bm8_tm4 (the router gate at 304-496 experts, into, out, the bf16 lm_head at 131072 x 4096), dense input family, float64 bound; - tf_route_topk at every Bolt expert count, top-k 9: picks exact against float64 (planted exact ties, the last partial 32-expert slice winning row 0), weights within the bound, a stated NaN rule (MLX's sort); - tf_moe_combine_rows_lanes8 at k 9 over the 1,024 latent; - tf_nemotron_group_norm_xs_bolt (MP 16 and 128), tf_nemotron_add_norm_xs_bolt and _moe_xs_bolt: OUT as float64 ranges through its bf16 points, HN bit for bit, XS bit for bit as the f32 sum of the kernel's own outputs, padded rows zero. Gate 4 stresses each with integer inputs exact in fp32 in any order (fp16 overflows, bf16 misses). Eight planted controls, each a one-line mutation of the kernel's own source, red at the gate named: gemv summed in half (sums), gemv losing its K tail (shapes), route dropping the last partial 32-expert slice (shapes), route comparing NaN as a number (nonfinite), combine dropping pick 8 (shapes), add norm writing HN without its delta, group norm summing 63 of 64, group norm over half its group (shapes). Gate 5: core/contract/bolt_records.zig, threads and threadgroup bytes as bolt.zig launches them, M1/M2 limits from --offline (all 1024). tf-kernel-contract --only bolt --offline DIR on an M3 Max: 8 kernels pass gates 1-4, 8 controls red as planted, 28 launch checks pass.
…, prompt and decode rows apart forward.Tap: an optional look at a forward's stages (h and x in and out of each layer, Mamba's in_proj, conv, gated scan, group norm, attention's qkv and output, the MoE's gate, picks, weights, shared expert, into, routed experts, combine and out). Null in the engine, which then encodes nothing more: logits with and without it are byte-identical, and Lightning's replies on main and this head match 16/16 (greedy and seeded). tf-nemotron-forward --decode-from N runs rows from N one a forward (decode) after fused_rows chunks (prompt); --stages DIR copies every stage of every layer of every forward out (stages.bin, stages.jsonl). tools/zig/nemotron_stages.py recomputes each stage in float64 from the dequantized checkpoint and the native's own input to that stage, so each stage's error is its own, and reports it in bf16 ulps of the row's RMS, prompt and decode rows apart; every projection also gets MLX's own bf16 result on the same input (quantized_matmul) as the floor. Route picks are compared exactly; each differing pick is listed with float64's gap and whether its fp32 keys tie. tools/zig/nemotron_fidelity.py runs the native twice a fixture (prompt rows, then decode rows), lists every teacher-forced token whose top-1 differs from mlx-lm serial with mlx-lm's margin, and fails: on a non-finite logit, on a differing token whose margin is above the largest at which mlx-lm's own chunk32 or full run flips on that fixture (or --tie-ulps), on more differing tokens than twice mlx-lm's own count plus 2, or on an NLL further from mlx-lm serial than twice mlx-lm's own spread.
…ns, with planted controls and M1/M2 records tf_tree_conv_bolt and tf_tree_scan_bolt run gates 1-4 as Bolt serves them: one stream's chain of 1 to 16 rows (a decode step or a prompt chunk; no replayed rows or trees, since the checkpoint has no draft head), its tables from layers.Tables.of over the segment backend.zig builds, the state read from the stream's slot and stored to a fresh one. init checks the two instantiations' template arguments against nemotron_tree.metal. XBC and Y are checked against float64 as intervals through their bf16 points: the conv's fma chain within gamma(4), the scan's recurrence op by op with the dot within gamma(35) (a lane's 4 states, then simd_sum in an unstated order), fast math's exp, log and divide within 2^-16. check() also requires RAW, DTRAW and the stored conv taps bit for bit, the stored scan state within its interval, the other slots and the tree states untouched. Gate 4's integers are exact in fp32 in any order (conv: w0 = big + r against w1 = -big; scan: A 0, B 0, each state's term cancelled by a rotated partner's), and bf16 and fp16 sums of them leave the bound. Six controls, each red at its gate: the conv dropping its oldest tap, storing the wrong taps, summing in half; the scan without its D skip, not decaying its state, summing its dot in half. Gate 5 records both launches (256 threads, no threadgroup memory) with the M1/M2 limits from --offline.
…st launch map, a clean refusal The contract's Bolt files are split along their kernels: metal_bolt.zig keeps gemv, route and combine, its norms move to metal_bolt_norm.zig, the Mamba scan to metal_bolt_scan.zig. Bolt registers through one hook, metal_bolt_main.zig, so metal_main.zig is back to main's size plus two lines. Every comment is one line within 120 columns; the two fidelity tools' long docstrings are their --help text. metal_limits.zig returns before it touches a source on the host walk, as its neighbours do, so test-metal-launch-map-host builds again. Model.load makes its queue and reads the device's generation inside an autorelease pool: a refused load leaves nothing for the caller's pool to hold. The refused-config test takes its count after a first load, since the first queue on a device raises the device's retain count once on every chip.
5a5c696 to
d50f93b
Compare
|
Thanks for the M5 cell and the trial rebase, and sorry for the few days' gap. The branch is rebased onto today's main ( The M5 cell
The rebase and the rules I did the rebase here, so no need to push yours. The conflicts were the lists you named: main's entries stay and Bolt's go at the ends.
Receipts at the new head (
Still a draft. The integrated M3 acceptance is yours whenever it suits. |
|
Thanks @trickyfalcon. The pool explanation reads right: the retain test now compares after a first refused load, and the footprint trace shows the one-time first-load cost with nothing left per refusal. We will rerun our 50-load cell on the new head and read the count after the first load, as you asked. The remaining work is ours: the queue rebase onto current main (the Metal registration and test tables moved, and two nemotron files need the usual line room). Nothing is needed from you.
|
|
Thank you @trickyfalcon: Nemotron 3.5 Bolt now serves on Metal from main. It landed through #4162, with your commits and authorship kept and our rebase onto today's main on top (the Bolt checks and dense blocks moved to sibling files to keep each under 600 lines, plus two build fixes the move needed). It will be in the next release's thanks too. Closing this one as landed.
|
Draft, opened early per #962 so the design can be steered before the kernels harden. The native Metal backend for
nemotron_h_puzzle(Nemotron 3.5 Bolt 74B-A9B), on current main, which already parses the Puzzle config and serves it on CUDA; this adds the Metal side. It serves the published checkpoint end to end (bytebunker/NVIDIA-Nemotron-3.5-Bolt-74B-A9B-MLX-4bit): on an M3 Max (128 GB) it loads in ~6 s and decodes at ~40 tok/s.Receipts (M3 Max, applegpu_g15, the published MLX-4bit build)
Pinned checkpoint:
config.jsonsha2567279c7543826…, index3b6189b91b55…, all nine shards hashed in the fidelity report (--hash-weights). Reference: MLX 0.32.3, mlx-lm 0.32.0. Engine: this branch.check_mlx_ops.py --ops bolt_gemv,bolt_route,bolt_combine)group_expert_selectat k 9, and the latent combine; MLX's own metallib kernel replayed at each shape agrees tootf-kernel-contract --only bolt --offline)xpu_concurrent_receipt.py)xpu_resume_receipt.py, CONTRIBUTING.md, two turns)--prompt-cache-gib 0, greedy and seedednum_nextn_predict_layers: 0)test-golden0 unexpected; Lightning 30B-A3B MLX-4bit (d9d758fb) on main and on this branch: 16/16 replies the same token_sha (8 prompts x greedy/seeded)--speed-upare refused before any weight is readzig build test,test-bolt-host,tf-metal-testsEach stage against float64, from the native's own input to that stage (
tf-nemotron-forward --stages,tools/zig/nemotron_stages.py; argparse's source, 256 prompt rows then 32 decode rows, all 88 layers; bf16 ulps of the row's RMS; MLX's own bf16 result on the same input in brackets):Route picks: 1 of 11,520 differ (prompt), an exact fp32 tie broken by the lower id as mlx-lm's stable sort does.
Teacher-forced logits vs mlx-lm serial (
tools/zig/nemotron_fidelity.py, prompt rows; decode rows give the same logits bit for bit). The run fails on a differing token past the largest margin at which mlx-lm's own chunk32/full runs flip on that fixture, on more than twice their count plus 2, or on an NLL past twice mlx-lm's own spread; it passes:What's in it
fc1/fc2_latent_projand the unquantized bf16lm_headread in place.bolt.zig), in mlx_lm's NemotronHMoE order: gate gemv →tf_route_topk→fc1_latent_proj→ routed experts →tf_moe_combine_rows_lanes8→fc2_latent_proj→+ shared→+ residual. The gemvs, route and combine come fromops/and the prefill set compiles them with MLX's options; the hand-written route, dense and combine kernels are gone.ops/gemv.metalgains MLX's bm4/bm8 bn1 gemv (tf_gemv_bf16_bm{4,8}_tm4) beside its bn8 one. Bolt's 9-pick combine is its owntf_moe_combine_rows_lanes8(col_reduce_small's 8 lanes past 8 picks); the sharedtf_moe_combineis unchanged. Bolt's scratch and its bf16 head are Bolt-only.gen_nemotron_kernels.py's style (that generator isn't in the public repo).bolt_op_cases.py(per-op cases),tests/contract/metal_bolt.zig(the kernel contract),forward.Tap+tf-nemotron-forward --decode-from/--stages+nemotron_stages.py(staged float64),nemotron_fidelity.py(teacher-forced logits, prompt and decode rows, gated against mlx-lm's own spread).Not yet / next
prefill_mixers) for the latent MoE; prompts run through the decode kernels 16 rows at a time.Deferred, with their gates kept