metal: add opt-in slab residency for DeepSeek V4.1 Flash - #1033
Open
Dango233 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DeepSeek V4.1 Flash SSD decode runs at about 0.25 tokens/s on this M2 Ultra when using the default expert-cache slabs. Attaching those slabs to a Metal queue residency set raises throughput to 9.57–9.67 tokens/s over eight generated tokens, or 13.71–13.83 tokens/s after the first token.
Cause and change
A model-free reproducer fills and locks a 104 GiB buffer pool, then reads small ranges through GPU addresses. Before queue attachment, each large-buffer submission takes about 250.5 ms: Metal reports 249.7 ms in its kernel/driver interval and 0.013 ms of GPU execution. Queue attachment reduces submission time to 0.180 ms. A 32 GiB pool does not show the delay. An unattached residency set, additional CPU mlock, and warmup alone did not resolve the model-level slowdown.
These results point to large-allocation submission/residency overhead. The reproducer checks every GPU checksum and opens no model file. Its retained set stays warm after queue detachment, so the model benchmarks below use fresh processes for each run.
DS4_METAL_STREAMING_SLAB_RESIDENCY=1enables the change on macOS 15+. It is off by default. The set contains only owned expert-cache slabs and uses the existing queue. Cache teardown and successful mlock-margin relief remove and release it; after relief, residency stays disabled until the cache is rebuilt.Performance
M2 Ultra, 192 GiB, macOS 15.7.4, Metal; calibrated DeepSeek V4.1 Flash IQ2_XXS/Q2_K. Base:
bd66c402070042bf0a79ad6ece8242de4c93680c. Each run uses the same binary, 2,048-token prompt, 8,257 allocated context, and automatic expert cache. The OS/file cache is not flushed.All four outputs match. The eight-token run keeps the slow control manageable; first-token latency has a substantial effect on its average. Prefill varied across runs.
Tests
The build retains two existing SDK 15 warnings about unused Metal 4 symbols. The real-model tests use matching V4.1 fixtures; the full legacy
make testsuite was not run. Hardware validation covers this M2 Ultra.Commands, model hash, raw CSVs and detailed results.