engram: parallelize DeepSeek V4.1 Flash decode reads on macOS - #1035
Open
Dango233 wants to merge 1 commit into
Open
engram: parallelize DeepSeek V4.1 Flash decode reads on macOS#1035Dango233 wants to merge 1 commit into
Dango233 wants to merge 1 commit into
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.
This reads DeepSeek V4.1 Flash Engram decode rows in parallel on macOS. On this M2 Ultra, reading both tables takes 1.359 ms per token instead of 4.787 ms. Full 512-token decode throughput increases from 10.295 to 10.800 tokens/s on average, a 4.9% improvement.
Cause and change
Each token reads 24 rows from each of two Engram tables. The existing reader performs all 48 uncached reads serially. Sorting and deduplicating rows alone did not improve the measured workload; using four readers reduced the time spent waiting for reads.
DS4_ENGRAM_PARALLEL_DECODE=1splits each 24-row call into four six-row calls to the existing reader. It is off by default. Inputs are validated before dispatch, each worker writes its own output and error slots, and all workers join before the call returns. Errors propagate to the caller; IO or data errors can leave partial output, as with the serial reader. The batched prefill reader and calls with other row counts keep their existing behavior.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, automatic expert cache, and 512 generated tokens.Both variants use
DS4_METAL_DISABLE_STREAMING_EXPERT_SLABS=1to avoid the large-slab submission delay on this host. Only the Engram flag changes. Each run starts a fresh engine; the OS/file cache is not flushed.All four 512-token outputs match. The row-reading benchmark uses 128 deterministic row sets per table and eight alternating passes, checking every output bit. The 4.787/1.359 ms figures exclude the first pass.
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.