Add challenge 115: Fused QKV Projection with RoPE and KV Cache Update (Medium) - #314
Open
claude[bot] wants to merge 1 commit into
Open
Add challenge 115: Fused QKV Projection with RoPE and KV Cache Update (Medium)#314claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
… (Medium) Adds the decode-step prologue of a LLaMA-style attention layer: one fused QKV GEMM, rotate-half RoPE applied to Q and K from a precomputed cos/sin table indexed by per-sequence positions, and a scattered write of the rotated K and the V into the KV cache at slot positions[b]. The solver has to split the fused projection into grouped-query heads, gather the rotation coefficients per sequence, and write only the target cache slots while leaving the rest of the cache untouched. Validated on a Tesla T4 with a CUDA solution (all functional and performance tests pass). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
claude
Bot
requested review from
ishaan-arya,
kunal-mansukhani and
shxjames
as code owners
August 21, 2026 03:20
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 115 — Fused QKV Projection with RoPE and KV Cache Update (Medium), the prologue that every LLaMA-style attention layer runs on each decoding step:
qkv = x @ W_qkvproducing[B, (H_q + 2·H_kv)·D]Q/K/Vheads (H_kv ≤ H_q)QandKonly, using a precomputedcos_sin_cache[S_max, D]row selected by the per-sequencepositions[b]Kand rawVintoK_cache/V_cacheat slotpositions[b], leaving every other cache slot untouchedWhy this one
It is not a map operation — the solver has to reason about a skinny GEMM, the head-offset arithmetic of the fused QKV layout, a per-sequence gather of rotation coefficients, and a strided scatter into a multi-gigabyte cache that must not be copied or clobbered. The
inoutcache tensors make "touch only what you write" part of the correctness criterion.No overlap with merged challenges (61 is standalone RoPE on a precomputed table, 84 is the MLP block, 96 reads an existing INT8 KV cache) or with any open PR.
Contents
challenge.py— reference impl, signature, example test, 10 functional tests (edge sizes 1–4, powers of 2, non-powers of 2, zero input, realistic decode batches), performance testchallenge.html— description, SVG dataflow diagram, worked example, constraints, referencesstarter/— all six frameworks (.cu,.pytorch.py,.triton.py,.jax.py,.cute.py,.mojo)Validation
pre-commit run --all-filespassesscripts/run_challenge.pyon a Tesla T4: all functional and performance tests pass (solution not committed)B=64,d_model=4,096,H_q=32,H_kv=8,D=128,S_max=2,048) allocates ~1.18 GB, well within the 5× / 16 GB budget🤖 Generated with Claude Code