Skip to content

checkpoint_metal: clamp pread chunks to INT_MAX - #4433

Closed
markyu0401 wants to merge 1 commit into
ashhart:mainfrom
markyu0401:fix/checkpoint-metal-pread-clamp
Closed

markyu0401 wants to merge 1 commit into
ashhart:mainfrom
markyu0401:fix/checkpoint-metal-pread-clamp

Conversation

@markyu0401

Copy link
Copy Markdown

What this changes

Clamps each pread(2) call in checkpoint_metal.zig (readAll) to std.math.maxInt(i32). Before: loading a large single-shard safetensors file (such as an 18+ GiB checkpoint where each of the 8 readParallel threads requests >2 GiB) fails on macOS/Darwin with EINVAL and surfaces as error.ShortRead. After: readAll delegates to readAllBounded(..., std.math.maxInt(i32)) and loops across bounded chunks until the full slice is read, with a host-only unit test covering multi-chunk reads and error.ShortRead on EOF.

  • Issue: n/a (encountered while loading the single-shard thinkingmachines/Inkling-2-Mini checkpoint on macOS; no existing issue for checkpoint_metal pread INT_MAX clamping).
  • Stacked on: main (69e4d0f04).
  • atc overlap --json: ran against upstream/main (69e4d0f04) on 2026-11-21 — changedFiles: 1, conflict: "clean" across #4387, #3859, and #3379 (complete: false due to otherPullRequestsLimit, pullFilesUnavailable, pullRequestsLimit, timeLimit).

Checks on this head

  • Head commit: c2eda27ad00ac77e02b4bfd2e3cf7fc854544528
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 165 on base (69e4d0f04), 165 on head (c2eda27ad), 0 new findings (python3 tools/pr_check.py --base upstream/main -> 0 error(s), 1 warning(s) for the missing PR-numbered CHANGELOG.md Unreleased bullet).
  • Tests run, with the command and pass, fail and skip counts: git diff --check clean; python3 tools/pr_check.py --base upstream/main 0 errors.
  • CI: pending on PR creation.
  • Not run, and why: zig fmt --check build.zig zig and zig build test were not run locally on this host because Zig 0.17.0 is not installed in this environment; waiting for GitHub Actions CI (zig-fmt and no-gpu) on this PR head.

Receipt

n/a — checkpoint file I/O bugfix only; does not modify inference kernels, scheduling, sampling, or arithmetic (loaded tensor bytes are unchanged).

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.

Darwin's pread(2) rejects nbyte > INT_MAX with EINVAL, so reading a large single-shard safetensors file (such as an 18+ GiB checkpoint where each of the 8 parallel read threads requests >2 GiB) fails with error.ShortRead. Delegate readAll to a bounded loop clamped to std.math.maxInt(i32), and add a host-only unit test exercising multi-chunk reads and EOF detection.
@markyu0401

Copy link
Copy Markdown
Author

Closing in favor of #4435, which fixes the same macOS pread > INT_MAX issue and already includes a 2 GiB + 4 KiB sparse-file repro test along with a full zig build test test-golden receipt on M5 Ultra.

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.

1 participant