TGViewer
Machine Learning Machine Learning @machinelearning9 Β· 41.7K subscribers
Post #5887 2.41K
🌐 Global, Local, Sparse: Attention Patterns in Long-Context Transformers

The O(nΒ²) complexity of dense (global) attention is impractical for long sequences. Here's what ML engineers need to know about the three dominant patterns: πŸ§ βš™οΈ

1️⃣ Global (Full Dense) 🌍
➜ Every token attends to every token.
➜ A = softmax(QKα΅€ / √d) V
➜ Complexity: O(n²d)
➜ Use: Short contexts (<4k) or precise recall tasks. 🎯
➜ Downside: KV cache memory explodes. πŸ’₯

2️⃣ Local (Sliding Window) – e.g., Mistral πŸͺŸ
➜ Tokens attend to a fixed neighborhood (±512).
➜ Complexity: O(n · w)
➜ Use: Streaming text, audio, DNA. 🎧🧬
➜ Trade-off: Linear scaling but zero long-range mixing between windows. πŸ”„

3️⃣ Sparse – e.g., BigBird, Longformer πŸ•Έ
➜ Pattern: Local + Global (e.g., [CLS] tokens) + Random/strided.
➜ Complexity: O(n Β· (w + g + r)) β‰ˆ O(n)
➜ Use: Document summarization (5k–16k tokens). πŸ“
➜ Insight: Sparse graphs preserve universal approximation if graph diameter is bounded. πŸ”—

Where we're going: Static sparsity is losing to dynamic routing (Mixture of Depths, 2024). πŸš€ Also, linear RNN-like attention (Mamba, RWKV) challenges whether we need any static pattern. πŸ€”

https://t.me/MachineLearning9 😑
  • ❀ 8
More from @machinelearning9
  1. Oct 9, 2026Channel photo updated
  2. Oct 9, 2026Tracking experiments and versioning ML models with MLflow. πŸ€– Machine learning development…
  3. Oct 8, 2026πŸ”– Official PyTorch Tutorials This collection includes: 🫑 PyTorch fundamentals and torch.…
  4. Oct 7, 2026A distinctive bot for subscribing to courses on the most popular educational platforms acr…
  5. Oct 7, 2026100 Machine Learning Interview Questions and Answers πŸ€– ✨ Join Best TG Channels https://t.…
  6. Oct 7, 2026Hands On Python Data Science - Data Science Bootcamp Master Python for Data Science with R…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook β†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 β†’