Skip to content

docs/research: Metal for every model, and offload on unified memory - #802

Merged
midagedev merged 2 commits into
mainfrom
mac-allmodels
Oct 25, 2026
Merged

midagedev merged 2 commits into
mainfrom
mac-allmodels

Conversation

@midagedev

@midagedev midagedev commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Two design docs for #593 (every model on Apple Silicon, offload included). Docs only; no code.

  • metal-all-models.md: the op map (77 kernel needs over 18 models, 41 shared by two or more), the cover order by Mac size, geometry from the file as build-time instances, the chain lift, a proof path on fixtures, and the phases. Phase 1 is 1-0 (MiniCPM-V, Sage, Ornith; host only), 1a (a header-only --plan, AIR hash and encode trace as the move proof), 1c (Qwen3.6 UD-Q4_K_XL).
  • metal-offload.md: measured working set (0.78 x RAM on three Macs), cold SSD reads (6.7 GB/s at QD >= 4), the host/GPU handoff, and the Pool tier on unified memory with its first round.

Both docs went through an adversarial re-review; the last section of each lists every finding and where it landed. Mac numbers are development-loop evidence.

The docs were written and reviewed with AI help (Claude Code); the maintainer reviews them before merge.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q5zTV27LbaVZFTjnkdmTjJ

metal-all-models.md: the op map (77 kernel needs over 18 models, 41
shared), the cover order by Mac size, shape from the file as
build-time instances, the chain lift, the fixture-only proof and the
phases (1-0 kin, 1a instruments, 1c UD, 1b-0/1b-1 instances and
Qwen3-30B, the seats track, the session lift).

metal-offload.md: the measured working set (0.78 x RAM on three Macs),
cold SSD reads, the host/GPU handoff, and the Pool tier on unified
memory with its first round and predictions.

Both carry their adversarial re-review in a last section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q5zTV27LbaVZFTjnkdmTjJ
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 25, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: The documents misstate the existing coverage API and Mac build support.

Must fix

1. Account for CUDA type checks before reusing check_with

docs/research/metal-all-models.md:680 assigns Metal coverage to check_with while Phase 1a promises no coverage.rs edits. But crates/model/src/arch/coverage.rs:1942 unconditionally calls weight_formats. Its Qwen35 head pin at line 1062 excludes MLX_A4, independently of the supplied operation rows. Passing Metal's Available table alone cannot meet Phase 1a's MLX success criterion.
Correct the API description before implementing against it (kind B). Replace the coverage claim with the following and make the Phase 1a scope, files and gates cells consistent:

`coverage::check_with` accepts operation rows but still applies CUDA's
routed-format rules and weight-type pins. Phase 1a must isolate Metal's
weight validation from those policies, checking Metal weights against
Metal-owned type rows while preserving CUDA's checks. If that separation
changes `coverage.rs`, include its owning CUDA checks in Phase 1a.
Completion requires Qwen3.6 Q4_K_M and MLX_A4 to pass, and an unsupported
Metal weight type to fail by name.

2. Correct the claimed Mac build blocker for the model seam

docs/research/metal-offload.md:197 says the Mac cannot build crates/model. Metal already declares that dependency specifically for macOS in crates/metal/Cargo.toml:75. pure-crates assesses the complete native test package, not just the library. A /sys path read is not a compilation blocker.
Correct this before scheduling an extraction on that premise (kind B). Replace the row:

| the seam to the model: `TierSlots`, `Claim`, `Ticket`, `TierError` | `crates/model/src/moe.rs:2479,2290`; impl `nvtier.rs:3641` | device-free; the Metal crate already depends on `crates/model` (`crates/metal/Cargo.toml:75`), although its complete native test suite is not in `pure-crates` | reuse the seam's existing owner when lifting the tier core | none |

Non-blocking

⚠ Match the bandwidth calibration to its quant: docs/research/metal-offload.md:226 combines UD's 2.753 GB/token with Q4_K_M's 85.6 tok/s. The companion table at metal-all-models.md:71 gives Q4_K_M as 1.976 GB/token: 169.1 GB/s, or 69.0% of 245 GB/s [derived, M4 Pro, depth about 0]. Use that calibration; label eta 0.75–0.90 as assumptions until workload-matched evidence supports them.

Checked

Duplicates: no new production items; record-kind definitions remain separate from the shared record core.
Complexity: no executable functions changed.
Silent failure: no executable error-handling changes.
Tests: no executable tests changed; no mutation run.
Gates: no existing gate or pin changed.
Escape catalog: C1–C4 do not match these documentation additions.

Notes

Dryer and crapper did not run because no Rust file changed. The cited external timing records and scratch probes are absent from these trees; their measurements could not be reproduced.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Filed outside this PR: #803

