---
title: "Understanding BigBird's Block Sparse Attention"
description: "BigBird replaces BERT's quadratic full attention with block sparse attention, which combines sliding-window, global and random attention to approximate full attention at linear cost."
url: "https://swe.quest/articles/understanding-bigbird-s-block-sparse-attention-c6890f38de755efc"
canonical: "https://huggingface.co/blog/big-bird"
source: "Hugging Face"
published: "2021-03-31"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 18
tags: ["llms","machine-learning","algorithms","performance"]
---

# Understanding BigBird's Block Sparse Attention

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2021-03-31, 18 min read, Deep dive. Original: [https://huggingface.co/blog/big-bird](https://huggingface.co/blog/big-bird)

## Summary

BigBird replaces BERT's quadratic full attention with block sparse attention, which combines sliding-window, global and random attention to approximate full attention at linear cost. That makes sequences up to 4096 tokens practical. Graph intuition shows how global and random connections shorten information paths between tokens, so fewer layers are needed to propagate context. The implementation groups tokens into blocks and uses shifted key copies and gathered random blocks, so the sparse pattern becomes dense matrix multiplications that run efficiently on GPUs and TPUs. The walkthrough maps the 🤗Transformers code, block by block, to the query segments it computes.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- transformer self-attention
- BERT architecture ([easy posts on System design](https://swe.quest/tags/system-design.md?difficulty=easy))
- matrix multiplication on GPUs

## Keywords

BigBird, block sparse attention, BERT, Hugging Face Transformers, Longformer, ETC

## Related posts

- [Ulysses Sequence Parallelism: Training with Million-Token Contexts](https://swe.quest/articles/ulysses-sequence-parallelism-training-with-million-token-contexts-a21775c0b516e85a.md): Hugging Face · 2026-03-09 · Hard · 13 min read · Model training, LLMs, Distributed systems, Hardware
  Ulysses Sequence Parallelism, part of Snowflake's Arctic Long Sequence Training protocol, enables training on contexts of hundreds of thousands to millions of tokens.
- [Optimizing your LLM in production](https://swe.quest/articles/optimizing-your-llm-in-production-aa5bbb901928fa57.md): Hugging Face · 2023-09-15 · Medium · 31 min read · Inference & serving, LLMs, Performance engineering, Python
  Serving billion-parameter LLMs efficiently comes down to three levers: lower precision, Flash Attention, and inference-friendly architectures such as ALiBi, rotary embeddings, Multi-Query Attention and Grouped-Query Attention.
- [Making FlashAttention-4 faster for inference](https://swe.quest/articles/making-flashattention-4-faster-for-inference-dc917e70c20e0f22.md): Modal · 2026-06-11 · Hard · 14 min read · Inference & serving, Hardware, Performance engineering, LLMs
  Modal engineers extended the FlashAttention-4 kernel for decode-heavy LLM inference on Blackwell GPUs through two kinds of change: new parallelism strategies, such as split-KV parallelism across the key/value dimension, and support for irregular memory access via cp.async in place of TMA bulk loads.
- [​Sequential Attention: Making AI models leaner and faster without sacrificing accuracy](https://swe.quest/articles/sequential-attention-making-ai-models-leaner-and-faster-without-sacrificing-65f934b916a51bd2.md): Google Research · 2026-02-04 · Hard · 7 min read · Machine learning, Algorithms, Inference & serving, Recommendations & ranking
  Sequential Attention is a greedy subset-selection algorithm that runs inside a single training run.
- [Welcome Beam: a 501B open model you can own, customize, and scale](https://swe.quest/articles/welcome-beam-a-501b-open-model-you-can-own-customize-and-scale-4761377efc334b45.md): Hugging Face · 2026-10-16 · Hard · 21 min read · LLMs, Inference & serving, Model training
  Beam is a 501B-parameter mixture-of-experts model from Reflection with 23B active parameters per token, a 1M-token context window, and an Apache 2.0 license, aimed at coding and agentic workloads.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
