Skip to content

Metal text-only loads hold no LFM3-VL vision weights: the tower and projector stay on disk - #3420

Merged
ashhart merged 5 commits into
ashhart:mainfrom
jschmied:metal-text-only-vision
Nov 24, 2026
Merged

ashhart merged 5 commits into
ashhart:mainfrom
jschmied:metal-text-only-vision

Conversation

@jschmied

@jschmied jschmied commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Branch metal-text-only-vision @ 6a77a0efa6, on main 9832561571 (rebased by the maintainer). Family-only: families/lfm3/model.zig, plus
its test import in tensorfold.zig.

Scope after review: Step-5 is split out, as asked (it waits for a box that can load Step-5-Preview). The Gemma 4 part is dropped: since
#3350, main's gemma4/model.zig:101 reads each shard with addFileSplit(.., "language_model.", weights.later), so a text-only Gemma 4 load
already holds no tower on main. This PR's Gemma addShard was called only by its own test. Measured on the Mac below: Gemma 4 12B
footprint and replies are identical on main and on the previous head 0a6e0c563f.

Problem, measured

LFM3-VL on Metal: addFile reads every tensor, so the tower and projector, which no Metal kernel runs, stay resident. LFM3-VL-2B MLX
4-bit: 0.353 GiB.

Change

  • lfm3: addShard: a VL shard packs only its text namespaces, wrapped language_model. and bare model. (one
    addFileSplit(.., prefix, never) each). vision_tower./multi_modal_projector. stay on disk. A text checkpoint loads exactly as before
    (addFile). A shard holding both namespaces still loads both, and metal_weights.load refuses it (MixedNamespaces), as on main.
  • No core change, no kernel change. CUDA and HIP read their own way and are untouched.
  • Refusals: no new refusal. The Metal server refuses LFM3-VL on main and here alike ("LFM3-VL inference requires the stacked vision
    contribution").
  • Device test: a synthetic shard in LFM3-VL's order (text tensor, projector, tower), wrapped and bare: the old read holds everything, the
    new one only the 4 text bytes, byte-equal to the old read's. Planted control: with the selector back to language_model. only, the bare
    case fails ("expected 4, found 0"); red on a3f3ba2, green since 733eae3.

Evidence (M3 Pro 36 GB, macOS, Zig 0.17.0, -Dcpu=apple_m1; main = 9832561571)

Measured at 0a6e0c563f; families/lfm3/model.zig and tensorfold.zig are byte-identical between that head and 6a77a0efa6 (the last
commit only reverts the Gemma files). md5 tf-lfm3-forward: main 0871684ae8e9c2b0, head 3b9d0f5af95a90e8.

LFM3-VL-2B MLX 4-bit via tf-lfm3-forward (the Metal server refuses LFM3-VL, so seeded/resumed/concurrent served replies do not apply
to it on main or here; the forward tool is the only Metal path that loads it):

300 tokens, peak footprint main this change
wrapped, text only 1,794,295,656 B 1,413,940,880 B -0.354 GiB
wrapped, 16 image rows -0.353 GiB
bare model.* copy, text only 1,792,657,304 B 1,413,777,040 B -0.353 GiB
bare, 16 image rows -0.353 GiB
  • Logits byte-identical to main, wrapped and bare: text only c6b2ad7d3ec6bf46, 16 injected image rows 44a135c313cdb9c9 (the
    image-enabled path: rows are injected, no Metal tower exists for LFM3-VL).
  • Resident tensor names after load (scratch count, not the measured binary): vision_tower./multi_modal_projector. main 138 of 732,
    this 0 of 594.

Gemma 4 12B (unchanged by this PR now, shown against the dropped part): 16K window, no --vision: 7,334,952,960 B idle and after an
8,540-token prompt, both rounds, main and 0a6e0c563f; resident vision_tower./embed_vision. names 0 on both. Replies equal
(token_sha256, 64 tokens): greedy and seeded (T=1, seed 7) at 8.5K and 29.6K prompt tokens, a resumed turn 2 (2,048 cached) equal to a
fresh server, concurrency 1 = 4 = 8. --vision refuses the 4-bit embedder on both arms alike (UnexpectedGemmaVisionTensor).
These Gemma rows are context for dropping that part, not a claim of this PR; no parity_controls.py line was taken for them.

Checks:

  • Mac at 0a6e0c563f: lfm3 and gemma4 host steps 99/99 (889/903 tests, 14 skip). The LFM3 device test passes.
  • zig build test on the Mac: the main test root fails to compile on main 9832561571 and here alike, 6 errors
    "Only nullable and allowzero pointers can be set to zero" from std.mem.zeroes in families/uocr/serve.zig:246/288 (uocr cancel tests).
    This PR does not touch uocr. With those 3 tests skipped locally: 1000/1000 steps.
  • x86 (-Dfixed-cpu) full CI set at 6a77a0efa6: green: 2467/2467 steps, 25069/25226 tests (157 skipped), check-native-cuda-host compile-cuda-tests 17/17, pr_check, zig fmt --check, git diff --check, lean 0 new (165/165).

Proposed CHANGELOG line

  • Metal servers no longer hold an LFM3-VL checkpoint's vision tower and projector, which no Metal kernel runs: 0.35 GiB less on LFM3-VL-2B.
    Logits are unchanged.

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

FIXES. @jschmied, the packing checks pass and the measured loads retain less memory. Gemma's 32 text replies and the official VL checkpoint's raw prompt, prefix and last-row logits remain bit-identical.

P2 at zig/src/families/lfm3/model.zig:109: the new VL filter keeps only language_model., while the existing admission and Metal weights loader also accept bare model.. An actual loader regression validates all 594 bare VL tensor entries, then shows addShard dropping model.embed_tokens.weight. The old reader retains it, so a previously accepted raw model layout now reaches MissingTensor. Please preserve both accepted text namespaces while excluding vision, and add a bare-VL regression. The served VL refusal is inherited on both arms.

The reported 31B saving and real Step-5 load still need device receipts. CI at this head also needs to be green.

  • Synthena (Ash's Agent)

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart Fixed in 733eae3: addShard keeps both text namespaces (language_model.* and bare model.*) and still leaves vision_tower./multi_modal_projector. on disk. The device test now covers a bare shard; it fails on a3f3ba2 and passes here. On a bare copy of lfm3-vl-2b-4bit (594 entries renamed), main loads, a3f3ba2 stops at MissingTensor, and 733eae3 loads with text and image logits byte-identical to main and to the wrapped checkpoint, peak footprint 0.353 GiB lower.

We can't produce the other two receipts here: the 31B does not load on main on a 36 GB Mac until #3350 lands, and Step-5-Preview needs a 256 GB Mac. Both stay header count plus device test, as the body says. Body updated to the new head; CI is running on it.

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart CI at 733eae3: everything passes except one test in the Linux zig job, 1 of 18,899: bringup_test.zig:97 "two ranks settle on the real clock and agree on one plan and view" (x.view == y.view differs). The push changes lfm3/model.zig only, which the cluster module doesn't import; the same job passed at a3f3ba2, and the test passes locally at this head (37 pass, 1 skip). It runs two ranks on the wall clock, so it looks timing-dependent; the same test also failed in #3294's CI run today. I can't re-run jobs on this repository; could you re-run the failed job?

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

DEVICE. @jschmied, the bare namespace fix closes the loader defect. Both accepted text namespaces now retain their bytes while leaving the tower and projector out. The real allocation regression passes for both layouts.

CI's zig job fails at this head; it needs to be green. We will run the remaining 31B and Step-5 load checks on our side, keeping their memory counters and exact replies separate from the already measured 12B and LFM3 results.

  • Synthena (Ash's Agent)

@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart Thanks. The zig job at 733eae3fe has one failure, in cluster/bringup_test: "two ranks settle on the real clock and agree on one plan and view; a goodbye ends the other's watch by name". Every other test in the job passes. This PR changes no file under zig/src/cluster. The test runs on the real clock, and #3377 hit the same failure on its CI run (comment), so I read it as runner timing.

I can't re-run upstream jobs. Could you re-run zig at this head?

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@jschmied, the 31B text-only load check passes on an M5 Ultra. Actual Metal allocation falls from 51,958,824,960 to 51,010,355,200 bytes, saving 0.883 GiB. All 1,654 retained text tensors match in metadata and payload bytes, and all 160 full replies match main across greedy and sampled, thinking on and off, plain solo and concurrent drafted requests.

The Step-5 text-only load and exact-reply check remains to be run on our side before that part is qualified.

  • Synthena (Ash's Agent)

@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

I reran test-step5-host compile-step5-host test-lfm3-host test-gemma4-load-parts-host with Zig 0.17.0 on M5 Max (-Dcpu=apple_m1 -j5 --summary all). I also used a local test filter on the real Metal engine to run the three synthetic shard-loading cases. At 733eae3fe, that combination passed 109 tests with zero skips. The Step-5 fixture exercised both values of the tower flag and checked that the text-only path keeps the tower and projector out of the resident checkpoint.

In the trial merge into 124052c97, the only conflict is zig/src/families/gemma4/model.zig, where the two branches add different tests at the end of the file. Keeping main's failed-tower-load test and this PR's addShard and packing test let the same checks pass with the extra test selected (114 passed, zero skips). This gives a device-backed synthetic Step-5 load receipt. The full Step-5 checkpoint and reply equality still need the larger Mac.

On 86cfd1451, the trial merge into 37fa51d23 passed all 51 host tests. A scratch filter on the real M5 Metal engine passed all 62 tests, including the LFM3 fixture with both language_model.model.* and bare model.*, the Step-5 tower opt-in, and the Gemma shard packing case. The trial merge also remains clean on 5f53c445e, with the tested family sources unchanged. These runs used generated shards.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart force-pushed the metal-text-only-vision branch 2 times, most recently from 86cfd14 to 25466d5 Compare November 22, 2026 00:28
@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged this head 25466d5da into main 2ce240cf0, then added #4435 at f953d4f23. Both merges were clean. On an M5 Max with Zig 0.17.0, test-step5-host compile-step5-host test-lfm3-host test-gemma4-load-parts-host plus a scratch filter on the existing Gemma, LFM3, Step-5, and sparse-read Metal fixtures passed 67/67 build steps and all 116 tests.

As a negative control, I changed only the scratch LFM3 selector back to language_model. and reran the same device filter. The wrapped-or-bare regression then failed with expected 4 resident text bytes, found 0. It passed on the combined trial. This covers the namespace fix and its interaction with the bounded reads on synthetic shards. I did not rerun the full checkpoints or measure their residency.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks, @jschmied. The bare text-namespace regression is fixed, and both accepted text layouts retain their bytes without the tower or projector. The Step-5 option wiring also looks correct: text-only loading defers the vision tensors and skips tower construction, while enabling vision preserves the old read path.

The remaining qualification is a full Step-5 checkpoint, not another synthetic shard. Please record the text-only allocation, confirm that no vision tensors remain resident and tower construction is skipped, and compare exact greedy and seeded replies, resumed turns and concurrent output against the current baseline. An enabled-vision compatibility run and fresh green CI at the final head are also still needed.

No further source defect was found in the LFM3 or Step-5 paths.

  • Synthena

@jschmied

Copy link
Copy Markdown
Contributor Author

Thanks. A full Step-5 run is out of reach on our side: stepfun-ai/Step-5-Preview is 604B parameters (about 600 GB of FP8 weights), and our largest Metal box is an M3 Pro with 36 GB. Neither it nor the GB10 can load it, so the full-checkpoint qualification would have to come from a machine that holds the model.

What I can do here, on head b270b86d70:

  • the Gemma 4 and LFM3-VL rows on real checkpoints (the text-only allocation, no vision tensors resident, tower construction skipped, plus greedy and seeded replies, resumed turns and concurrent output against main, and an enabled-vision run), run on our Mac;
  • fresh green CI at this head.

Should I post those and leave the Step-5 line to whoever can load it? Or would you rather split Step-5 out of this PR so the Gemma 4 and LFM3-VL parts can land on their own?

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied, that makes sense. Nobody we work with can load Step-5 either.

Please split Step-5 out of this PR. The Gemma 4 and LFM3-VL parts can then land on the receipts you described: text-only allocation with no vision tensors resident and the tower skipped, greedy and seeded replies, resumed turns and concurrent output against main, an enabled-vision run, and fresh green CI at the final head.

Keep the Step-5 change as its own PR with its host tests. It can wait there until someone with a machine that holds the model can check it.

  • Synthena

@jschmied jschmied changed the title Metal text-only loads hold no vision weights: Gemma 4 and LFM3-VL keep only their language model, Step-5 reads its tower only with --vision Metal text-only loads hold no LFM3-VL vision weights: the tower and projector stay on disk Nov 24, 2026
@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart Done at 6a77a0efa6.

  • Step-5: split out. It is kept on its own branch with its device test, to go up as its own PR.
  • Gemma 4: dropped from this PR. Since Gemma 4 on Metal holds each linear's bytes once: the 31B 4-bit loads in 17 GB of GPU memory, not 48 #3350, main already reads Gemma 4 shards with addFileSplit(.., "language_model.", weights.later), so a text-only load holds no tower on main. This PR's Gemma addShard was only called by its own test. On the
    Mac, Gemma 4 12B has the same footprint (7,334,952,960 B), 0 resident tower tensors, and equal replies on main and on the previous head.
    The replies covered greedy, seeded, resumed and concurrency 1/4/8.
  • LFM3-VL-2B (the only change left): peak footprint 0.353 GiB lower, wrapped and bare. Resident vision_tower./multi_modal_projector.
    tensors go from 138 to 0. Logits are byte-identical to main, text only and with 16 injected image rows. The Metal server refuses LFM3-VL
    on main and here alike, so served seeded, resumed and concurrent replies don't apply to it.
  • zig build test on the Mac fails to compile on main 9832561571 too:
    std.mem.zeroes in families/uocr/serve.zig:246/288. That is
    main's, not this PR's. x86 full CI set at this head: green: 2467/2467 steps, 25069/25226 tests (157 skipped), check-native-cuda-host compile-cuda-tests 17/17, pr_check, zig fmt --check, git diff --check, lean 0 new (165/165).

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. Splitting Step-5 and dropping the redundant Gemma change leaves a clear LFM3-only patch. Both text namespaces are retained, and the packing regression plus real allocation and byte-equal forward results cover that scope. The final CI results are noted.

This is ready on current main. The native server still refuses VL there, so another served-image or full Step-5 run is not owed for this patch. The separate vision integration will need its loader to retain or defer the tensors that its tower reads.

  • Synthena

jschmied and others added 5 commits November 24, 2026 22:10
…k their language model, Step-5 reads its tower only with --vision

- Gemma 4: each shard's language_model. tensors pack into their own buffer, not the file span that holds the 31B's
  vision tower (0.88 GiB); the tower still loads apart with --vision.
- LFM3-VL: the language model packs alone; the tower and projector no Metal kernel runs stay on disk (0.35 GiB).
- Step-5: without --vision the tower and projector stay in their files and no tower is built; with it, as before.
…t loads again, still without its tower

addShard selected language_model. only, so a VL checkpoint in the bare model.* namespace, which metal_weights.load
accepts, lost model.embed_tokens.weight and stopped at MissingTensor. It now reads both prefixes; vision_tower. and
multi_modal_projector. stay on disk as before. The device test runs a wrapped and a bare shard.
The Step-5 loader change (model.load's tower flag, addShard and its device test) returns to main's code and moves to
its own branch, as asked in review. Gemma 4 and LFM3-VL are unchanged.
Since ashhart#3350, gemma4/model.zig reads each shard with addFileSplit(.., "language_model.", weights.later), so the tower is
not held on main; this PR's addShard was only called by its own test. The PR now covers LFM3-VL only.
@ashhart
ashhart force-pushed the metal-text-only-vision branch from 6a77a0e to 863a826 Compare November 24, 2026 22:10
@ashhart
ashhart merged commit d66b998 into ashhart:main Nov 24, 2026
1 check failed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. 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.

BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Nov 25, 2026
…s on disk

Since ashhart#3420 a VL checkpoint packs only its language model, so the vision opener stopped at MissingTensor.
Model.loadWithResidency takes the --vision choice: with it each shard loads whole, as before ashhart#3420; without it
the shard packs the same two text namespaces as main. The host test reads an official VL header through the
choice: the tower layout loads with --vision and is MissingTensor without it, the text set unchanged.
ashhart pushed a commit to BlivionIaG/TensorFold that referenced this pull request Nov 25, 2026
…s on disk

Since ashhart#3420 a VL checkpoint packs only its language model, so the vision opener stopped at MissingTensor.
Model.loadWithResidency takes the --vision choice: with it each shard loads whole, as before ashhart#3420; without it
the shard packs the same two text namespaces as main. The host test reads an official VL header through the
choice: the tower layout loads with --vision and is MissingTensor without it, the text set unchanged.
ashhart pushed a commit to BlivionIaG/TensorFold that referenced this pull request Nov 25, 2026
…s on disk

Since ashhart#3420 a VL checkpoint packs only its language model, so the vision opener stopped at MissingTensor.
Model.loadWithResidency takes the --vision choice: with it each shard loads whole, as before ashhart#3420; without it
the shard packs the same two text namespaces as main. The host test reads an official VL header through the
choice: the tower layout loads with --vision and is MissingTensor without it, the text set unchanged.
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.

3 participants