Improved Stochastic Optimization of LogSumExp

Egor Gladin, Alexey Kroshnin, Jia-Jie Zhu, Pavel E. Dvurechensky · OpenReview

Abstract

The LogSumExp function, also known as the free energy, plays a central role in many important optimization problems, including entropy-regularized optimal transport and distributionally robust optimization (DRO). It is also the dual to the Kullback-Leibler (KL) divergence, which is widely used in machine learning. In practice, when the number of exponential terms inside the logarithm is large or infinite, optimization becomes challenging since computing the gradient requires differentiating every term. Previous approaches that replace the full sum with a small batch introduce significant bias. We propose a novel approximation to LogSumExp that can be efficiently optimized using stochastic gradient methods. This approximation is rooted in a sound modification of the KL divergence in the dual, resulting in a new $f$-divergence called the safe KL divergence. The accuracy of the approximation is controlled by a tunable parameter and can be made arbitrarily small. Like the LogSumExp, our approximation preserves convexity. Moreover, when applied to an $L$-smooth function bounded from below, the smoothness constant of the resulting objective scales linearly with $L$. Experiments in DRO and continuous optimal transport demonstrate the advantages of our approach over state-of-the-art baselines and the effective treatment of numerical issues associated with the standard LogSumExp and KL.

Introduction

The LogSumExp (LSE) function—and its continuous counterpart, the log-partition functional—is a fundamental component in modern machine learning. It appears prominently in softmax classifiers, entropy-regularized Optimal Transport (OT), and Distributionally Robust Optimization (DRO). However, optimizing LSE at scale presents two significant challenges:

  1. The Summation Bottleneck: In high-dimensional or infinite-dimensional settings, computing the gradient requires differentiating every term in the summation or integral. This makes standard gradient descent computationally prohibitive for large datasets.
  2. Numerical Instability: Computers struggle with exponentials. In dual formulations of OT or DRO, small regularization parameters often lead to values that exceed the representable range of floating-point numbers (overflow), causing optimization algorithms to fail.

While Stochastic Gradient Descent (SGD) is the standard solution for high-dimensional problems, until now, there has been a lack of unbiased and numerically stable stochastic gradient estimators for the LSE function.

Methodology: The Safe KL Divergence

The proposed solution involves a convexity- and smoothness-preserving approximation of the log-partition functional. This innovation is rooted in duality: the standard LSE function is the convex conjugate (dual) of the Kullback-Leibler (KL) divergence. By modifying the KL divergence, the authors introduce the "safe KL divergence" ($D_\rho$).

The safe KL divergence generator $f_\rho(t)$ for various values of $\rho$ compared to the standard KL generator $f_0(t)$.

This new divergence imposes a hard constraint on the probability density reweighting, capped by $1/\rho$. Applying this safe KL in the variational formulation results in an approximation that replaces the raw exponential function with a rescaled SoftPlus function: $\log(1 + e^x)$. The resulting objective is defined as:

$$F_\rho(\phi; \mu) = \inf_{\alpha \in \mathbb{R}} \left\{ \alpha - 1 + \frac{1}{\rho} \int \log(1 + \rho e^{\phi(x)-\alpha}) d\mu(x) \right\}$$

This formulation offers two primary advantages. First, it is numerically stable, as the SoftPlus function is significantly better behaved than raw exponentials. Second, it allows for unbiased stochastic gradients, enabling the estimation of the integral through sampling without needing to differentiate every term.

Experimental Results

The approach was validated across several benchmarks, including continuous entropy-regularized OT tasks (MNIST and EMNIST-letters) and DRO experiments (California Housing dataset).

Stability and Convergence

In continuous OT tasks, traditional baselines frequently suffer from numerical overflow or require extremely small learning rates to maintain stability. The proposed method remains stable even with large learning rates, leading to significantly faster convergence.

Training loss comparison on continuous OT tasks, demonstrating the numerical stability of the proposed approach versus baseline overflows.

Performance in DRO

On the California Housing dataset, the proposed gradient estimator outperformed state-of-the-art biased estimators, particularly in small batch size regimes. Furthermore, because the "Safe KL" prevents density from exploding, the method demonstrates natural resilience to outliers compared to standard KL-based DRO.

Discussion and Insights

The parameter $\rho$ serves as a critical trade-off dial: a large $\rho$ ensures stable convergence, while a small $\rho$ increases accuracy at the cost of smoothness. The authors found that $\rho = 10^{-3}$ typically provides an optimal balance. Theoretically, this approximation generates a family of problems that includes both LogSumExp minimization and Conditional Value-at-Risk (CVaR) as limit cases.

While the method requires some tuning of $\rho$, it preserves the essential mathematical geometry (convexity and smoothness) of the original problem. Future work may extend this "Safe LSE" to other domains such as Bayesian inference and reinforcement learning, providing a robust toolkit for managing exponential complexity in large-scale optimization.

Summary updated

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