Neural Thermodynamic Laws for Large Language Model Training
Published 15 May 2025 in cs.LG, cs.AI, physics.data-an, and stat.ML | (2505.10559v1)
Abstract: Beyond neural scaling laws, little is known about the laws underlying LLMs. We introduce Neural Thermodynamic Laws (NTL) -- a new framework that offers fresh insights into LLM training dynamics. On the theoretical side, we demonstrate that key thermodynamic quantities (e.g., temperature, entropy, heat capacity, thermal conduction) and classical thermodynamic principles (e.g., the three laws of thermodynamics and the equipartition theorem) naturally emerge under river-valley loss landscape assumptions. On the practical side, this scientific perspective yields intuitive guidelines for designing learning rate schedules.
The paper introduces a framework that maps LLM loss landscapes to thermodynamic principles, decomposing losses into fast (thermal) and slow (river) dynamics.
The paper derives optimal learning rate decay schedules, showing that a 1/t decay effectively minimizes thermal loss and aligns with empirical trends in LLM training.
The paper demonstrates that entropic forces subtly influence optimizer trajectories, supporting the use of higher stable-phase learning rates to reduce final validation loss.
This paper, "Neural Thermodynamic Laws for LLM Training" (2505.10559), introduces a novel framework, Neural Thermodynamic Laws (NTL), that draws analogies between the training dynamics of LLMs and principles from classical thermodynamics. The core idea is to leverage this analogy to gain theoretical insights into LLM training, particularly concerning the complex learning rate schedules used in practice.
The framework is built upon the observation that the loss landscape of LLMs exhibits a "river-valley" structure. This structure is characterized by directions of high sharpness (valleys) and directions of flatness (rivers). Training dynamics can be decomposed into fast dynamics (rapid movement and fluctuations within the sharp valleys) and slow dynamics (gradual movement along the flat riverbed). This decomposition is analogous to the quasi-static equilibrium found in thermodynamics, where fast microscopic degrees of freedom (like gas molecules) equilibrate rapidly while macroscopic variables (like piston volume) change slowly. The paper maps the total loss ℓ to internal energy U, decomposing it into a fast component ℓf (thermal loss, analogous to heat Q) and a slow component ℓs (river loss, analogous to work W).
To formalize this, the authors propose a 2D toy model of the river-valley landscape: ℓ(x,y)=21a(y)x2+c(y). Here, x is the fast variable and y is the slow variable. a(y) represents the sharpness of the valley at position y, and c(y) is the loss at the bottom of the valley (the riverbed). The fast loss is ℓf(x,y)=21a(y)x2 and the slow loss is ℓs(y)=c(y).
Fast Dynamics in Equilibrium (Stable Phase)
Focusing on the fast variable x while holding y fixed, the toy model reduces to a 1D quadratic loss ℓf(x)=21ax2. The paper analyzes the dynamics of Stochastic Gradient Descent (SGD) and Signed Gradient Descent (SignGD) on this loss with a fixed learning rate η and gradient noise σg. Under certain conditions (specifically, 0<a<2/η for SGD), the dynamics converge to a Gaussian steady-state distribution p(x) with a standard deviation σ.
For SGD, in the flat limit (aη≪1), the standard deviation is approximately σSGD≈2aησg.
For SignGD, in the flat limit (aη≪σg/η), it's approximately σSignGD≈(8π)1/4aσgη.
In both cases, σ∝η1/2a−1/2σgn (where n=1 for SGD, n=1/2 for SignGD). This shows that σ increases with η and σg and decreases with sharpness a. The average thermal loss is ℓf=E[21ax2]=21aσ2. Substituting the flat-limit approximations for σ, we find that ℓf becomes independent of a:
For SGD: ℓfSGD≈21a(2aησg2)=41ησg2.
For SignGD: ℓfSignGD≈21a((8π)1/2aσgη)=32πσgη.
This independence of ℓf from sharpness a is analogous to the equipartition theorem in thermodynamics, where energy is distributed equally among quadratic degrees of freedom regardless of their 'stiffness'. The paper interprets the learning rate η as an effective temperature (T∼η) because the thermal loss ℓf scales linearly with η. The rate of change of thermal loss with respect to η, C≡∂ℓf/∂η, is interpreted as heat capacity.
Practical Implication: The average loss contributed by fast dynamics in any given direction in the valley is roughly proportional to the learning rate and independent of how sharp that direction is. This suggests that reducing the learning rate is a direct way to reduce the fluctuations and corresponding loss contribution in the valley directions. This also explains why the validation loss at the end of the decay phase in LLM training often scales linearly with the final learning rate ηmin, as shown in empirical experiments on GPT-2 [(2505.10559), Figure 2b].
Fast Dynamics in Annealing (Decay Phase)
During the decay phase of training, the learning rate η is gradually reduced. As η decreases, the standard deviation σ of the fast variable distribution is expected to decrease, reducing the thermal loss ℓf. However, η also acts as a step size, influencing the speed at which the system can adapt to the changing 'temperature'. If η decays too quickly, the system might not maintain equilibrium, leading to sub-optimal reduction in ℓf.
The paper derives an optimal learning rate decay schedule for the 1D quadratic toy model that minimizes σt at each step t. Starting from an initial learning rate η, the optimal schedule is found to be approximately ηt∝1/t, specifically ηt=1+t/thη/2 where th is a characteristic time scale depending on a, η, and σg. For SGD, thSGD=2/(aη), and for SignGD, thSignGD=2πσg/(aη). This schedule predicts that decaying to η=0 would take infinite time, implying that decaying to zero in finite time might be suboptimal.
The evolution of thermal loss under a sudden drop in learning rate (from ηA to ηB) is shown to follow an exponential decay towards the new equilibrium loss ℓeq(ηB), similar to Fourier's law of thermal conduction (Q∝TA−TB). This process is also related to the second law of thermodynamics, as the system cannot reach a thermal loss lower than the equilibrium loss at the final temperature ηB.
Practical Implication: The optimal $1/t$ decay schedule provides a theoretical basis for non-linear decay schedules observed to perform well in practice (e.g., 1-sqrt decay). It suggests that the rate of decay should depend on the sharpness a and noise level σg. Furthermore, decaying the learning rate too quickly can prevent the system from reaching the desired low thermal loss, leading to higher final validation loss. Empirical results in the paper's appendix support that starting the decay too late (shortening the decay phase) can be detrimental.
River Dynamics and Entropic Forces
The fast dynamics in the valley can influence the slow dynamics along the river. In the 2D toy model ℓ(x,y)=21a(y)x2+c(y), the equilibrium distribution over x at a fixed y depends on a(y). The slow variable y experiences a force composed of the gradient of the slow loss c(y) (Fbtm=−c′(y)) and an effective entropic force arising from the average of the fast gradient with respect to y:
Fent=−∂ℓf/∂y=−21a′(y)x2=−21a′(y)σ(y)2.
Substituting σ(y)2∝ησgn/a(y), we get Fent∝−a(y)σgnηa′(y)∝−ησgna(y)a′(y).
The term a(y)a′(y) can be written as dyd(loga(y)), suggesting that −21loga(y) can be related to entropy. Specifically, the entropy of the Gaussian distribution p(x) scales as S∝logσ∝−21loga(y). The entropic force is proportional to the gradient of −loga(y), pushing the slow variable y towards regions of lower sharpness (larger a(y) is sharper, so smaller $1/a(y)$ is flatter).
Practical Implication: Entropic forces can influence the path taken along the riverbed. If the river runs through a region where the valley widens rapidly (a′(y)<0), the entropic force pushes the optimizer forward along the river. If the valley narrows rapidly (a′(y)>0), the entropic force pushes backward. This can lead to "entropic trapping" where the optimizer gets stuck if the entropic force opposes the gradient of the slow loss. The magnitude of this force depends on η and σg.
The paper tests for the existence of entropic forces in LLM training by comparing loss curves for schedules with different stable learning rates but the same total η sum. In the gradient flow limit (η→0), only the η sum matters for the final state of the slow variables. Any misalignment observed with finite η indicates entropic forces. The LLM experiments show relatively good alignment, suggesting that entropic forces are small but slightly negative (pushing towards flatter regions), corresponding to a slightly narrowing valley structure along the river on average in the early training phase.
Summary of Learning Rate Roles and Final Loss
The learning rate η plays multiple roles:
Temperature/Gaussian Width: Controls the magnitude of fluctuations in valley directions (σ∝η).
Entropic Force Magnitude: Scales the entropic force (∝ησgn).
Time Scale/Step Size: Controls the speed of movement along both valley and river directions.
The final training loss is influenced by the total learning rate sum (D, which primarily affects the slow loss ℓs) and the final learning rate ηmin (which controls the final thermal loss ℓf), plus potential corrections from entropic forces (Δentropic) and insufficient annealing (Δanneal).
ℓfinal≈ℓ(D,ηmin)+Δentropic+Δanneal.
To reduce the final loss, one can reduce ηmin or increase the total η sum D. Reducing ηmin requires a longer decay phase to avoid insufficient annealing (Δanneal). Increasing D can be achieved by increasing the stable phase learning rate η. The paper's experiments suggest that larger stable phase η can lead to lower loss (due to increased D) without significantly increasing the required decay time (as Td∼1/ηmin is independent of stable η) or introducing large entropic forces (which were found to be small). This supports the use of potentially higher stable phase learning rates than currently common, provided numerical stability is maintained.
Implementation Considerations and Limitations
The analysis provides practical intuition for designing learning rate schedules.
The stable phase helps accumulate η sum (D) for progress along the river.
The decay phase reduces η to minimize final thermal loss ℓf.
The optimal decay is roughly $1/t$.
Decaying to ηmin>0 might be better than ηmin=0.
Increasing the stable phase η (within limits of numerical stability and edge of stability) might be an effective way to reduce final loss by increasing the η sum.
The paper highlights several limitations of the current analysis, acknowledging that it uses a physicist's approach emphasizing intuition and simplification over mathematical rigor:
The derivations assume isotropic or 1D quadratic landscapes, whereas LLM loss landscapes are highly anisotropic and complex.
The river is treated as straight, but it is likely curved in practice.
Momentum and weight decay are ignored, which are crucial components of modern optimizers like Adam and AdamW.
The Gaussian approximation for steady states is not always strictly accurate.
Despite these simplifications, the framework provides valuable qualitative and semi-quantitative insights that align with empirical observations in LLM training and offer guiding principles for hyperparameter tuning and optimizer design. Future work could extend this framework to incorporate more realistic landscape features and optimizer complexities.
“Emergent Mind helps me see which AI papers have caught fire online.”
Philip
Creator, AI Explained on YouTube
Sign up for free to explore the frontiers of research
Discover trending papers, chat with arXiv, and track the latest research shaping the future of science and technology.Discover trending papers, chat with arXiv, and more.