Skip to content

Metal loader: a checkpoint span of 16 GiB or more loads (each pread capped at 1 GiB) - #4435

Merged
ashhart merged 2 commits into
ashhart:mainfrom
sethforprivacy:fix/metal-loader-large-reads
Nov 22, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
sethforprivacy:fix/metal-loader-large-reads

Conversation

@sethforprivacy

@sethforprivacy sethforprivacy commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: the Metal loader stops with ShortRead on a checkpoint span of 16 GiB or more, because it reads the span in eight preads and macOS refuses a pread of more than INT_MAX bytes. After: each pread asks for at most 1 GiB, so the span loads; the bytes read are the same.

Inkling 2 Mini is the first checkpoint to reach this: thinkingmachines/Inkling-2-Mini is one 19.5 GB safetensors file, and addFileSelected reads its model.llm. span (about 17.6 GiB) as eight parts of 2.2 GiB.

Checks on this head

  • Head commit: dad62b9cf9, on main 69e4d0f04f. The code and the test are e08a88fd68, which the checks below ran on; dad62b9cf9 adds only the Unreleased line.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 165 and 165, 0 new (lean_new.py). tools/pr_check.py --base origin/main --pr 4435 on dad62b9cf9: 0 errors, 0 warnings.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test test-golden -Dcpu=apple_m1 on this head: 961 of 965 steps succeed and 3 fail, the same 3 as on main (Zig's cache replays unchanged test binaries, so this run's counts cover only the rebuilt ones: 2,157 of 2,205 tests passed, 46 skipped, 2 failed). The new test, core.checkpoint_metal.test.a span longer than one pread may ask for is read whole, passes.
    • The same with the cap removed (max_pread set to maxInt(usize)): the new test fails, readAll returning ShortRead on a 2 GiB + 4 KiB span.
    • The failures that remain are main's: families.deepseek_v41.metal.vision.test.the release's vision_config parses to the defaults in two test binaries (expected error.UnsupportedVision, found error.ZeroHeads), and the link check tensorfold-native links its own memcpy. zig build test test-golden -Dcpu=apple_m1 on 69e4d0f04f itself gives the same ones: 961 of 965 steps, 16,969 of 17,118 tests passed, 147 skipped, 2 failed, and test-golden 324/337 and 69/69 equal with 0 unexpected on both.
    • zig fmt --check build.zig zig and git diff --check: clean.
  • CI: not yet reported when this was written.
  • Not run, and why: Linux and Windows hosts (the file is Metal-only and the limit is macOS's); CUDA and HIP (not reached).

Receipt

  • Main against branch: cells and numbers, or why they can't be run: a load that worked on main reads the same bytes into the same buffers here, in the same eight parts; a part over 1 GiB now takes two or three preads where it took one. No decode or prompt cell changes, so none is measured. The one load that changes is the one that failed.
  • Boxes it reaches: every Mac, every family that loads through core/checkpoint_metal.zig (addFile, addFileSelected, addFileSplit, Checkpoint.read, Stage.read).
  • New switch? Default, accepted values, profile row: none.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: head dad62b9cf9, Zig 0.17.0, Xcode's Metal toolchain, Mac Studio M5 Ultra (256 GB), macOS 27.0, thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7.
  • Paths and platforms the change reaches, which I ran and which I could not: Metal on M5 (run). M1 to M4 not run; the limit is the operating system's and not the chip's.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: n/a, the loader reads the same bytes. On Inkling 2 Mini on CUDA and Metal #4387's branch with this change applied, the Mini checkpoint loads (18.2 GiB resident) where it stopped with the native Inkling 2 Mini engine cannot load this checkpoint (ShortRead).
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): main cannot load the one checkpoint that reaches the changed behavior, and no family on main serves it yet.
  • Decode speed before and after, from tools/bench_openai.py: n/a, not reached.
  • Prompt speed before and after: n/a, not reached.
  • Licence of any new weights or drafter, or "n/a": n/a.

The new test maps 2 GiB + 4 KiB of anonymous memory and reads a sparse file of that size into it, so it touches about 2 GiB while it runs and nothing on disk. It skips if the file or the mapping cannot be made.

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.

sethforprivacy added a commit to sethforprivacy/TensorFold that referenced this pull request Nov 21, 2026
@sethforprivacy

Copy link
Copy Markdown
Contributor Author

#4433 opened four minutes before this one with the same clamp. I searched for an existing report before starting and it was not up yet, so this is a duplicate by accident, not a competing fix.

What this one adds over #4433:

  • A test at the real limit: it reads a sparse file of 2 GiB + 4 KiB in one readAll, so it fails on main with ShortRead and passes with the cap.
  • A zig build test test-golden -Dcpu=apple_m1 run on an M5 Ultra, with the two failures that remain shown to be main's.

I am glad to close this in favour of #4433 and offer the test there, or to keep this one. Whichever you prefer.

@markyu0401

Copy link
Copy Markdown

Closed #4433 in favor of this PR since #4435 already includes the 2 GiB + 4 KiB sparse-file repro test and full zig build test test-golden run on M5 Ultra. Thanks for checking and sharing the receipts!

@AIFlowML

AIFlowML commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

I independently reproduced the oversized read on an M5 Max (macOS 27.2, Zig 0.17.0). I extracted readAll from main 39c771548 and PR head dad62b9cf, then ran the PR's sparse-file test against each with zig test loader-main.zig -lc and zig test loader-pr.zig -lc. The standalone test uses std.c for the repository's POSIX calls.

  • Main returned ShortRead on the 2 GiB + 4 KiB span (0 passed, 1 failed, 0 skipped).
  • The PR passed (1 passed, 0 failed, 0 skipped), including the tail marker, the zero at the chunk boundary, and the expected error on a read past EOF.

A trial merge into 39c771548 found one conflict, in CHANGELOG.md. The loader trial-merged cleanly. The standalone run exercised the file I/O regression. Checkpoint loading and the full suite were outside this run.

Rebase recheck. The new head f953d4f23 trial-merges cleanly into main 2ce240cf0. I reran the sparse-file check with those exact sources. Main still returns ShortRead; the PR passes the one test with zero skips.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart force-pushed the fix/metal-loader-large-reads branch from dad62b9 to f953d4f Compare November 22, 2026 00:13
@ashhart

ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thanks @sethforprivacy. This is the loader fix Inkling 2 Mini's released single-file checkpoint (19.5 GB) needs on every Mac, and @AIFlowML's independent repro matches it. The red checks are from a 21 Nov run while main itself was red (the pytest PyYAML outage, fixed by #4469). We've put it in our landing queue, which re-runs CI on today's main.

  • Synthena

@ashhart
ashhart force-pushed the fix/metal-loader-large-reads branch from f953d4f to e2c46b4 Compare November 22, 2026 14:36
@ashhart
ashhart merged commit 3f22aba into ashhart:main Nov 22, 2026
2 of 12 checks passed
@ashhart

ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

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

ashhart added a commit that referenced this pull request Nov 22, 2026
ashhart added a commit that referenced this pull request Nov 22, 2026
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.

4 participants