Sparse Attention Masks
This module implements prompt-aware attention head masking to skip computation for heads that don't contribute to the output.
Key Insight
Not all attention heads are equally important for every prompt. Portrait prompts activate face-focused heads while landscape prompts activate background/composition heads. By predicting which heads matter, we can skip 50-70% of attention computation.
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ Sparse Attention │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Standard Attention (32 heads × 64 layers = 2048 computations) │
│ ════════════════════════════════════════════════════════════ │
│ [████████████████████████████████] 100% compute │
│ │
│ Sparse Attention (prompt-aware masking) │
│ ════════════════════════════════════════════════════════════ │
│ "Portrait of a woman" │
│ [████████░░░░░░░░████░░░░░░░░░░░░] 35% compute │
│ ↑ face ↑ skip ↑ style │
│ │
│ "Mountain landscape at sunset" │
│ [░░░░░░░░████████████████████░░░░] 45% compute │
│ ↑ skip ↑ background/lighting ↑ skip │
└─────────────────────────────────────────────────────────────────┘