mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3030] [CLOSED] fix(Metal): the prompt path no longer kills the engine on prompts > 6… #4412
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#4412
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/3030
Author: @DarkJoll
Created: 10/18/2026
Status: ❌ Closed
Base:
main← Head:metal-prompt-path📝 Commits (1)
ad92d05fix(Metal): the prompt path no longer kills the engine on prompts > 64 tokens📊 Changes
2 files changed (+16 additions, -0 deletions)
View changed files
📝
src/prefill/prefill.cpp(+10 -0)📝
src/program/generate.cpp(+6 -0)📄 Description
fix(Metal): the prompt path no longer kills the engine on prompts > 64 tokens
Addresses #2671 - the Metal failure reported there (same machine family, M1 Max 64 GB; the
follow-up comment's diagnosis,
!m.borrowedinsidePrefill::relayout, matches what I measured).What this changes
On Metal, every prompt over 64 tokens kills the engine, in two ways:
lending the prompt path its slots failed: ... at most 0, exit 1(the guard inside
Prefill::relayout, as #2671 diagnosed);a copy touches a device allocation of 21298.5 MB that was given backinsideExpertCache::fill_slot_queued, exit -6. The Metalarena purges host allocations >= 32 MB (
metal/src/engine/window.cppstream_arena->purge_device_allocations(32<<20)), and the post-read refill writes into that purged regionthrough the slots the lend loop marked.
One root cause under both: on Metal the prompt's buffers live in the Metal arena (
window_ensure),not in the host region the host code believes it is borrowing, and the Metal window never reads the
host residency table. So the relayout has nothing to re-layout, and the lend has nothing to lend.
Prefill::relayout: on Metal, a successful no-op that keeps the larger chunk count (the Metalbuffers never shrink; a large
chunk()is onerun()per segment).lendlambda: the slot-marking loop is guarded out, sop.lentstays empty and the refillafter the read is a no-op instead of writing to purged host memory.
p.lent_chunk = want_pstays.What this leaves alone
Every added line is inside a
STRATA_GPU_METAL/!STRATA_GPU_METALguard: the CUDA / HIP / SYCLbranch is the untouched pre-fix source, byte-identical by construction. The startup line "the prompt
path borrows N CUDA0 cache slots" still logs (cosmetic on Metal) and the sizing arithmetic is
untouched. No new flags, no behaviour change on any other backend.
How I checked
Apple M1 Max 64 GB, macOS 27.0, engine 0.1.45-metal, test arena 8 GB (
STRATA_METAL_ARENA_GB=8):10,797-token prompt -> "given back" SIGABRT exit -6.
alive after; 10,797-token prompt -> prefill 179.8 tok/s, 512 generated at 6.9 tok/s, engine alive
after. Log over both: no "given back", no "at most 0", no lending error.
/health: loaded.ninja -C build-metalfull build 0 errors;ctest1/1 (runtime_hello);gr_parityALL PASS(prepared planes bitwise, rel-L2 <= 3.4e-08 on the rest);
prompt_parityALL PASS.Not checked: the CUDA / HIP / SYCL builds cannot be compiled on a Mac (no toolchains). Per
AGENTS.md a build per backend is the check before merge; the guard makes the non-Metal branch the
untouched source, but I cannot claim the builds, only the construction.
Numbers on the shipping configuration
Same machine, the default run (
run-iq3_s.sh, IQ3_S, expert arena ~32.5 GB, 256K context):prefill ~220 tok/s, decode ~20 tok/s, and long prompts complete with the engine staying up. These
are read off the server's own logs during normal use, not a controlled benchmark; the 8 GB-arena
numbers above are the controlled ones (the small arena is what makes its prefill slower).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.