Add challenge 109: Fused QKV Projection (Medium)#291
Open
claude[bot] wants to merge 1 commit into
Open
Conversation
Implement the fused query/key/value projection at the entrance of a transformer attention layer: a single [3D, D] matmul over the packed weight followed by a split and reshape into the [num_heads, M, head_dim] layout used by multi-head attention. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
claude
Bot
requested review from
ishaan-arya,
kunal-mansukhani and
shxjames
as code owners
July 10, 2026 06:24
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 109: Fused QKV Projection — a Medium-difficulty inference kernel that fuses the three query/key/value projections into a single packed matmul and reshapes the result into the multi-head-attention layout.
xof shape[M, D]and packed weightW_qkvof shape[3D, D](rows stacked as[W_Q; W_K; W_V])Q,K,V, each of shape[num_heads, M, head_dim]qkv = x · W_qkv^T, split along the last dim, reshape to(M, num_heads, head_dim), transpose to(num_heads, M, head_dim)M = 512,num_heads = 32,head_dim = 128(D = 4096, ~192 MB weight matrix)Fused QKV is a canonical transformer-inference kernel: one matmul over the packed weight shares the input reads across Q/K/V and cuts launch overhead versus three separate GEMMs. The output layout requires solvers to think about non-trivial write patterns (interleaved head/token indexing) on top of a tiled matmul.
Validated end-to-end against the Tesla T4 runner with
python scripts/run_challenge.py … --action submit: all functional and performance tests pass.Test plan
pre-commit run --all-filespassesQ,K,V(hand-checkable identity/swap/scale weights)reference_implruns on all 10 functional cases locally (CPU torch)scripts/run_challenge.py … --action submitpasses example + functional + performance tests on Tesla T4challenge.htmlsections all match the checklist in CLAUDE.md🤖 Generated with Claude Code