Reproduce “Efficient Many-Shot In-Context Learning with Dynamic Block-Sparse Attention” on OpenResearch

Turn your favorite coding agents into research agents that review literature, develop hypotheses, and run experiments.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Emily Xiao, Chin-Jou Li, Yilin Zhang, Graham Neubig, Amanda Bertsch

Carnegie Mellon University researchers developed Dynamic Block-Sparse Attention (DBSA), a training-free inference framework that enables efficient many-shot in-context learning by pre-encoding demonstration blocks with structured sparse attention and dynamically selecting their KV caches for query processing. DBSA achieves per-example inference latencies comparable to finetuning while maintaining over 95% of the best method's accuracy, making large-scale in-context learning practical for real-world deployment.

Key insights

  • A structured block-sparse attention pattern, combining a global anchor (attention sink) with local preceding block attention and self-attention, effectively pre-encodes long demonstration contexts without requiring retraining.
  • Dynamically selecting and re-indexing pre-computed KV cache blocks allows for the benefits of retrieval-based ICL (per-query adaptation) while achieving inference speeds comparable to finetuning.
  • The efficiency gains from block-level KV cache reuse and dynamic selection scale proportionally with the reduction in effective context length, significantly reducing per-example latency without substantial accuracy loss.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.