Repository navigation
Conversation
A ModelOpt checkpoint writes NVFP4 as E2M1 codes with a 16-element-block scale and one global scale, and FP8 as E4M3 codes with one scale, neither of which the shared formats name. This reads both as they are stored and decodes them on the device, so a converted checkpoint serves without being re-quantized to MLX's layout. NVFP4 keeps its E2M1 code through the BF16 dot2 product, which is exact for the format's levels; FP8 decodes in flight and is exact in f32. Both run through one 64 x 64 tile that stages a column chunk once and serves 64 rows, with a 16-row block for a decode round summing as the tile does. The host projection is the family's own union of the shared formats, `quant.nvfp4.Host` and a stored FP8, so core's format vocabulary keeps the three formats both engines read. A routed expert stack stays core's: a global scale an expert, so NVFP4 stacks are refused. A ModelOpt checkpoint's bf16 layers read dense. Scale handling carries the review's asks: FP8 scales ModelOpt does not write are refused, as is a weight holding an E4M3 NaN code, and each refusal names the tensor and the reason through core's `Why` buffer rather than an uninitialised name. A decode round on the product ran the 16-row block, which distributes its threads over all sixteen rows while writing only a.m of them, so fifteen sixteenths of the work is discarded at m = 1. The same header gains four entry points, tf_nvfp4_col1 to tf_nvfp4_col4, over one nvfp4_columns<ROWS, DEPTH>: a thread owns one output column, reads that column's whole K span, and holds ROWS accumulators. The launch picks the entry point whose ROWS matches a.m exactly, so no row is padded and a row's offset stays constant. They are separate entry points rather than a branch on a.m because the contract records resources an entry point, and a branch would make every variant carry the widest one's registers. nvfp4_columns prefetches DEPTH chunks into registers and fetches the next before the group loop consumes the held one. On gfx1151 at a 5120 x 5120 layer, m = 1: 0.0969 ms against 0.2516 ms reading each chunk in place, 2.6x, and 0.0580 ms for the prefetched form that follows the guard - 282.5 GB/s, 17.5x the single-chunk form. A guard clause that returns early measured 2.6x slower at 22 VGPRs against 33, so the prefetch sits after the guard rather than replacing it. Against the product on the same host, m = 1: attention 5120 x 1024 14.86x, gate/up 5120 x 17408 4.96x, down 17408 x 5120 7.79x, lm_head 5120 x 151936 5.22x. At m = 2: 13.71x, 4.86x, 8.85x, 4.90x. Row variants at 5120 x 5120: m = 1 9.81x, m = 2 9.92x, m = 3 7.33x, m = 4 7.03x, every one bit-identical to the tile. A K that is not a multiple of 64 keeps its tail on tf_nvfp4_gemm. build/hip.zig's headers list becomes hip_headers.zig, which walks every .hpp under zig/kernels/hip instead of naming them. The list it replaces had gone three headers out of date - quant/nvfp4.hpp, nvfp4_tiles.hpp and fp8_tiles.hpp were missing - so an edit to one left the .hsaco that includes it stale, and the four new symbols then failed to resolve in affine_tiles although they were compiled. A walked list cannot be left out of, and hip.zig loses ten lines to it. The product records name the tile's measured LDS on the four served chips. `hip-kernel-contract-limits` on gfx1030, gfx1100, gfx1151 and gfx1201 after the 64 x 64 tile and the 16-row decode block: the tile stages a column chunk in LDS, so NVFP4 holds 16384 bytes (was 11264) and FP8 18432 (was 12288), and FP8's scale and accumulator registers moved with it. The four column entry points' records, measured on the same run (VGPRs / SGPRs / LDS bytes): - tf_nvfp4_gemm: 138/38/16384, 144/38/16384, 144/38/16384, 143/36/16384. - tf_fp8_gemm: 58/49/18432, 56/49/18432, 56/49/18432, 58/48/18432. - tf_nvfp4_col1: 130/22/0, 138/22/0, 138/22/0, 138/23/0. - tf_nvfp4_col2: 164/26/0, 165/26/0, 165/26/0, 164/28/0. - tf_nvfp4_col3: 148/31/0, 145/30/0, 145/30/0, 147/34/0. - tf_nvfp4_col4: 121/32/0, 141/32/0, 141/32/0, 144/38/0. All 24 ModelOpt lines read "record current" on all four chips, and the run's problem count is the same as before this branch: 799 on the base and 799 here, every line of them predating it. Main's prompt tail names the shared handle's dense tag (prompt_tail.zig:63); the handle is optional here, so it asks the projection's format instead.
A single-format ModelOpt FP8 checkpoint declares quant_algo FP8 and carries no config_groups, so the config check fell through to the NVFP4 branch and refused it before the FP8 tensor reader ran. admit and admitRecipes now take one rule through singleFormat: NVFP4 checked as ModelOpt writes it, plain FP8 accepted per tensor. Sharing the one rule keeps the two entry points from drifting, and every other algorithm is still refused by name; the grouped FP8 formats are named MXFP8 and FP8_PB_WO and stay refusals by module. The Qwen-shaped MTP head always splits the fused mtp.fc, but the FP8 split returned UnevenSplit. It now cuts the codes into two contiguous halves along K, keeps every row in order, and shares the projection's one F32 scale between them. Tests: both entry points admit one ModelOpt FP8 config fixture, an INT4_AWQ fixture is still refused by name, and an FP8 fused FC beside the pre-FC norms checks both halves' shapes, code bytes and the shared scale. zig build test: 6528 passed, 168 skipped, 0 failed.
…endencies The HIP code objects' dependency scan walked only .hpp, so a group source's own include was untracked: attention.hip brings in attention/attention_fa.hip, and an edit to that include could reuse a stale code object until a clean rebuild. The scan now reads every kernel source under the root and tracks the files it includes, resolved beside the including file first as clang reads "...", then at the -I root, so a later include is covered without a list to update. hip_headers.zig's walk becomes a pure collect(allocator, io, root), tested on a synthetic tree: a .hpp and an included .hip are tracked, a compiland that nothing includes is not. A test-hip-headers step joins `test` and runs without -Dhip, so a dropped include fails in CI as well as on the next edit. The singleFormat comment is one line, as the lean rule requires.
The indexed file selection kept only shards holding model.language_model.* or lm_head.*, and always returned an empty side list. A ModelOpt checkpoint whose declared mtp.* tensors ship in their own indexed shard or in an mtp*.safetensors side file therefore lost the head: Checkpoint.mtp reopened the model's shards, found no MTP norm and returned null without an error. indexed() now takes whether to keep the head, adds the shards holding mtp.* and the mtp*.safetensors files beside them, leaving an mtp-named file out of the model list so a tensor is not counted twice. mtp() looks through the side files and then the model's own shards and only returns null when neither holds a norm, so a head that ships apart is found and one that is absent is still silent. Checkpoint.open passes the config's ModelOpt flag, so the same selection feeds the preflight. deviceBytes counted every stored byte, doubling only E4M3 group tables. Norms, A_log, dt_bias and conv weights read through projection.float, centred and conv, which produce F32 tensors, and the uploader allocates those lengths: a BF16 norm of N elements costs 4N on the device, not 2N. Each conversion is now counted against the tensor's own value count, and the MTP shards and side files are counted with the rest. Tests: an indexed MTP shard and an mtp side file each reach Checkpoint.mtp, and each fails before the selection change; a BF16-to-F32 case beside the existing table and embedding test.
… rule The lean rule's 600-line limit fails on the current base: engine.zig reached 602 lines and native.zig 617. The no-GPU lean step reported two problems the base lacks and the zig job failed before any test ran. The layer-cancel poll moves to prompt_poll.zig: the Poll struct, its layer hook and the trace that decides whether a pass can stop. The engine keeps Cancel and Poll as aliases and forwards poll in one line, so hip_lanes and the nemotron family see the same shapes they did. The port also carries the base's edge-event handoff: one layer stays queued while the previous one's edge is awaited, and a cancel still drains before error.Cancelled. The four config-only refusals move to native_refusals.zig: decisionOnly, oneRank, bf16Drafter and the Refused/refuse/gibs they need. They read the checkpoint's config and never touch a device, so nothing about admission or loading changes. Refused is re-exported, so native/hip.zig's error.Refused tests are untouched. No behavior change: every moved body is byte-for-byte the same. lean check against the rebased base: 0 new problems; engine.zig 597 and native.zig 582 lines. zig fmt --check and zig ast-check pass on all four files.
The rebase joined upstream's unused-tensor refusal with this branch's side-first MTP table search: the refusal named `side`, but this function reaches the shard sets through `c.files.side` and declares no such local. The Windows `zig build test` step could not compile checkpoint.zig. Use `c.files.side` in the refusal, matching the search above it.
…counters One presence test on Files now decides the source for Checkpoint.open, textBytes and deviceBytesAt, so a bf16 checkpoint's text count can no longer disagree with what its loader reads. A head the loader refuses (declared mtp_layers) is counted by neither, and an embedded language_model.mtp head is counted once, from the shards that hold it.
The loader kept its own presence test for a side or model-shard head (mtp.norm_e.weight or mtp.pre_fc_norm_embedding.weight), while Files.mtpSource took any `mtp.` key. The two disagreed on malformed layouts: - a side file with `mtp.` tensors but neither norm loaded as "no head", while preflight counted its bytes; - a stray `mtp.` tensor in the model shards made the main table the source, and the loader then failed on a missing norm where main returns null. mtpSource now selects a shard set by those first norms (isMtpNorm, the names readMtp reads for every head it accepts): the side files first, then the model shards, unprefixed (the main table) before `language_model.`. A set holding `mtp.` tensors but neither norm is refused with error.MtpHeadWithoutNorm and one message naming the file and both norms. Checkpoint.open, deviceBytesAt and textBytes all call it, so the loader and preflight refuse together. The loader's side check calls the same names (Table.hasMtpNorm). Well-formed checkpoints keep their source and totals: every layout in mtp_source_test.zig is unchanged, and a head readMtp can read always holds one of the two norms. Tests: a side file of mtp tensors without a norm, and a stray mtp tensor in the model shards, are each refused by Checkpoint.open, the preflight source and the byte counters; both fail on #2490's head.
…to the kernels' u32 unfit took 2 * weight.shape[1] and scale.shape[1] * 16 unchecked, so a header-only empty tensor (shape [0, 2^63] or a scale [0, 2^60], which the safetensors parser accepts as no bytes) wrapped to K = 0 and passed every check; view repeated the products and cast N and K to u32, a panic for an empty [2^33, 0]. unfit now multiplies with std.math.mul and refuses past 2^64, refuses N or K at 2^32 or more (the kernels take u32), and read names the weight in the refusal; view checks the same products and casts with std.math.cast, refusing as UnsupportedTables. A host test builds header-only safetensors files with those shapes and checks each reason.
…s core projection Main's hip_prompt_test.zig (8c14c27) sets e.weights.embed to .{ .mlx = undefined } and .{ .bf16 = undefined }, written while a Projection was quant.Device itself; #2490 makes it a union whose core arm holds that Device beside nvfp4 and fp8, so those four lines now say .{ .core = .{ .mlx = undefined } } and .{ .core = .{ .bf16 = undefined } }. Engine.plain reads the format through .core, so each test checks what it did on main.
…gs write it, is no extra scale The published Ergo configs (the release, its bf16 copy and the TFQ checkpoint) all write "global_attention_scale": null. Vulkan's published-field reader took it as a number and refused every one with InvalidErgoConfig_global_attention_scale, so no published Ergo checkpoint loaded on Vulkan. A present null now reads as 1.0, as mlx_tf reads it (and #6037's readers): a global layer's attention scale is then the local one exactly. The key must still be present, and a wrong type is still refused by name. The null-refusal test skips this one field; a new test parses a null scale as 1.0 and checks a global layer's attention scale equals a local layer's.
Move complete methods without body edits. Extract the oversized init resource tail into one helper on the same Context; retain parent cleanup guards and resource creation order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI for a landing train: #2490 #6190 #6197 stacked on main in that order. Nothing merges from this PR: each PR above lands on its own once this tip is green, and this PR is then closed.