Shuffle SGD is Always Better than SGD: Improved Analysis of SGD with Arbitrary Data Orders

Anastasia Koloskova, Nikita Doikov, Sebastian U. Stich, Martin Jaggi · OpenReview

Abstract

Stochastic Gradient Descent (SGD) algorithms are widely used in optimizing neural networks, with Random Reshuffling (RR) and Single Shuffle (SS) being popular choices for cycling through random or single permutations of the training data. However, the convergence properties of these algorithms in the non-convex case are not fully understood. Existing results suggest that, in realistic training scenarios where the number of epochs is smaller than the training set size, RR may perform worse than SGD. In this paper, we analyze a general SGD algorithm that allows for arbitrary data orderings and show improved convergence rates for non-convex functions. Specifically, our analysis reveals that SGD with random and single shuffling is always faster or at least as good as classical SGD with replacement, regardless of the number of iterations. Overall, our study highlights the benefits of using SGD with random/single shuffling and provides new insights into its convergence properties for non-convex optimization.

Introduction: The Theory-Practice Gap

In machine learning practice, "pure" SGD—sampling data points uniformly at random with replacement—is rarely used. Instead, practitioners favor methods that involve shuffling the data once (Single Shuffle), shuffling every epoch (Random Reshuffling), or cycling through data in a fixed order (Incremental Gradient). These approaches are cache-friendly and empirically faster.

However, a persistent gap has existed between theory and practice. Standard optimization theory for non-convex functions often suggested that these ordered methods were significantly slower than random sampling. Specifically, prior bounds showed a dependency on $O(n/\epsilon)$, implying that as the dataset size ($n$) grows, the number of iterations required to reach a specific accuracy $\epsilon$ increases linearly. This paper resolves this pessimistic outlook by providing a tighter, modern analysis.

Methodology: Effective Correlation Time

The authors introduce a unified framework to analyze arbitrary data orderings. The core of their approach is a new metric called Sequence Correlation, which quantifies how much a specific data sequence deviates from the true gradient.

The pivotal concept in their proof is the effective correlation time ($\tau$). While previous research typically analyzed these algorithms in fixed "epochs" of size $n$, this analysis divides the training process into smaller chunks of size $\tau = \Theta(1/L\gamma)$, where $L$ is the smoothness and $\gamma$ is the step size. By making the analysis window adaptive to the step size rather than the dataset size, the authors prove that the algorithm makes significantly more progress per step. They utilize a perturbed iterate analysis, comparing the actual path of the algorithm to a "virtual" noiseless sequence that restarts every $\tau$ iterations.

Empirical Validation

The theoretical findings were validated using synthetic quadratic objectives, logistic regression on standard LibSVM datasets (e.g., a9a, rcv1), and deep learning architectures including a three-layer CNN on MNIST and ResNet-18 on CIFAR-10.

Convergence of gradient norm and iteration count vs dataset size.

As shown in the figure above, Single Shuffle (SS) and Random Reshuffling (RR) consistently reach lower gradient norms faster than standard SGD across various learning rates ($\gamma$). Furthermore, the plot of $T_{\min}(n, \epsilon)$ demonstrates that the number of iterations required to reach a target accuracy does not suffer from the linear $n$-dependence predicted by older theories; instead, SS and RR maintain a clear advantage over SGD as the dataset size increases.

Key Insights and Results

  • Removal of $n$-dependence: The linear penalty on dataset size $n$ found in previous literature was an artifact of the mathematical tools used, not a failure of the algorithms. The authors improved the optimization term of the convergence guarantee from $O(n/\epsilon)$ to $O(1/\epsilon)$, a $1/n$ improvement.
  • Strength of Single Shuffle: Shuffling data just once at the beginning (SS) provides convergence guarantees strictly better than previously known best rates, often performing nearly as well as shuffling every epoch.
  • Larger Step Sizes: The shorter correlation periods used in the analysis allow for larger theoretical step sizes, translating to faster convergence in the optimization term.
  • Empirical Superiority: Across logistic regression and deep learning tasks, SS and RR consistently outperformed standard uniform SGD. In CIFAR-10 experiments, Single Shuffle achieved the best overall performance.

Limitations and Future Work

While this work significantly advances our understanding, some questions remain. The leading stochastic noise term for Random Reshuffling still contains a dependency on $n$; whether this can be removed entirely is an open question. Additionally, the current analysis relies on $L$-smoothness. Extending these high-precision results to non-smooth functions or constrained settings remains a challenge. Finally, while the optimization term is improved, the bound for RR's stochastic part is currently $\sqrt{n}$ worse than some specialized RR analyses. Finding a single bound optimal in both terms is the next frontier for this research.

Summary updated

BibTeX
@inproceedings{koloskova2024shuffle,
  author = {Anastasia Koloskova and Nikita Doikov and Sebastian U. Stich and Martin Jaggi},
  title = {{Shuffle SGD is Always Better than SGD: Improved Analysis of SGD with Arbitrary Data Orders}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=ZRMQX6aTUS},
}
Figure