Implement grouped-query attention (GQA) in PyTorch by repeating/broadcasting KV heads acro

Attention Efficiency & Long Context3 / 5

Chapter 033 / 5

Attention Efficiency & Long Context

Implement grouped-query attention (GQA) in PyTorch by repeating/broadcasting KV heads acro

Medium

Implement grouped-query attention (GQA) in PyTorch by repeating/broadcasting KV heads across query-head groups, and verify it matches full multi-head attention when num_kv_heads equals num_query_heads.

Target interface
class GQA

Implement the function/class skeleton in the editor. Any correct approach is accepted.

Hints0 / 2
Reference solution
Your own code stays in the editor.