Latent Flow Transformer

Yen-Chen Wu, Feng-Ting Liao, Meng-Hsi Chen, Pei-Chen Ho, Farhang Nabiei, Da-shan ShiuarXiv 2025 · DOI

Abstract

Large Language Models (LLMs) face significant challenges in deployment due to their massive memory and computational requirements. Traditional compression methods often struggle to maintain performance at high compression ratios. This paper introduces the Latent Flow Transformer (LFT), a novel framework that treats the transformer forward pass as a continuous dynamical process. By replacing entire blocks of discrete layers with a single, learned "latent flow" operator, LFT achieves significant compression. Utilizing a new Flow Walking algorithm and an Optimal Transport-based Recoupling Ratio, the authors demonstrate that 12 transformer layers can be distilled into one while significantly outperforming traditional layer-skipping baselines.

Introduction

Modern LLMs consist of dozens or hundreds of layers, leading to massive memory and compute requirements. While researchers know many of these layers are overparameterized, current compression techniques like pruning or knowledge distillation often struggle to maintain performance at high compression ratios. The Latent Flow Transformer (LFT) approaches this problem by viewing the sequence of hidden states as a trajectory. Drawing inspiration from the efficiency of flow-matching models in image generation, LFT aims to "straighten" these inter-layer mappings to enable high-ratio compression.

The Latent Flow Transformer Architecture

The core of the LFT is the replacement of a sequence of transformer layers with a single latent flow layer. This layer approximates the total transformation of a token's hidden state through the original block in one or more steps.

Velocity Field Estimator

The LFT utilizes a Velocity Field Estimator, adapted from Diffusion Transformer (DiT) blocks. These blocks are augmented with scale and shift operators to predict the "velocity"—the instantaneous direction of change—of hidden states as they progress through the latent space.

Architecture variants of the Latent Flow Transformer, including the velocity field estimator (b) and parallel versions (c).

Dynamic Unrolling

A key advantage of the LFT is its inference-time flexibility. The latent flow layer can be "unrolled" over multiple discrete time steps. This allows the model to dynamically trade off computational cost for accuracy on a per-token or per-task basis, similar to numerical integration in ODE solvers.

Training with Flow Walking

Standard flow matching often encounters "velocity ambiguity" when trajectories in the hidden state space cross or become too dense. To address this, the authors introduce Flow Walking (FW).

Visualization of hidden state trajectories and the straightening effect of Flow Matching.

Flow Walking is a scalable training algorithm that uses numerical integration to resolve local ambiguities. By learning smoother, non-crossing paths, the model preserves the original input-output relationship more effectively than simple straight-line assumptions.

Identifying Compressible Layers

To determine which layers are best suited for compression, the authors propose the Recoupling Ratio. Based on Optimal Transport (OT), this metric measures how much the original mapping between two layers deviates from an ideal straight-line path. Analysis of Pythia-410M revealed that middle layers are significantly more "compressible" than the initial or final layers, which perform qualitatively different transformations that resist linear or flow-based approximation.

Experimental Results

The LFT was evaluated by distilling the middle layers (6–18) of a Pythia-410M model using a 2.6 billion token subset of The Pile.

  • Compression Performance: When replacing 12 layers of Pythia-410M with a single LFT-FW layer, the model achieved a KL divergence of 0.736. For comparison, simply skipping just 3 layers results in a much worse KL of 0.932.
  • Local Fidelity: In terms of reconstructing the teacher's hidden states (NMSE), LFT-FW (0.021) outperformed a standard regression baseline (0.024), proving that the flow-based approach captures the underlying dynamics more accurately.
  • Efficiency: LFT-FW with a single step ($k=1$) achieved parity with complex regression models while offering the flexibility to improve performance by increasing steps ($k=3$) at inference time.

Conclusion and Future Work

The Latent Flow Transformer provides a promising path toward extreme LLM compression by leveraging the continuous dynamics of hidden states. While currently validated on models up to 410M parameters, future work will focus on scaling to larger architectures and exploring "Flow Untangling" to optimize layer endpoints. The structural similarity between LFT and standard transformers ensures compatibility with existing hardware and software optimizations, making it a practical candidate for efficient LLM deployment.

Summary updated

BibTeX
@misc{wu2025latent,
  author = {Yen-Chen Wu and Feng-Ting Liao and Meng-Hsi Chen and Pei-Chen Ho and Farhang Nabiei and Da-shan Shiu},
  title = {{Latent Flow Transformer}},
  year = {2025},
  eprint = {2505.14513},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.14513},
}
Figure