Add challenge 108: Cross-Attention (Medium)#288
Open
claude[bot] wants to merge 1 commit into
Open
Conversation
Introduce a multi-head cross-attention challenge modeled on the attention layer used by encoder-decoder transformers (T5, BART, Whisper) and by the text-conditioning path of diffusion models. Decoder queries of shape (M, H, D) attend to encoder keys/values of shape (N, H, D) with distinct query and key/value sequence lengths and no causal mask — a pattern not covered by the existing self-attention or causal attention challenges. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
challenges/medium/108_cross_attention/6_softmax_attention,12_multi_head_attention,53_causal_attention,59_sliding_window_attn,80_grouped_query_attention, etc.) are all self-attention or causal variants with matching query and key lengths. Cross-attention is the fundamental building block used by encoder-decoder transformers (T5, BART, Whisper) and by the text-conditioning path of diffusion models like Stable Diffusion(position, head, dim)for all four tensors. Decoder queries of shape(M, H, D)attend to encoder keys/values of shape(N, H, D)withM ≠ Nin general, no causal mask, per-head scaled dot-product attentionmatmul+softmax) so it lowers cleanly on both CUDA and XLA(M=1, N=16), prefill-like(M=4, N=1), zero inputs, uniform mixed values, power-of-2 sizes, non-power-of-2 shapes (30×45, 100×200), and realistic Whisper/BART-scale cases up to(M=128, N=512, H=16, D=64)M=1024, N=2048, H=16, D=128(~48 MB, safely within 5× of Tesla T4 VRAM)Validated end-to-end on the platform with
run_challenge.py --language cuda(single-block-per-(query, head), softmax over N with shared-memory reductions): both the example run and the full functional/performance suite pass withStatus: success | Output: ✓ All tests passed.Test plan
pre-commit run --all-files(black, isort, flake8, clang-format, mojo format)python scripts/run_challenge.py challenges/medium/108_cross_attention --language cuda --action run— example test passespython scripts/run_challenge.py challenges/medium/108_cross_attention --language cuda --action submit— all functional + performance tests pass on Tesla T4__init__, reference asserts shape+dtype only, all tensors usedevice=self.device, 11 functional cases spanning edges/powers-of-2/non-powers-of-2/zeros/mixed/realistic, perf fits 5× in 16 GB VRAM🤖 Generated with Claude Code