Comment thread docs/research/metal-offload.md Outdated
| arena memory: `ArenaMem` (`:139`), `ArenaKind::{Anon, Pinned}` (`:307`), `ArenaMem::pinned` (`:189`, `cuMemHostAlloc`) | `nvtier.rs:139-200,307-321,2126-2130` | the only CUDA-bound line group of the tier core (plus `issue_card_hold`) | a third kind `Shared`: an `AnonMap` wrapped by `makeBuffer(bytesNoCopy:)`, or the `MTLBuffer`'s own pages | no `MADV_DONTNEED` give-back (the refill overwrites in place; `tierengine.md:301`); one buffer is at most 0.585 x RAM, so one buffer per layer group |
| fill reader: `NVTIER_FILL_THREADS` 16, rank queue, one `pread` a part | `nvtier.rs:127`, `nvtier/reader.rs:1-16,321` (792 lines) | yes (`GpuError` only) | carries over; thread count is the measured queue depth (QD 4 reaches the plateau on both Macs) | the unit stays a part (3 a fill, ~1 MB each: QD 3 of 1 MiB parts = 5.2-5.7 GB/s [derived between QD 1 and QD 4 above]) |
| the O_DIRECT reader: `DirectFile`, `AnonMap`, `aligned_span`, `DIRECT_ALIGN` | `crates/engram/src/direct.rs:29,45,143,156` | yes | already runs: `crates/os/src/lib.rs:286` opens with `F_NOCACHE` on macOS | `DIRECT_ALIGN` is 4096 and Apple pages are 16 KiB; the probe above used 16 KiB alignment, 4 KiB-skewed `F_NOCACHE` reads are [unverified] |
| the seam to the model: `TierSlots`, `Claim`, `Ticket`, `TierError` | `crates/model/src/moe.rs:2479,2290`; impl `nvtier.rs:3641` | device-free but in `crates/model`, which the Mac cannot build (`workstation.rs:74` reads `/sys/fs/cgroup`; `tools/recipes.py pure-crates` rejects it) | the seam types move with the tier core | none |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metal already depends on the model library; native test-suite restrictions do not prevent that dependency.

Suggested change
| the seam to the model: `TierSlots`, `Claim`, `Ticket`, `TierError` | `crates/model/src/moe.rs:2479,2290`; impl `nvtier.rs:3641` | device-free but in `crates/model`, which the Mac cannot build (`workstation.rs:74` reads `/sys/fs/cgroup`; `tools/recipes.py pure-crates` rejects it) | the seam types move with the tier core | none |
| the seam to the model: `TierSlots`, `Claim`, `Ticket`, `TierError` | `crates/model/src/moe.rs:2479,2290`; impl `nvtier.rs:3641` | device-free; the Metal crate already depends on `crates/model` (`crates/metal/Cargo.toml:75`), although its complete native test suite is not in `pure-crates` | reuse the seam's existing owner when lifting the tier core | none |

… claims

- metal-all-models.md: check_with still applies CUDA's routed-format
  rules and weight-type pins (coverage.rs:1942, :1062), so Phase 1a
  isolates Metal's type rows from them; the move proof hashes each
  pipeline as built (a binary archive per pipeline), since neither test
  Mac has the Metal toolchain and both take the run-time source path.
- metal-offload.md: the Metal crate already depends on crates/model; the
  bandwidth calibration mixed UD's bytes a token with Q4_K_M's rate. On
  the design doc's two-term model, Qwen3.8's M4 Pro GPU term is 29.2 ms
  against the 28.7 ms the tables use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q5zTV27LbaVZFTjnkdmTjJ

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review:

  • Must-fix 1 fixed: Metal-owned type validation and conditional CUDA checks are explicit in §5.3 and Phase 1a.
  • Must-fix 2 fixed: the seam row now acknowledges the existing macOS dependency and reuses its owner.
  • Bandwidth calibration: the quant mismatch is corrected in the new text.

Verdict: CLEAN: Both earlier must-fix documentation errors are corrected, and the new changes introduce no proven defect.

Checked

Duplicates: 0 new executable items; no new duplicate owner. No dryer pairs were produced.
Complexity: no executable functions changed; no crapper functions were flagged.
Silent failure: 0 changed executable sites; the plan requires unsupported weight types to fail by name.
Tests: no executable tests changed; no mutation run. Recomputed the revised bandwidth and latency arithmetic.
Gates: no existing gate or pin changed. The proposed hash requires a determinism probe, specialized pipeline identity, an encode trace and bit-identical gate outputs.
Escape catalog: C1–C4 match none of the changed documentation.

Notes

Dryer and crapper did not run because no Rust file changed. The cited scratch probes and external timing records are absent from the supplied trees; their measurements were not reproduced.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@midagedev
midagedev merged commit 3a0e7ec into main Oct 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant