🤖 AI Summary
This work investigates the dynamic evolution of hidden states across tokens in large language model (LLM) inference, aiming to enhance interpretability, anomaly detection, and controllability. We propose a physics-inspired mechanistic framework and introduce, for the first time, a “log-Lagrangian” perspective, revealing an energy-conservation-like balance between the rate of change of hidden states and prediction certainty. We empirically verify that pretrained Transformers closely satisfy this conservation law, whereas randomly initialized models do not. Leveraging the Jacobian matrix and information entropy, we design a confidence metric and develop Jacobian steering—a minimal-perturbation intervention method for controlled hidden-state manipulation. We validate the approximate energy conservation phenomenon across multiple open-source Transformer architectures. Generated text under our method exhibits superior energy stability and semantic quality compared to native LLM outputs.
📝 Abstract
We take a physics-based approach to studying how the internal hidden states of large language models change from token to token during inference. Across 20 open-source transformer models (135M-3B parameters), we find that a quantity combining the rate of change in hidden states and the model's next-token certainty, analogous to energy in physics, remains nearly constant. Random-weight models conserve this "energy" more tightly than pre-trained ones, while training shifts models into a faster, more decisive regime with greater variability. Using this "log-Lagrangian" view, we derive a control method called Jacobian steering, which perturbs hidden states in the minimal way needed to favor a target token. This approach maintained near-constant energy in two tested models and produced continuations rated higher in semantic quality than the models' natural outputs. Viewing transformers through this mechanics lens offers a principled basis for interpretability, anomaly detection, and low-risk steering. This could help make powerful models more predictable and aligned with human intent.