LazyFormer: Optimizing Transformer Architectures
- LazyFormer refers to two distinct Transformer-based architectures, each addressing specific computational challenges: LazyFormer for reducing self-attention computation and LazFormer for scaling recommendation systems with generative pre-training and adaptive adaptations.
- LazyFormer in language processing reduces the quadratic self-attention computation by reusing the attention distribution across adjacent layers, achieving a 1.3x speedup compared to BERT
- LazFormer efficiently scales recommendation systems by leveraging generative pre-training, targeted request-aware adaptations, and sparse attention, improving ranking accuracy and user metrics in industrial applications.
LazFormer, also written LazyFormer or LazFormer in different references, denotes two distinct Transformer-based architectures published under closely related names. “LazyFormer: Self Attention with Lazy Update” introduces a language-model architecture that reuses attention distributions across adjacent Transformer layers to reduce quadratic attention computation (Ying et al., 2021). “LazFormer: Scaling Transformers for Industrial Recommendation via Transferable Generative Pre-training” presents an industrial recommendation system that combines generative pre-training, transferable residual adapters, request-aware long-sequence modeling, hybrid sparse attention, progressive token pruning, and asymmetric multi-epoch optimization (Li et al., 14 Sep 2026). The two systems address different computational bottlenecks: depth-wise redundancy in self-attention for language pre-training, and feature-transfer, long-history, and sparse-parameter optimization problems in industrial ranking.
1. Terminological distinction and research contexts
The 2021 LazyFormer is a modification of a BERT-style Transformer encoder. It divides the network into lazy blocks and computes the normalized query–key attention distribution only in the first layer of each block. Subsequent layers reuse that distribution while continuing to compute layer-specific value projections, output projections, residual connections, feed-forward networks, and normalization. Its principal objective is to reduce the number of quadratic attention-distribution computations.
The 2026 LazFormer is an industrial recommendation model based on transferable generative pre-training. It autoregressively pre-trains on sequential user behavior, transfers sparse embeddings and dense Transformer parameters to ranking, injects ranking-only features through a zero-initialized residual adapter, and processes multiple target items jointly within a request. Its efficiency mechanisms target long behavioral histories and repeated candidate-wise encoding rather than repeated attention computation across adjacent depth layers.
The names therefore describe different design principles. LazyFormer makes self-attention “lazy in depth” by refreshing attention distributions less frequently. LazFormer uses generative pre-training and request-aware sparse ranking to scale model capacity, history length, and ranking-data consumption.
2. LazyFormer: depth-wise reuse of attention distributions
For a sequence of length , conventional self-attention forms the score matrix
normalizes it as , and computes . The attention-distribution computation has quadratic time and memory cost, , ignoring hidden-dimension factors. A stack of ordinary Transformer layers therefore performs attention-matrix computation at approximately .
LazyFormer partitions the stack into blocks containing Transformer layers. In the first layer of block , it computes
For the remaining layers 0, it does not recompute queries, keys, the query–key product, or the softmax. Instead, it applies the previously computed distribution to the current layer’s value projection:
1
The attention-distribution cost consequently changes from
2
This is not a complete 3-fold reduction in total model cost. Feed-forward networks, residual operations, layer normalization, value projections, output projections, and other dense transformations remain active in every layer. The total cost is expressed schematically as 4 for a conventional layer and 5 for the corresponding lazy structure, where 6 denotes the cost of position-wise and other densely connected components.
A LazyFormer configuration is denoted 7, where 8 is the number of layers per block and 9 is the number of blocks. Thus, M2x6 contains six blocks of two layers each, for twelve Transformer layers. The attention distribution is recomputed at the beginning of each block, not once for the entire network.
The reuse applies independently to the head-specific distributions in multi-head attention. LazyFormer does not replace dense attention with sparse or approximate attention; it reduces the frequency with which dense attention is computed. It is consequently complementary to approaches such as Reformer, Linformer, Longformer, BigBird, and Performer.
3. LazyFormer architecture, training, and empirical trade-offs
LazyFormer retains the ordinary Transformer computational structure apart from query–key attention-distribution reuse. Residual connections, feed-forward networks, layer normalization, position-wise transformations, and output projections remain layer-specific. The experiments use absolute positional encodings and additionally use relative positional encoding in the self-attention module. The paper does not specify a separate relative-position mechanism designed specifically for lazy reuse.
The model is trained with BERT-style masked language modeling rather than causal language modeling. The pre-training corpus consists of English Wikipedia and BookCorpus, forming a 16GB corpus. The setup uses sequence length 512, batch size 256, a 15% masking probability, full-sentence packing, and no next-sentence-prediction objective. Training uses Adam, mixed precision, eight NVIDIA Tesla V100 GPUs, a peak learning rate of 0, 10,000 warm-up steps, linear decay, gradient clipping norm 1.0, weight decay 0.01, and up to 1M steps. Evaluation covers nine GLUE tasks.
Two practical techniques accompany attention reuse. First, the reduction in query and key projection matrices and attention computation can be reinvested in wider feed-forward dimensions, embedding dimensions, attention-head counts, or additional lazy blocks. Second, the principal variants remove dropout from the 1 attention matrix while retaining ordinary dropout elsewhere. In the reported ablation, removing attention dropout changes the M2x6-S training time from 38 to 35 units and the GLUE average from 83.52 to 83.69.
| Model | Parameters | Time for 100 iterations | GLUE average |
|---|---|---|---|
| BERT | 112M | 45 | 83.52 |
| M2x6-S | 112M | 35 | 83.69 |
| M2x6 | 157M | 45 | 84.56 |
M2x6-S matches BERT’s approximately 112M parameters and achieves approximately 2 speedup. Its performance is not uniformly higher on every task: it is lower on some tasks, including QNLI and MRPC, and higher on others, especially RTE and STS-B. The wider M2x6 model has 157M parameters, dimensions 3, and approximately the same measured training time as BERT while increasing the GLUE average from 83.52 to 84.56. Its 500k-step checkpoint already reaches a GLUE average of 83.77.
Block size produces a speed–quality trade-off. Larger blocks reduce the frequency of attention-distribution computation but increase the duration for which a single distribution is reused. The reported GLUE averages are 83.52 for M1x12-SD, 83.52 for M2x6-SD, 82.94 for M3x4-SD, 83.22 for M4x3-SD, and 82.47 for M6x2-SD. The nonuniform layouts M5M3M2M2-SD and M2M2M3M5-SD obtain 82.89 and 82.82, respectively. These results identify M2x6 as a practical compromise in the reported experiments.
The method’s central assumption is that attention distributions change more slowly across adjacent layers than hidden representations do. The architecture therefore updates “what content to propagate” through layer-specific values while updating “where to attend” only once per block. The paper motivates this assumption using empirical observations of similar adjacent-layer attention matrices but does not prove theoretical stability or optimality.
4. LazFormer for industrial recommendation
The industrial-recommendation LazFormer addresses two transfer problems. First, pre-training and ranking generally use inconsistent feature sets, so directly transferring dense parameters can cause negative transfer. Generative pre-training may use item ID, category, shop, brand, time decay, stay time, and scene/context features, whereas ranking additionally uses add-to-cart, order, add-to-cart gap, and order gap features. Directly injecting these ranking-only features into the pre-trained input representation changes the distribution and geometry of the inputs received by the dense Transformer.
Second, repeated multi-epoch updates of very large sparse embedding tables can produce sparse-parameter overfitting. Freezing sparse parameters avoids repeated degradation but prevents adaptation to ranking objectives. LazFormer instead updates sparse parameters within each epoch and resets them to their pre-trained values before the next epoch, while dense parameters retain their updates across epochs.
The system has four major stages:
- Generative pre-training: historical interactions are tokenized, processed by a causal Transformer, and used for autoregressive next-item prediction.
- Transfer to ranking: shared embeddings and projections are reused, dense Transformer parameters are transferred, and ranking-only features enter through a residual adapter.
- Request-aware ranking: long histories are compressed, hybrid sparse attention is applied, historical tokens are progressively pruned, and all candidate items in a request are processed jointly.
- Asymmetric multi-epoch optimization: sparse parameters are reset between epochs while dense parameters accumulate updates.
For an item interaction, feature embeddings are concatenated and projected into a common hidden dimension:
4
The pre-training backbone uses causal self-attention, RMS pre-normalization, QK normalization, an attention gate, feed-forward networks, and residual connections. It predicts the next item using temperature-scaled cosine similarity and in-batch negative items. The resulting pre-training parameters include sparse item and feature representations, input projections, Transformer attention and FFN parameters, and sequential behavior representations.
5. Transferable residual adapter and asymmetric optimization
Ranking-only features are concatenated as
5
A bottleneck adapter computes
6
and adds this residual before normalization:
7
The up-projection is initialized as 8. Consequently, the adapter initially contributes zero, and the ranking representation is exactly compatible with the generative pre-training representation. During ranking optimization, the adapter learns task-specific deviations without perturbing the transferred backbone at initialization.
The reported adapter ablation gives the following results:
| Variant | CTR AUC | CTR GAUC | CVR AUC | CVR GAUC |
|---|---|---|---|---|
| Sparse-only transfer | 0.7699 | 0.6810 | 0.8898 | 0.7109 |
| Direct fusion | 0.7701 | 0.6817 | 0.8897 | 0.7091 |
| Pre-projection fusion | 0.7699 | 0.6810 | 0.8889 | 0.7050 |
| LazFormer adapter | 0.7735 | 0.6868 | 0.8905 | 0.7130 |
The results support the reported interpretation that zero-initialized residual injection is more compatible with dense parameter transfer than direct or randomly initialized pre-projection fusion. The CVR degradation of the no-ranking-specific-features variant further supports the importance of purchase-intent features for conversion prediction.
Asymmetric multi-epoch training partitions parameters into sparse 9 and dense 0. At the beginning of each epoch, sparse parameters are reset to their pre-training initialization 1, whereas dense parameters begin from the values obtained at the end of the preceding epoch. Both groups are updated during the epoch. In the three-epoch comparison, sparse continued training produces CTR AUC 0.7387 and CTR GAUC 0.6694, while sparse reset produces 0.7731 and 0.6851. Sparse reset combined with dense transfer reaches 0.7761 and 0.6891.
6. Request-aware long-sequence ranking
Ranking requests contain a user, a behavior history, multiple target items, and labels. Instead of independently encoding the same history for every candidate, LazFormer processes
2
as one unit. The history is transferred and encoded once, while all target items are processed jointly.
The history is compressed using a coarse-to-fine scheme. The most recent 3 interactions are retained individually. Older interactions are grouped in blocks of size 4 and sum-pooled:
5
The compressed history therefore contains recent fine-grained tokens and older coarse representations. The reported default retains 1,024 short-term tokens and uses compression group size 6.
The compressed history is concatenated with all target-item tokens. Hybrid sparse attention then gives local history tokens access to a causal preceding window, permits global history tokens to support long-range propagation, and allows target items to attend to valid history tokens while restricting each target’s target-to-target interaction to itself. This prevents one candidate’s prediction from leaking into another candidate’s prediction. The sparse pattern is materialized through Flex Attention, which compiles the block-sparse relation into fused CUDA kernels.
Progressive token pruning further reduces computation with depth. Early layers process more historical representations; deeper layers retain progressively fewer history tokens while preserving all target representations. The resulting computation is coarse-to-fine: broad history is available in early processing, whereas later layers concentrate on a smaller recent context and the candidate items.
The default ranking configuration uses five Transformer layers, sequence length 2,048, a short-term retention length of 1,024, group size 7, sliding-window size 8, global-token count 9, and minimum retained history 0. The reported sequence-scaling experiments increase historical sequence length from 512 to 9,216, with AUC and GAUC improving across the tested settings.
Hybrid sparse attention yields one configuration with 88.04% sparsity and a 3.7-fold attention speedup, and a more aggressive configuration with 92.63% sparsity and a 5.1-fold attention speedup. The most aggressive setting incurs approximately a 0.10 percentage-point AUC cost. These measurements concern attention computation rather than the complete end-to-end serving system.
7. Results, applications, and limitations
The industrial-recommendation experiments use 16M users and 11B tokens for generative pre-training, and 11M users and 370M impressions for ranking. The ranking data comprise 25 consecutive training days followed by one testing day. Models are implemented in PyTorch, trained with AdamW on NVIDIA H100 GPUs, and compared with a vanilla Transformer, HSTU, OneTrans, SORT, and STCA.
| Model | CTR AUC | CTR GAUC | CVR AUC | CVR GAUC |
|---|---|---|---|---|
| Transformer | 0.7630 | 0.6704 | 0.8835 | 0.7001 |
| HSTU | 0.7636 | 0.6725 | 0.8826 | 0.6942 |
| OneTrans | 0.7661 | 0.6738 | 0.8840 | 0.7053 |
| SORT | 0.7652 | 0.6740 | 0.8850 | 0.7068 |
| LazFormer* | 0.7704 | 0.6808 | 0.8885 | 0.7094 |
| LazFormer | 0.7735 | 0.6868 | 0.8905 | 0.7130 |
| LazFormer, 3 epochs | 0.7761 | 0.6891 | 0.8933 | 0.7143 |
Relative to the best baseline, the default LazFormer improves CTR AUC by 0.74 percentage points, CTR GAUC by 1.28 points, CVR AUC by 0.55 points, and CVR GAUC by 0.62 points. The reported scaling experiments show monotonic performance increases over the tested model-capacity, data-epoch, and sequence-length ranges; the paper does not establish that these gains continue indefinitely.
In a two-week online A/B test on the homepage ranking stage of a large e-commerce platform, LazFormer produces relative improvements of 5.21% in IPV, 3.38% in orders, 3.70% in buyers, and 9.85% in GMV. The deeper backbone and longer history reduce single-machine throughput by 12.1% on an NVIDIA A10, while compression and sparse attention control the additional overhead.
The principal limitations differ between the two architectures. LazyFormer does not eliminate quadratic attention; it reduces the number of times the quadratic operation is performed. More aggressive reuse lowers computational cost but can reduce downstream accuracy, and the paper does not evaluate causal generation, machine translation, very long-context tasks, adaptive block lengths, selective head refresh, or learned reuse schedules. It also reports no separate numerical table of peak GPU-memory savings.
Industrial-recommendation LazFormer introduces substantial systems complexity through request-level batching, dynamic history compression, Flex Attention kernels, token pruning, residual adapters, and asymmetric parameter management. Sum pooling can lose order and fine-grained information from older behavior, while more aggressive sparse attention can reduce AUC or GAUC. Its reported online throughput decreases by 12.1%, and the experiments derive from one industrial e-commerce platform. The generality of the method across domains, substantially different feature groups, and untested scaling regimes is therefore not established by the reported results.