Improved Stochastic Optimization of LogSumExp

Egor Gladin, Alexey Kroshnin, Jia-Jie Zhu, Pavel Dvurechensky

Abstract The LogSumExp (LSE) function, dual to the Kullback-Leibler (KL) divergence, is foundational to optimization problems in machine learning, including entropy-regularized Optimal Transport (OT) and Distributionally Robust Optimization (DRO). However, when the number of exponential terms is massive or infinite, computing gradients becomes computationally prohibitive. Standard minibatch sampling introduces biased gradient estimators, and the function is notoriously prone to numerical overflow. This paper introduces a novel, convexity-preserving approximation to LSE based on a new $f$-divergence called the Safe KL divergence. By enabling unbiased stochastic optimization, this approach eliminates numerical crashes and significantly improves convergence in large-scale OT and DRO tasks.

1. The Challenge of Scaling LogSumExp

The LogSumExp function is a workhorse of modern machine learning, appearing in everything from multiclass classification (softmax) to complex optimization frameworks like OT and DRO. Despite its ubiquity, LSE suffers from critical scaling and stability issues.

When dealing with a massive or infinite number of terms—such as in continuous probability distributions—computing the exact gradient requires differentiating every single exponential term. To circumvent this, practitioners typically sample a "minibatch" of terms. However, because the logarithm is a non-linear function, the average of the logs does not equal the log of the averages (due to Jensen's Inequality). This fundamental mathematical reality results in biased gradient estimators, which severely degrade convergence.

Furthermore, LSE is numerically temperamental. The exponential terms inside the function can easily exceed the maximum representable value in standard floating-point arithmetic. This leads to "overflow" or NaN errors, particularly when regularization is weak.

2. A Novel Approach: Safe KL Divergence

To resolve these bottlenecks, the authors propose a novel approximation of the log-partition functional (the generalized version of LSE) using a SoftPlus-based relaxation. The core innovation lies in a variational formulation where the standard Kullback-Leibler (KL) divergence is replaced with a new $f$-divergence, termed the Safe KL divergence.

This method relies on three key pillars:

  • The Auxiliary Variable Trick: The authors introduce an auxiliary scalar variable, $\alpha$, which allows the expectation to be moved outside the logarithm. This structural change transforms the problem into a form solvable via standard Stochastic Gradient Descent (SGD) using strictly unbiased gradients.
  • Overflow-Safe Optimization: Unlike standard KL divergence, which permits infinite density ratios, Safe KL imposes a hard cap on reweighting, controlled by a hyperparameter $\rho$. This ensures the density ratio $d\nu/d\mu$ never exceeds $1/\rho$. By preventing any single data point from exerting an exploding influence on the gradient, the optimization becomes inherently "overflow-safe."
  • Preserving Convexity: A crucial theoretical guarantee of this approach is that if the original loss function is convex, the new approximation remains jointly convex. This ensures that numerical stability is achieved without sacrificing mathematical guarantees.

3. Key Theoretical Insights

The introduction of the Safe KL divergence yields several fascinating theoretical properties:

  • The Bias-Stability Tradeoff: The parameter $\rho$ acts as a tuning dial. A large $\rho$ makes the optimization extremely stable and smooth but introduces a larger approximation gap relative to the true LSE. Conversely, a tiny $\rho$ closely approximates LSE but is harder to optimize. Empirical findings suggest that $\rho = 10^{-3}$ often serves as an effective "sweet spot."
  • A Bridge to CVaR: The Safe KL approximation generates a family of optimization problems that theoretically bridges two major concepts: it includes both LSE minimization and Conditional Value at Risk (CVaR) as limit cases.

4. Experimental Validation

The authors rigorously evaluated their approach across several domains, including continuous entropy-regularized Optimal Transport (eOT) using MNIST and EMNIST-letters, and DRO tasks using the California Housing Dataset and ACS PUMS (2018) income data to test against train-test distribution shifts.

Key Results: * Unprecedented Stability in eOT: In continuous Optimal Transport tasks, standard baselines frequently crashed due to numerical overflow or required agonizingly slow learning rates. The Safe KL method remained stable and converged significantly faster, even under weak regularization. * Superiority in Small Batches: For DRO tasks, the proposed unbiased estimator consistently outperformed biased baselines. This advantage was particularly pronounced when using very small batch sizes (e.g., $|D|=10$). * Robustness to Extreme Noise: When tested on MNIST with 85% label noise, the Safe approach achieved better cross-entropy and ROC AUC scores on the hardest classes compared to standard DRO baselines, demonstrating its ability to handle extreme outliers without destabilizing.

5. Limitations and Future Directions

While the Safe KL divergence offers a robust solution to LSE optimization, it introduces new avenues for refinement:

  • Hyperparameter Tuning: Currently, the stability parameter $\rho$ must be selected manually. Developing an adaptive procedure to dynamically tune $\rho$ during training is a primary goal for future work.
  • Structural Changes: Because Safe KL modifies the original KL divergence, it may alter application-specific theoretical properties of the original problem. These structural impacts must be analyzed on a case-by-case basis.
  • Broader Applications: While the current research focuses on OT and DRO, the "Safe" framework could be extended to other domains where LSE creates a computational bottleneck, such as variational inference or KL-regularized Markov Decision Processes in reinforcement learning.

Summary updated

BibTeX
@inproceedings{gladin2026improved,
  author = {Egor Gladin and Alexey Kroshnin and Jia-Jie Zhu and Pavel Dvurechensky},
  title = {{Improved Stochastic Optimization of LogSumExp}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=TzQElzflxR},
}
Figure