[GH-ISSUE #5401] [Engine] Metal: a conversation park/save copy aborts on a device allocation that stream_arena gave back (batch windows, 0.1.57-metal) #3222

Open
opened 2026-11-07 14:38:59 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Spinoza0 on GitHub (Nov 6, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5401

Area

[Engine] (speed, kernels, models, the server and API)

Desktop app, Terminal or source?

Source (START-HERE.bat, setup.sh or a build)

Reproduction status

Reproduced locally

Strata version

Strata 0.2.11 · engine 0.1.57-metal

Graphics card, memory and system

Apple M4 Pro (integrated Metal, shared memory) · 48 GB RAM · macOS 27.0.1

Model, size and settings

Qwen3.8-Flash-Next-GSQ-RCO-IQ2_XS (experts' gate/up in IQ1_M) · 262144 context · batch window via tools/batch_interleave_test.py

What happened

The Metal engine aborts during a batch-window conversation park/save when the copy's target allocation was already given back by Window::stream_arena:

strata metal stream: 30.15 GB of the host code's device weight copies given back (unused by the Metal window)
...
strata serve: conversation cache: dropped 1 superseded copy of this conversation; parked=2
strata metal runtime: a copy touches a device allocation of 7043.4 MB that was given back (STRATA_METAL_KEEP_HOST_WEIGHTS=1 keeps it)

  strata::gpu::(anonymous)::encode_copy + 572
  strata::gpu::memcpy_async + 252
  strata::core::conversation_detail::copy_nonblocking + 152
  strata::core::conversation_kv_save + 2004
  strata::core::conversation_snapshot_save + 1808   (main's ParkSource)

Expected: the park/save copy either re-materialises the given-back allocation or the purge skips regions a later copy can touch.

What decides it (measured on the same day, same build and commands)

tools/batch_interleave_test.py (the engine runs --batch 3 itself; the config carries --vram-reserve-mib 1536, the engine's own #2065 advice at this context):

  • 3 starts of 2026-11-05, engine 0.1.57-metal at 9f7d977d (+ a 3-file .metal patch, see below):
    • macOS reported 13.2 GB free at the failed copy → the given-back abort (2 of 2 runs started in this state, the same script point, the same line).
    • 34.2 GB free → the whole flow passed, no abort.
  • 3 further starts in the squeezed-memory state (macOS "available" fell to ~5 GB after the aborts): the expert arena planned 17.9 GB but got 1.0 GB and decode fell to ~5 tok/s, so the #29 watchdog stopped before this point — a different, non-fatal face of the same memory squeeze.
  • Control: the 0.1.45-line build with the same model files decoded at the usual ~15-20 tok/s that same afternoon.
  • The runtime.cpp fetch/copy/purge path is unchanged ffa80d73..9f7d977d (git diff empty); the same test passed 10/10 on 2026-11-03 under ffa80d73, when the machine's memory was healthy.

Full same-day numbers and every command: PR #4886's Validation, "Failed (2026-11-05, this revision, environment)".

About this tree's 3-file patch

These runs need the IQ1_M (type 29) expert kernels a stock build does not link yet for the GSQ-RCO IQ2_XS pack, so the tested tree is main + 27 lines of .metal instantiations (PR #4886). That patch touches no host code and cannot reach runtime.cpp or the park/save copy; the machine-state dependence above stays the variable. A stock main should reproduce this with any pack whose expert types main already covers (e.g. an IQ3_XXS- or Q5_0-experts pack) under equivalent memory pressure — I have no such pack local, so I did not run that.

Reproduce

  1. main (9f7d977d) + PR #4886's three files, cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release -DMETAL_CPP_DIR=<metal-cpp>.
  2. Serve the GSQ-RCO IQ2_XS pack streamed (--mmap-experts, experts on the SSD; --max-context 262144).
  3. STRATA_METAL_BATCH-free tools/batch_interleave_test.py --exe build-metal/strata --config <config> --extra "--vram-reserve-mib 1536".
  4. When macOS has roughly 10-15 GB free rather than 30+, the run dies at the BGEN 1 window right after the give-away with the line above. Not reproduced with 30+ GB free — same-day evidence, not a claim it cannot happen.

Not tested

  • A stock build (no IQ1_M kernels linked) on a non-IQ1_M pack under the same pressure.
  • Windows/Linux and other backends: the abort is in the Metal runtime.cpp.
Originally created by @Spinoza0 on GitHub (Nov 6, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/5401 ### Area [Engine] (speed, kernels, models, the server and API) ### Desktop app, Terminal or source? Source (START-HERE.bat, setup.sh or a build) ### Reproduction status Reproduced locally ### Strata version Strata 0.2.11 · engine 0.1.57-metal ### Graphics card, memory and system Apple M4 Pro (integrated Metal, shared memory) · 48 GB RAM · macOS 27.0.1 ### Model, size and settings Qwen3.8-Flash-Next-GSQ-RCO-IQ2_XS (experts' gate/up in IQ1_M) · 262144 context · batch window via tools/batch_interleave_test.py ### What happened The Metal engine aborts during a batch-window conversation park/save when the copy's target allocation was already given back by `Window::stream_arena`: ``` strata metal stream: 30.15 GB of the host code's device weight copies given back (unused by the Metal window) ... strata serve: conversation cache: dropped 1 superseded copy of this conversation; parked=2 strata metal runtime: a copy touches a device allocation of 7043.4 MB that was given back (STRATA_METAL_KEEP_HOST_WEIGHTS=1 keeps it) strata::gpu::(anonymous)::encode_copy + 572 strata::gpu::memcpy_async + 252 strata::core::conversation_detail::copy_nonblocking + 152 strata::core::conversation_kv_save + 2004 strata::core::conversation_snapshot_save + 1808 (main's ParkSource) ``` Expected: the park/save copy either re-materialises the given-back allocation or the purge skips regions a later copy can touch. ### What decides it (measured on the same day, same build and commands) `tools/batch_interleave_test.py` (the engine runs `--batch 3` itself; the config carries `--vram-reserve-mib 1536`, the engine's own #2065 advice at this context): - 3 starts of 2026-11-05, engine `0.1.57-metal` at `9f7d977d` (+ a 3-file `.metal` patch, see below): - macOS reported **13.2 GB** free at the failed copy → the given-back abort (2 of 2 runs started in this state, the same script point, the same line). - **34.2 GB** free → the whole flow passed, no abort. - 3 further starts in the squeezed-memory state (macOS "available" fell to ~5 GB after the aborts): the expert arena planned 17.9 GB but got 1.0 GB and decode fell to ~5 tok/s, so the #29 watchdog stopped before this point — a different, non-fatal face of the same memory squeeze. - Control: the 0.1.45-line build with the same model files decoded at the usual ~15-20 tok/s that same afternoon. - The `runtime.cpp` fetch/copy/purge path is unchanged `ffa80d73..9f7d977d` (git diff empty); the same test passed 10/10 on 2026-11-03 under `ffa80d73`, when the machine's memory was healthy. Full same-day numbers and every command: PR #4886's Validation, "Failed (2026-11-05, this revision, environment)". ### About this tree's 3-file patch These runs need the IQ1_M (type 29) expert kernels a stock build does not link yet for the GSQ-RCO IQ2_XS pack, so the tested tree is `main` + 27 lines of `.metal` instantiations ([PR #4886](https://github.com/Niko1221/Strata/pull/4886)). That patch touches no host code and cannot reach `runtime.cpp` or the park/save copy; the machine-state dependence above stays the variable. A stock `main` should reproduce this with any pack whose expert types `main` already covers (e.g. an IQ3_XXS- or Q5_0-experts pack) under equivalent memory pressure — I have no such pack local, so I did not run that. ### Reproduce 1. `main` (`9f7d977d`) + PR #4886's three files, `cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release -DMETAL_CPP_DIR=<metal-cpp>`. 2. Serve the GSQ-RCO IQ2_XS pack streamed (`--mmap-experts`, experts on the SSD; `--max-context 262144`). 3. `STRATA_METAL_BATCH`-free `tools/batch_interleave_test.py --exe build-metal/strata --config <config> --extra "--vram-reserve-mib 1536"`. 4. When macOS has roughly 10-15 GB free rather than 30+, the run dies at the `BGEN 1` window right after the give-away with the line above. Not reproduced with 30+ GB free — same-day evidence, not a claim it cannot happen. ### Not tested - A stock build (no IQ1_M kernels linked) on a non-IQ1_M pack under the same pressure. - Windows/Linux and other backends: the abort is in the Metal `runtime.cpp`.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 6, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Fill in "Area".
  • Fill in "Desktop app, Terminal or source?".
  • Fill in "Reproduction status".
  • Fill in "Strata version".
  • Fill in "Graphics card, memory and system".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6685459810 --> @github-actions[bot] commented on GitHub (Nov 6, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Fill in "Area". - [ ] Fill in "Desktop app, Terminal or source?". - [ ] Fill in "Reproduction status". - [ ] Fill in "Strata version". - [ ] Fill in "Graphics card, memory and system". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@github-actions[bot] commented on GitHub (Nov 7, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6709657638 --> @github-actions[bot] commented on GitHub (Nov 7, 2026): Thanks, this follows the format now.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3222
No description provided.