Skip to content

Run the Metal queue keepalive every 250 ms - #1347

Open
maciekd wants to merge 1 commit into
antirez:mainfrom
maciekd:queue-keepalive-250ms
Open

maciekd wants to merge 1 commit into
antirez:mainfrom
maciekd:queue-keepalive-250ms

Conversation

@maciekd

@maciekd maciekd commented Nov 12, 2026

Copy link
Copy Markdown

The main-queue keepalive runs once a second. On an M5 Ultra (256 GB, macOS 27.0) that is not quite often enough: the driver drops the idle process's GPU mappings after about 1 s, so the keepalive loses the race roughly every 6 s and the mappings are rebuilt.

With 205 GB of model views (DeepSeek V4.1 Flash, mixed Q4_K / IQ2_XXS / Q2_K quant, ctx 196608) a request that arrives during the rebuild is slow. Measured with a 1-token chat request repeated every 1.4 s, plus 60 s idle sampling "In use system memory" from ioreg:

DS4_METAL_QUEUE_KEEPALIVE_MS drops while idle request latency
1000 (current default) one every ~6 s 0.41 s, or 3–11 s during a drop (6 of 24)
500 none in 60 s 0.37 s (15 of 15)
250 none in 60 s 0.37 s (15 of 15)

This PR changes the default to 250 ms and updates the comment. Nothing else changes; the environment variable still overrides it.

Decode speed is unchanged: 56.8 t/s at 1000 ms vs 56.6 t/s at 250 ms (300-token generation, three runs each). I did not measure idle power.

Tests: make test builds and passes up to ./ds4_test. ./ds4_test with DS4_TEST_MODEL set to the mixed quant above reports 9 failures (the logprob-vector and SSD-streaming checks, which expect the standard quant, and the ds4_think_mode_for_context assertion at ds4_server.c:18238). The same 9 fail with DS4_METAL_QUEUE_KEEPALIVE_MS=1000, so they are not from this change; I don't have ds4flash.gguf on this machine to run the vectors against.

🤖 Generated with Claude Code

On M5 Ultra (macOS 27) the driver drops an idle process GPU mappings after
about 1 s, so the 1 s keepalive lost the race every ~6 s. With 205 GB of
model views a request arriving during the rebuild waited 3-11 s instead of
0.4 s. At 500 ms and 250 ms no drop was seen in 60 s idle and decode speed
is unchanged (56.7 t/s).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
maciekd added a commit to maciekd/Keep that referenced this pull request Nov 12, 2026
The GPU Memory chart of the Dashboard dipped to zero every few seconds on
the M5 Ultra. The dips were real: macOS unwires an idle process's GPU
memory after about a second, and ds4's keepalive kernel runs once a second
by default, so it lost that race every ~6 s and 209 GB of model was wired
again. A request arriving in that window waited 3-11 s instead of 0.4 s
(6 of 24 one-token requests in the probe).

local_ds4_start.sh now starts the server with
DS4_METAL_QUEUE_KEEPALIVE_MS=250 unless the caller sets it. Measured on
the M5 Ultra (macOS 27): at 500 ms and at 250 ms no unwiring in 60 s idle
and every request at its normal latency; decode speed unchanged (56.6 vs
56.8 t/s).

The same value is proposed as ds4's default in antirez/ds4#1347; the
export is redundant once the server's ds4 build has it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant