---
title: 'Raptor: Recurrent Approximations in Vision Transformers'
url: https://www.emergentmind.com/topics/recurrent-approximations-to-phase-structured-transformers-raptor-fd1e37cf-f5d4-40a4-8054-b7899207fddf
type: topic
---

# Raptor: Recurrent Approximations in Vision Transformers

Recurrent Approximations to Phase-structured Transformers (Raptor) provide a mechanism for compressing deep Vision Transformers (ViTs) by exploiting recurring computational phases, enabling the representation of a depth-$L$ ViT as a composition of $k \ll L$ parameter-tied blocks recurrently applied according to a phase structure. Raptor offers a practical realization of the Block-Recurrent Hypothesis (BRH), yielding both efficient surrogates and new tools for dynamical interpretability within ViTs [2512.19941].

## 1. Block-Recurrent Hypothesis and Motivation

The Block-Recurrent Hypothesis posits that, while standard ViTs utilize $L$ distinct residual-Transformer blocks, trained models frequently exhibit contiguous phases along depth, as evidenced by block-diagonal patterns in representational similarity matrices. These phases are hypothesized to be not only similar in representation but functionally equivalent, such that the computations across a sequence of layers may be reconstructed using a much smaller set of recurrently applied blocks.

The $\epsilon$–BRH formally defines this property: for a pretrained ViT of depth $L$, there exist $k$ blocks $B_1,\ldots,B_k$ and integers $n_1,\ldots,n_k$ (with $n_1+\ldots+n_k=L$) such that for all images $x$,
$$
\mathbb{E}_x \|f_L(x) - (B_k^{(n_k)} \circ \cdots \circ B_1^{(n_1)})(x)\|_F \leq \epsilon,
$$
where $B_j^{(n_j)}$ denotes application of block $B_j$ for $n_j$ successive layers using shared parameters. This property mandates recovery of all intermediate activations—not merely final outputs—thus distinguishing it from degenerate bottlenecked or single-block solutions.

The emergence of such phase structure motivates Raptor: a constructive, recurrent surrogate scheme that distills a pretrained ViT into $k$ functionally recurrent, weight-shared blocks.

## 2. Mathematical Formulation and Training Methodology

Given an input image $x$ with patch encoder output $a_0(x) \in \mathbb{R}^{T \times d}$, let $a_\ell(x)$ denote the $\ell$th layer transformer output. The layer depth is partitioned into $k$ contiguous phases of length $n_1,\ldots,n_k$ by maximally block-diagonalizing the layer-layer cosine similarity matrix $S_{ij} = \cos(a_i,a_j)$ using a max-cut dynamic programming procedure.

The Raptor surrogate introduces $k$ weight-shared blocks $B_1,\ldots,B_k$, each architecturally matching their ViT counterparts. The activation at layer $\ell$ for the student is defined as:
$$
\tilde{a}_\ell(x) = (B_j^{(r)} \circ B_{j-1}^{(n_{j-1})} \circ \cdots \circ B_1^{(n_1)})(a_0(x)),
$$
where $\ell$ falls into the $j$th phase and $r \leq n_j$.

The training objective combines two strategies:
- **Teacher-forcing (TF):**
  $$
  L_{\mathrm{TF}}(x) = \sum_{\ell=1}^L \|B_{\mathrm{phase}(\ell)}(a_\ell(x)) - a_{\ell+1}(x)\|_F
  $$
- **Autoregressive (AR):**
  $$
  L_{\mathrm{AR}}(x;h) = \sum_{\ell=1}^h \|\tilde{a}_\ell(x) - a_\ell(x)\|_F
  $$

Overall, the loss is:
$$
L_{\text{total}} = \lambda \mathbb{E}_x[L_{\mathrm{TF}}(x)] + (1-\lambda)\mathbb{E}_x[L_{\mathrm{AR}}(x;L)] + \Omega(\theta),
$$
with $\lambda$ annealed from $0.5 \rightarrow 0$ in early epochs and $\Omega(\theta)$ representing regularization (e.g., weight decay).

## 3. Practical Training Procedure and Phase Discovery

Phase boundaries are identified by maximizing intra-block layer similarity via dynamic programming with $O(kL^2)$ complexity, ensuring optimal contiguous block partitioning.

The Raptor training pipeline consists of two stages:
1. **Block-wise Pretraining:** Each block is initially trained as a multi-layer student, with both TF and AR loss, using AdamW (weight decay $1\times10^{-4}$), learning rate warmup ($1\times10^{-4}$) with cosine decay, batch size 64, and $\lambda$ annealed over $\sim$5 epochs. Token weighting (e.g., $\lambda_{cls}$, $\lambda_{reg}$, $\lambda_{patch}$) can be introduced to optimize specific token groups.
2. **End-to-End Surrogate Assembly:** All blocks are composed into a full $L$-layer recurrent model, trained end-to-end with pure AR loss (i.e., $\lambda=0$) for 20 epochs, maintaining the optimizer and token weights.

For evaluation, the backbone can be frozen and shallow probe heads trained on image classification (ImageNet-1k), semantic segmentation (ADE20k), or depth estimation (NYUv2).

Small-scale experiments (CIFAR-100) reveal that increasing teacher stochastic depth ($p \in \{0, \ldots, 0.9\}$) enhances layer similarity, improves Raptor fit, and increases both teacher and student final accuracy. R-squared matching quantifies alignment between student and teacher token embeddings at each layer as a function of $p$.

## 4. Empirical Evaluation and Causal Analysis

Empirical investigations reveal that off-the-shelf ViTs (e.g., DINOv2, CLIP, plain supervised) consistently exhibit block-diagonal layer similarity matrices. The identified phases correlate strongly with the compressibility achievable via Raptor; random (non-phase-aligned) partitions produce significantly worse performance, degrading at least $1\sigma$ below optimal phase-aligned partitions.

### Performance Metrics

| Backbone     | Task         | Baseline Acc. | Raptor ($k=2$) | Raptor ($k=3$) | Raptor ($k=4$) |
|--------------|--------------|---------------|----------------|----------------|----------------|
| DINOv2-Base  | ImageNet-1k  | 84.5%         | 81.2% (96%)    | 83.0% (98%)    | 83.2%          |
| DINOv2-Base  | ADE20k mIoU  | 47.5          | —              | 43.0           | —              |
| DINOv2-Base  | NYUv2 RMSE   | 0.578         | —              | 0.618          | —              |

Using only $k=2$ blocks, Raptor recovers 96% of top-1 linear probe accuracy of the DINOv2-Base on ImageNet-1k at equivalent computational cost; $k=3$ recovers 98%. Cosine alignment per layer remains above 0.7 for all $k$.

Causal swapping experiments validate the functional distinctness of phases: replacing a layer with another from the same recurrent block maintains top-1 accuracy, while cross-phase swaps severely degrade performance, confirming that discovered phases correspond to genuinely distinct computations.

Computational cost remains unchanged: $k$-block Raptor incurs the same FLOPs as an $L$-layer ViT, since each block is applied for $n_j$ steps with shared parameters.

## 5. Dynamical Interpretability Insights

Raptor enables detailed dynamical systems analysis of ViT computation by treating depth index $\ell$ as discrete time. Several interpretability results characterize the evolution of token embeddings:

- **Directional Convergence:** Normalized token directions $\hat{x}_\ell = x_\ell / \|x_\ell\|$ approach class-dependent angular basins, with the curve $\gamma_\ell = \langle \hat{x}_\ell, \hat{x}_L \rangle$ displaying S-shaped convergence to 1. Principal component projections show trajectories for distinct ImageNet classes clustering into tight angular basins.
- **Token-specific Angular Speeds:** $s_\ell = \arccos \langle \hat{x}_{\ell+1}, \hat{x}_\ell \rangle$ is low and stable for register tokens; moderate for patch tokens; but spikes for the cls token in late phases (aggregation). Max-cut phase boundaries correspond to abrupt changes in these dynamics.
- **Self-correction Under Perturbations:** Injecting small Gaussian noise at intermediate layers results in log-linear contraction of deviation $d_{\mathrm{cos}} = 1-\langle \hat{x}_L^{\mathrm{perturbed}}, \hat{x}_L \rangle$ for patch tokens, yet accumulated error for cls tokens in the final phase (consistent with their readout role).
- **Low-rank Collapse and Coherence:** The stable rank $r_s(U_\ell)$ of angular update matrices drops from approximately 20 to 6 over depth. Patch tokens' coherence $\kappa_\ell$ increases towards unity, indicating late-layer collective movement and convergence to low-dimensional attractors.
- **Dynamic Mode Decomposition (DMD):** For each token group, DMD of normalized group mean trajectories yields spectral modes with eigenvalues just inside the unit circle, suggesting weak contraction and dominant rotational dynamics. The cls modes are closest to +1, reflecting long memory, while patch groups are more contractive and rotational.

## 6. Practical Application, Limitations, and Extensions

Raptor can be applied to any pretrained ViT with standard residual Transformer blocks. Practitioners first compute a layer-layer cosine similarity matrix over a small validation set and apply contiguous max-cut dynamic programming, typically yielding $k \approx 2\text{–}4$ phases. If strong block-diagonal structure is present, Raptor is likely to succeed.

Recommended training follows the two-stage TF $\rightarrow$ AR distillation with $\lambda$ annealing, AdamW optimizer ($\mathrm{wd} \approx 1 \times 10^{-4}$), learning rate warmup and cosine schedule, batch size 64, and 20–40 epochs. For foundation-scale models, the backbone should be frozen and only probe heads fine-tuned on downstream tasks.

Limitations include a residual accuracy penalty (typically $\sim 2\%$ top-1 on ImageNet with $k=2$); bridging this gap may require non-autonomous recurrence (e.g., explicit depth encodings) or partial sharing (e.g., block-specific adapters). Application to very deep or irregular-phase networks can be challenging if representation phases are ambiguous or heavily overlapping.

Possible extensions include:
- Integrating explicit depth encodings, such as a depth-scale MLP, to enable non-autonomous recurrence.
- Augmenting each block with small, block-specific adapter layers to capture finer inter-phase distinctions.
- Applying the methodology to language transformers or hybrid vision-language backbones.
- Utilizing Raptor surrogates for formal verification and for systematic rollout sampling in interpretability studies.

## 7. Implications and Future Directions

The Raptor framework offers a scalable, mechanistically grounded route for compressing and interpreting ViTs by functionally decomposing depth into genuinely recurrent computation. Empirical validation across standard vision models establishes the presence of robust phase structure and the feasibility of accurate recurrent surrogates. This suggests a path toward dynamical systems-theoretic analyses, algorithmic complexity benchmarking, and systematized interpretability rooted in the identified low-complexity recurrent programs. Further exploration of non-autonomous recurrence and extension to non-visual domains are promising areas for future research [2512.19941].

Source: https://www.emergentmind.com/topics/recurrent-approximations-to-phase-structured-transformers-raptor-fd1e37cf-f5d4-40a4-8054-b7899207fddf