Sequential Attention: Making AI models leaner and faster without sacrificing accuracy
Sequential Attention is a greedy subset-selection algorithm that runs inside a single training run. It uses softmax attention scores over unselected candidates (features, embedding chunks, weight blocks) to add the most informative one at each step, and recomputes scores so the ranking reflects marginal gain and avoids redundant picks. For feature selection it matches or beats baselines on proteomics, image and activity-recognition benchmarks, and on linear regression it is provably equivalent to Orthogonal Matching Pursuit. SequentialAttention++ combines differentiable pruning with combinatorial search to produce block-sparse weights that run efficiently on GPUs and TPUs, with compression gains on ImageNet. Planned uses include recommender embedding optimization and structured LLM pruning.
Related posts
- Sequence learning: A paradigm shift for personalized ads recommendations
Meta Engineering hardMasterMeta replaced its DLRM ads ranking models, which depended on thousands of hand-engineered aggregated sparse features, with sequence learning over event-based features (EBFs). These features preserve the order and fine-grained attributes of a person's engagement and conversion events. An event model compresses per-attribute embeddings and adds timestamp encodings, and a transformer-based sequence model uses multi-headed attention pooling keyed by the candidate ad, cutting attention cost from O(N²) to O(M·N). Variable-length sequences are made production-viable through jagged tensor support in PyTorch, GPU kernels, Jagged Flash Attention, quantization and vector quantization. The result was a 2-4% conversion lift on select segments, with plans to scale sequences 100x and explore linear attention and state space models.
- Understanding BigBird's Block Sparse Attention
Hugging Face hardMasterBigBird 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.
- From User Sequences to Scaling Laws: A Multi-Stage Architecture for Meta’s Ads Ranking
Meta Engineering hardMasterMeta scales sequence learning for ads ranking by splitting it into two stages: an offline transformer user model processes thousands of user events asynchronously and caches user-level embeddings, and a lightweight online ranking model combines those embeddings with fresh signals and ad candidates under strict latency budgets. Dense tokenization folds sparse features into a single vocabulary, and target-aware multi-head attention weighs past behavior against the ad being scored, so feature interactions are learned rather than hand-engineered. The system shows LLM-style log-linear scaling of normalized entropy with compute. Scaling works best when depth, width and sequence length grow together, and diverse action-type sequences beat homogeneous ones. Together with other model work it contributed to 6% more conversions on Instagram and 3% on Facebook.
- Hugging Face Reads, Feb. 2021 - Long-range Transformers
Hugging Face hardMasterLong-range attention methods attack the quadratic memory and time cost of self-attention in sequence length, and four papers illustrate the main families. Longformer combines dilated windowed and global attention to reach linear cost and serves as a drop-in replacement, so pretrained checkpoints can be adapted to long inputs. Compressive Transformer extends Transformer-XL with a compressed memory of past activations, using pooling or convolution, to model longer dependencies. Linformer exploits the low rank of attention matrices to project the sequence dimension and get linear complexity. Each paper comes with complexity analysis, main findings and open questions, such as TPU indexing costs, hyperparameter brittleness and long-target seq2seq tasks.
- Ulysses Sequence Parallelism: Training with Million-Token Contexts
Hugging Face hardMasterUlysses Sequence Parallelism, part of Snowflake's Arctic Long Sequence Training protocol, enables training on contexts of hundreds of thousands to millions of tokens. Each GPU holds a shard of the sequence, and all-to-all collectives regroup the data so each GPU computes attention over every position for a subset of heads. That costs O(n·d/P) communication per GPU, versus O(n·d) over P−1 serial hops for Ring Attention. Ulysses is now integrated into Hugging Face Accelerate (ParallelismConfig with a DeepSpeed backend), the Transformers Trainer and TRL's SFTTrainer, which handle dataloader sharding, shifted labels and token-weighted loss aggregation automatically. Practical guidance covers padding to a multiple of sp_size, the num_heads ≥ sp_size constraint, choosing FlashAttention versions, ZeRO-3 offload, expandable_segments, Liger-Kernel, and balancing SP against DP across GPU counts.