Block Sparse Attention With Block Retrieval


Jacob@jvboid

Block Sparse Attention WIth Block Retrieval!

docs: jacobfv.github.io/bsbr repo: github.com/JacobFV/bsbr

Image attached to @jvboid's post of 2025-03-29
2025-03-291246
Jacob@jvboid

Why block sparse? The standard transformer attention mechanism computes attention scores between all pairs of tokens in a sequence. which leads to O(n²) complexity in both computation and memory

Image attached to @jvboid's post of 2025-03-29
2025-03-2921
Jacob@jvboid

BSBR addresses this scalability issue by breaking the sequence into chucks of block size B and then combining standard attention within fixed-size chunks and a meta-attention mechanism to efficiently retrieve information between chunks. It works by compressing each chunk’s

Image attached to @jvboid's post of 2025-03-29
2025-03-29 · read the rest on X41
Jacob@jvboid

The chunk size (B) is a crucial hyperparameter that affects: - Memory Usage: Larger chunks use more memory but provide better local context - Computation Time: Smaller chunks are faster but may miss important long-range dependencies - Model Expressivity: Chunk size affects how

Image attached to @jvboid's post of 2025-03-29
2025-03-29 · read the rest on X21
Jacob@jvboid

You can control the compression factor which determines how much information is preserved in chunk states. Higher compression factors reduce memory usage and speed up computation but may lose fine-grained information:

Image attached to @jvboid's post of 2025-03-29
2025-03-2921
Jacob@jvboid

BSBR also supports overlap between chunks which may help mitigate attention discontinuities at the block boundaries:

Image attached to @jvboid's post of 2025-03-29
2025-03-2921
Jacob@jvboid

And besides sparse attention, the implementation also supports state reuse across layers, optimized attention masks for autoregression, and I plan on implementing more streaming-first optimizations when I get time. Imagine building agentic software that weaves threads of tokens

2025-03-29 · read the rest on X51
Jacob@jvboid

Finally, how useful is a new architecture without pretrained models? Well sorry I don’t have any yet lol but the bsbr_transformers provides tools to convert pretrained huggingface transformers into bsbr ones. Just make sure to pip install bsbr[transformers] and then from

Image attached to @jvboid's post of 2025-03-29
2025-03-29 · read the rest on X41
Jacob@jvboid

Finishing off with an end to end example. I hope you find bsbr useful! Please also give OG’s poast a read:

Image attached to @jvboid's post of 2025-03-29
2025-03-292

Dense attention is a beautiful default and a brutal scaling law. Standard transformer attention compares every token with every other token, which gives the familiar O(n2)O(n^2) memory and compute shape. That is tolerable until context stops being a prompt and starts becoming a working memory.

Block Sparse Attention With Block Retrieval, or BSBR, is one attempt to make that memory more structured. The sequence is divided into blocks. Attention remains dense inside a local block, where nearby tokens usually need fine-grained access. Across blocks, the model retrieves compressed block states rather than attending naively to every token.

The design pressure is simple:

  • Local attention should preserve short-range precision.
  • Block retrieval should preserve long-range access.
  • Compression should make old context cheap enough to keep around.
  • State reuse should make repeated long-context computation less wasteful.

That gives several knobs that are more operational than theoretical:

  • Block size controls the local-context versus memory tradeoff.
  • Compression factor controls how much information survives into block state.
  • Overlap reduces discontinuities at block boundaries.
  • State reuse lets layers and decoding steps avoid recomputing context that has already been summarized.

The interesting product direction is not just "longer context." It is streaming-first agent software. Agents do not merely answer once. They accumulate traces: files, tool calls, decisions, failures, user corrections, world state, and partial plans. A useful memory substrate has to weave those traces into something reusable without making every future step pay the full quadratic cost of the past.

This connects to my older interest in structured sparsity in the brain model and the more speculative architectural notes in Design Patterns for AI. The recurring intuition is that topology should be part of the interface. A model should not only learn weights; it should expose useful ways to route, compress, reuse, and inspect information.

The missing work is the part that always matters: pretrained checkpoints, benchmarks, ablations, and uncomfortable comparisons against simpler baselines. A sparse attention pattern becomes real only when it earns its complexity.

posted:

Related

Block Sparse Attention With Blo…brain-model / Resonancebrain-model / ResonanceDesign Patterns for AIDesign Patterns for AIAI systems engineeringAI systems engineeringResearch and technical writingResearch and technical writ…From Arxiv Reading to ML Systems TasteFrom Arxiv Reading to…Software Engineering After AgentsSoftware Engineering …IBM-1IBM-1SC-WBDSC-WBDComputatrumComputatrumThe Agent SuiteThe Agent SuiteThe APIThe APIA navigable mindA navigable mindBroadening and Building Beyond Classical Reinforcement LearningBroadening and Buildi…multi-graph-formermulti-graph-formerarxiv-notesarxiv-notesTeaching Computers to Use ComputersTeaching Computers …Full-Stack Artificial IntelligenceFull-Stack Artifici…belief-graph-orchestratorbelief-graph-orches…EEG Acquisition ChainEEG Acquisition Cha…personal sitepersonal siteThe Tensor ComputerThe Tensor ComputerA Differentiable von Neumann ComputerA Differentiable vo…A Beautiful LoopA Beautiful LoopAttention Is All You NeedAttention Is All Yo…Language Models are Few-Shot LearnersLanguage Models are…Pretrained Transformers as Universal Computation EnginesPretrained Transfor…Reward is EnoughReward is EnoughReworking the site around durable updatesReworking the site …Full-stack product engineeringFull-stack product …Broaden and Build Conference 2021Broaden and Build C…Focus StatementFocus StatementFull Stack Artificial IntelligenceFull Stack Artifici…👩🏽‍🌾 The Fertile Cresent👩🏽‍🌾 The Fertile…ComputatrumComputatrumBroadening and building beyond classical reinforcement learningBroadening and buil…multigraph-nnmultigraph-nnDRAG TO ORBIT · SCROLL OR PINCH TO ZOOM