TL;DR
FlashMorph2 is a new "on-policy" method for converting pretrained Transformers into efficient hybrid attention models (combining full and linear attention). By sampling discrete architectures and jointly optimizing layer selection with weight adaptation, it bridges the gap between selection-time evaluation and post-recovery performance, outperforming previous methods on long-context benchmarks while remaining highly efficient.
What Problem Does This Paper Address?
Standard Transformers suffer from $O(T^2)$ computational and memory complexity due to their self-attention mechanism, making them slow and expensive for long sequences. Hybrid attention models offer a solution by keeping full attention in only a few critical layers and using efficient linear attention elsewhere.
The challenge lies in layer selection: which layers should stay "full" and which should be "linearized"? Previous state-of-the-art methods like FlashMorph used "off-policy" selection. This means they evaluated layer importance using continuous interpolation (mixing both branches) and teacher-forced hidden states with frozen weights. This creates a mismatch: the model used to select layers doesn't behave like the final deployed model, which uses discrete branches, generates its own hidden states, and has adapted weights.
Methods
FlashMorph2 introduces an on-policy layer-selection principle to resolve these mismatches. The core components are:
- On-Policy Hybrid Computation: Instead of continuous mixing, the method uses Gumbel-Top-K sampling to pick a discrete set of full-attention layers in every training step. The model then performs an end-to-end forward pass through this sampled architecture. This allows the model to operate on its own self-generated hidden states, capturing how errors from linearized layers might accumulate or be compensated for by later layers.
- On-Policy Weight Adaptation: Unlike previous methods that keep weights frozen during selection, FlashMorph2 jointly optimizes layer-selection scores and model weights. This ensures the selection process accounts for how weights will co-adapt to the new hybrid structure during the final recovery phase.
- Budget-Constrained Straight-Through Estimator (STE): Since discrete selection is non-differentiable, the authors use a continuous relaxation and a specialized STE to backpropagate gradients to the selection scores while strictly adhering to the prescribed "full-attention budget."
The overall pipeline follows four stages: (1) Layerwise alignment to initialize linear branches, (2) the novel On-Policy Layer Selection, (3) Logits distillation to recover quality, and (4) Long-context finetuning.
Datasets
- Training: The models were trained on randomly sampled subsets of the DCLM dataset.
- Evaluation:
- RULER: A benchmark for long-context retrieval and understanding.
- LongBench: A comprehensive suite of 14 long-context tasks (QA, summarization, etc.).
- Recall-intensive tasks: Evaluated using the prefix-linear-attention suite (e.g., SQuAD, Natural Questions).
- General Capabilities: Standard benchmarks like WikiText, LAMBADA, ARC, PIQA, and HellaSwag were used to ensure language modeling and reasoning were preserved.
Key Insights and Ideas
- The "Aha" Moment on Mismatch: The authors realized that layer importance is not an intrinsic, static property. It depends heavily on the surrounding architecture and how the weights are tuned. Evaluating a layer in isolation or with frozen weights leads to suboptimal "off-policy" choices.
- Error Accumulation Matters: By using self-propagated hidden states during selection, FlashMorph2 can "see" that linearizing an early layer might be more damaging than linearizing a later one because the error propagates through the whole stack.
- Efficiency vs. Accuracy: While more complex than simple ranking, FlashMorph2 is designed to be "one-time" and extremely fast. It completes selection in a few GPU hours, which is a tiny fraction (<1%) of the total conversion budget.
Key Results
FlashMorph2 consistently outperformed all baselines across different model scales (0.6B to 8B) and linear attention variants (Lightning, GLA, GDN).
- Performance Gains: It improved average scores over the original FlashMorph by +2.42 points on RULER and +1.08 points on LongBench.
- Robustness: As shown in Figure 4, FlashMorph2 maintains a significant lead even under tight budgets (e.g., a 6:1 ratio of linear to full attention).
- Efficiency: It is orders of magnitude faster than search-based methods like PostNAS or ranking methods like KL-LS. For an 8B model, selection takes only ~3.5 GPU hours.

Limitations and Future Work
- Computational Overhead: While efficient, FlashMorph2 requires roughly 2x the FLOPs of FlashMorph during the selection stage because it performs end-to-end forward/backward passes rather than local layer-wise updates.
- Weight Re-initialization: Currently, the weights adapted during the selection stage are discarded, and the model is re-initialized for the final recovery stage to isolate the effect of selection. Future work could explore using these "warm" weights to further speed up the recovery process.
- Fixed Budgets: The current method assumes a fixed, pre-defined budget of full-attention layers. Exploring dynamic budgets or non-uniform layer configurations (e.g., different head counts) remains an open area.
Summary updated