mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2338] [CLOSED] metal: keep IQ3_XXS resident on 64 GB Macs (wrap a model bigger than maxBufferLength as overlapping buffers) #3990
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3990
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2338
Author: @hokar3361
Created: 10/13/2026
Status: ❌ Closed
Base:
main← Head:mac64-resident📝 Commits (1)
362c3f2metal: wrap a model bigger than maxBufferLength as overlapping no-copy buffers (64 GB Macs keep IQ3_XXS resident); MoE kernels bound per layer📊 Changes
4 files changed (+92 additions, -12 deletions)
View changed files
📝
metal/src/engine/prompt_chain.inc(+3 -2)📝
metal/src/engine/window.cpp(+28 -5)📝
metal/src/mtl_rt.h(+8 -1)📝
metal/src/mtl_rt.mm(+53 -4)📄 Description
What this changes
On a 64 GB Mac, the IQ3_XXS pack cannot stay resident in v0.1.44:
Context::wrapmakes one no-copyMTLBufferof the whole model file (47.0 GB), which is larger than the device'smaxBufferLength(41.75 GB on an M4 Max 64 GB), so it fails withmtl: wrap 47039873024 failed(withSTRATA_METAL_STREAM=0), and the automatic choice streams the experts from the SSD.This PR lets such a file be wrapped and used in place:
metal/src/mtl_rt.{h,mm}: a newwrap(ptr, bytes, max_span). Whenbytes > maxBufferLength, the file is wrapped as several no-copy buffers that overlap bymax_span(the largest range ever bound at one offset). When a dispatch binds the buffer at offsetoff,encode()/run_icb()pick chunkmin(off / stride, n - 1)and bind it atoff - k * stride, so every bound range lies whole inside its chunk.metal/src/engine/window.cpp,prompt_chain.inc: the routed-expert kernels (decodemoe_gu_*/moe_down_*, the prompt GEMMs and the prompt chain) bound the model at offset 0 and passed the experts' absolute file offsets in their argument structs. They are now bound at the layer's first expert tensor with offsets relative to it (moe_rebase).max_span= the largest tensor or the largest layer's gate+up+down range (1.20 GB here).What it leaves alone
wrap(ptr, bytes)path, andmoe_rebasereturns 0 there, so the default path is unchanged.ExpertStream::wanted, setup) is unchanged: a 64 GB Mac still streams unlessSTRATA_METAL_STREAM=0is set. I did not change the default because I have not checked the memory headroom with other programs running beside it.STRATA_METAL_WRAP_SPLIT=0keeps the old single-buffer wrap.How I checked
Mac Studio M4 Max 64 GB (macOS 15), Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS, same build otherwise:
strata generatewith a 12-token and a 360-token prompt: resident (STRATA_METAL_STREAM=0) and streamed give the same tokens, and the traced top logits are equal.reasoning_effort: none): the 400-token code and story answers are identical resident vs streamed, and resident+MTP vs resident.Measured (same Mac, same day, decode tok/s)
bench-strata.py --lengths 1024,4096 --max-tokens 256 --repeat 3(1K / 4K), plus 400 greedy tokens of "Write a Python function that parses an ISO-8601 date string and returns the weekday name. Include error handling." (code) and "Write a short story about a lighthouse keeper who finds a message in a bottle." (story):--spec 2(
--spec 3: 67.0 / 70.7 / 67.1 / 48.7;--spec 4: 73.9 / 72.9 / 67.3 / 41.5; suffix drafter on: 73.7 / 71.9 / 69.8 / 59.1.)Not tested
Other Macs (M1-M3, M5, 96 GB), Q2_0 / IQ3_S packs, memory pressure with other large programs open, and contexts beyond 32K.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.