metal: Improve deepseek v4 token generation - #26514
Closed
tarruda wants to merge 4 commits into
Closed
Conversation
Replace dense compressed-attention scans during DeepSeek V4 prefill with a backend-neutral sparse path that packs the sliding window and Lightning Indexer selections into a compact working set. - Add DSV4_SPARSE_PACK with a CPU reference and backend capability probes. - Extend Flash Attention with broadcast masks and row-indexed sinks. - Select sparse prefill graphs when supported while preserving dense fallback. - Test sparse packing and tiled and padded Flash Attention paths. Assisted-by: Codex
Implement the sparse DeepSeek V4 prefill path on Metal so Flash Attention consumes compact per-token key sets instead of scanning the full compressed cache. - Add a DSV4_SPARSE_PACK kernel for raw-window and selected keys. - Add an exact radix TOP_K specialization for 512 Lightning Indexer results. - Extend tiled Flash Attention with broadcast masks and row-indexed sinks. - Register backend support for the fused packing operation. Assisted-by: Codex
Reduce DeepSeek V4 decode overhead with fused compressor and mask operations, avoid redundant Lightning Indexer work, and bound long-context attention by gathering only selected compressed keys. - Add DSV4_COMPRESS and DSV4_TOP_K_MASK with CPU references and capability probes. - Skip Lightning Indexer and TOP_K when every compressed row is selected. - Reuse sparse packing for deep single-token decode with dense fallbacks. - Test fused compression, mask construction, and compact Flash Attention. Assisted-by: Codex
Fuse compressor and attention-mask construction on Metal and keep long-context decode bounded by gathering only selected compressed keys. - Add kernels for DSV4_COMPRESS and DSV4_TOP_K_MASK. - Skip K and V loads for fully masked vector Flash Attention groups. - Extend DSV4_SPARSE_PACK with a parallel compressed-only decode mode. - Preserve compact F16 masks without intermediate conversions. Assisted-by: Codex
Contributor
Author
|
I was hoping to create stacked PRs from #26512 and this, but there seems to be no option in the web UI. |
Contributor
Author
|
closing for now because this depends on #26512, which introduces new ops @ggerganov |
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.
Overview
Picking a couple of commits from my branch which improve DSv4 token generation
Additional information
This builds on #26512 and will improve token generation and keep it more stable as context grows. Here's
-d 0,10000,20000,30000 -n 128 -p 2048 -b 2048 -ub 2048on a M1 Ultra:Requirements