Add challenge 114: Multi-Head Latent Attention Decode (Hard) - #312
Open
claude[bot] wants to merge 1 commit into
Open
Add challenge 114: Multi-Head Latent Attention Decode (Hard)#312claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
Implements one MLA decode step in the weight-absorbed form used by DeepSeek-V2/V3 inference kernels: a single rank-512 latent cache shared by all heads plus a shared decoupled rotary key, with W_UK folded into the query so attention runs entirely in latent space and W_UV applied once per head after the weighted sum. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
claude
Bot
requested review from
ishaan-arya,
kunal-mansukhani and
shxjames
as code owners
August 7, 2026 04:38
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.
Summary
Adds challenge 114: Multi-Head Latent Attention Decode (Hard) — one decode step of MLA, the attention variant used by DeepSeek-V2/V3.
Instead of caching per-head K and V, MLA caches a single low-rank latent vector
c(rank 512) per position, shared by every head, plus a shared decoupled rotary keyk_pe. The solver must use weight absorption — foldW_UKinto the query and run the whole attention in latent space, applyingW_UVonce per head after the weighted sum — rather than reconstructing per-head keys and values, which would defeat the compressed cache.Why this is interesting
kv_cacherows — reuse across heads is the whole performance story, unlike MHA/GQA where each head owns its keys.W_UK, a softmax reduction over the cache, and a rank-512 accumulation followed by a second GEMV.Contents
challenge.html— description, SVG of the shared latent cache layout, worked 2-head example, constraintschallenge.py— reference impl (standard PyTorch ops only, CUDA/XLA-safe), 10 functional tests (single-position cache, zero query, zero cache, powers-of-2, non-powers-of-2, rank-512 realistic case), perf test atnum_heads=128,seq_len=4,096,kv_lora_rank=512,head_dim=128,rope_dim=64 (~77 MB)Validation
scripts/run_challenge.pyon a T4: all tests passed (functional + performance). The solution is not committed.pre-commit run --all-filespasses.🤖 Generated with Claude Code