Conversation
emilianbold
reviewed
Sep 16, 2026
emilianbold
left a comment
There was a problem hiding this comment.
I like how small the actual change is. Some minor comments below.
| !g_stream_expert_cache_mlock_relief_applied) { | ||
| #if TARGET_OS_OSX | ||
| if (@available(macOS 15.0, *)) { | ||
| const BOOL fresh = g_stream_slab_residency_set == nil; |
There was a problem hiding this comment.
I find the fresh bool logic hard to read. It's basically an if/else on g_stream_slab_residency_set == nil with the else just adding the new buffer to the existing residency set.
| if (!g_stream_slab_residency_set) { | ||
| fprintf(stderr, "ds4: streaming slab residency set failed: %s\n", | ||
| [[error localizedDescription] UTF8String]); | ||
| return nil; |
There was a problem hiding this comment.
Somewhat debatable to me why can't we just return the usable buffer here.
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.
This attaches owned SSD expert-cache slabs to a queue residency set on macOS 15+. The switch is off by default. Memory-pressure relief removes the set until the cache is rebuilt. This addresses the multi-second command submission delay reproduced with large slabs on this M2 Ultra.
Enable with
DS4_METAL_STREAMING_SLAB_RESIDENCY=1.Revalidation against current upstream
Measured on 2026-09-14 after merging
a04f46fa423e45712c8c7e430eff422479f314a3(DeepSeek V4.1 CUDA support). M2 Ultra, 192 GiB, macOS 15.7.4, Metal; calibrated V4.1 Flash IQ2_XXS/Q2_K. Same binary per comparison, 2,048-token prompt, 8,257 allocated context, automatic expert cache, fresh engine per run; OS/file cache was not flushed.Mean 8-token decode: 0.240 → 9.310 tokens/s (38.8×).
All four decoded outputs match. These are two observations per variant on one host. The short decode includes the first-token cost; candidate steady decode is 13.41, 13.31 tokens/s. Original 2026-09-13 measurements remain in the report.
Validation and limits
Slab lifecycle and pressure-relief tests, SSD expert kernels, MoE prefill, admission/address checks, and the real-model session fixture pass under Metal API validation.
Clean Metal build, CPU compilation, frontend/Engram/GGUF/quality-tool unit tests and seven targeted Metal kernel subtests pass. The full Metal kernel suite is not green: the new router check fails at
tests/test_deepseek41_metal.c:105; pristine upstream reproduces the exact same actual/reference values. No kernel or tolerance was changed to bypass it.The two existing SDK 15 unused Metal 4 symbol warnings remain. Full legacy
make testand CUDA/ROCm hardware validation were not run.Commands, model hash, raw CSVs and full results.