One Model, Many Depths: Straightening Latent Trajectories for Post-Hoc Depth Reduction
Stacked layers in a transformer can be read as steps of a discretized ODE acting on a latent state. In standard models, this latent trajectory is strongly curved, and pruning layers after training sharply degrades performance. We propose a trajectory-straightening regularizer that penalizes each layer's update for deviating from the average update, which pushes successive layers to move the hidden state in a shared direction. At inference, an extrapolation rule replaces dropped layers by repeating the last computed update. We test the idea on vision transformers (for classification of MNIST, CIFAR100, satellite cloud images) and on diffusion transformers (for MNIST super-resolution, Moving MNIST video prediction, 2m temperature nowcasting). The regularizer lowers a directional-misalignment measure by one to several orders of magnitude and, at moderate strengths, largely preserves full-depth quality on most tasks. Models trained with it degrade far more gracefully than unconstrained models when layers are removed, and more gracefully than LayerDrop under aggressive reductions, although LayerDrop is as good or better for mild reductions. The costs are real: lower full-depth quality at large $λ$, steep accuracy loss under aggressive depth reduction on harder tasks, and slower optimization. We compare against LayerDrop, a structured-dropout baseline, on every task. Our evidence is that shaping the geometry of latent trajectories is a promising route to depth-flexible models, not that it already beats existing alternatives. Code is available at https://github.com/Siddharth-Rout/straightenedTransformer.