Fast and Accurate Stochastic Gradient Estimation.

Beidi Chen, Yingchen Xu, Anshumali Shrivastava

Abstract

Stochastic Gradient Descent or SGD is the most popular optimization algorithm for large-scale problems. SGD estimates the gradient by uniform sampling with sample size one. There have been several other works that suggest faster epoch-wise convergence by using weighted non-uniform sampling for better gradient estimates. Unfortunately, the per-iteration cost of maintaining this adaptive distribution for gradient estimation is more than calculating the full gradient itself, which we call the chicken-and-the-egg loop. As a result, the false impression of faster convergence in iterations, in reality, leads to slower convergence in time. In this paper, we break this barrier by providing the first demonstration of a scheme, Locality sensitive hashing (LSH) sampled Stochastic Gradient Descent (LGD), which leads to superior gradient estimation while keeping the sampling cost per iteration similar to that of the uniform sampling. Such an algorithm is possible due to the sampling view of LSH, which came to light recently. As a consequence of superior and fast estimation, we reduce the running time of all existing gradient descent algorithms, that relies on gradient estimates including Adam, Ada-grad, etc. We demonstrate the effectiveness of our proposal with experiments on linear models as well as the non-linear BERT, which is a recent popular deep learning based language representation model.

Introduction

Stochastic Gradient Descent (SGD) is the cornerstone of modern large-scale machine learning. Its primary advantage is computational efficiency, as it estimates the gradient of a massive dataset using only a small subset of samples. However, this efficiency is often offset by high variance in the gradient estimates. While importance sampling—weighting samples by their gradient magnitude—can theoretically reduce this variance and accelerate convergence, it introduces a "chicken-and-the-egg" paradox. To identify high-magnitude gradients, one typically needs to compute gradients for the entire dataset, an $O(N)$ operation that negates the benefits of stochastic sampling. Consequently, many theoretically "faster" adaptive sampling methods fail to deliver improvements in actual wall-clock time.

Methodology

To address this bottleneck, we propose LGD (LSH sampled Stochastic Gradient Descent). Our approach repurposes Locality Sensitive Hashing (LSH), traditionally used for efficient nearest-neighbor search, as a high-speed sampling engine.

Overview of the LGD algorithm workflow using Locality Sensitive Hashing for fast sampling.

The LGD process consists of three main phases:

  1. Preprocessing: Training data is hashed into tables. For many common loss functions, the gradient norm is monotonic to the inner product between model parameters ($\theta$) and the data point ($x$), which LSH can efficiently exploit.
  2. Sampling: In each iteration, the current parameters $\theta$ serve as a query. LSH retrieves points with high inner products in $O(1)$ time, effectively performing importance sampling without the $O(N)$ overhead.
  3. Estimation: We utilize a mathematical framework to determine the exact sampling probability for each retrieved point, ensuring that the resulting gradient estimate remains unbiased through proper re-weighting.

Experimental Setup

We evaluated LGD across two distinct domains to demonstrate its versatility:

  • Linear Regression: Benchmarked on three large-scale datasets: YearPredictionMSD, Slice, and UJIIndoorLoc.
  • Deep Learning: Integrated LGD into the fine-tuning of BERT on the MRPC and RTE tasks from the GLUE benchmark.

Results and Discussion

LGD demonstrates significant improvements in both gradient quality and optimization speed.

Comparison of gradient norm and cosine similarity for LGD vs. SGD across PredMSD and Slice datasets.

Superior Gradient Quality

As shown in the figure above, LGD consistently samples points with higher gradient norms compared to uniform SGD. Furthermore, the cosine similarity between the LGD estimate and the true gradient is significantly higher, indicating a more accurate directional update.

Performance and Efficiency

On linear models, LGD achieves lower training loss faster than vanilla SGD and AdaGrad in terms of wall-clock time. The computational overhead of LSH sampling is minimal—approximately 1.5x that of a standard SGD iteration—making it a practical alternative to uniform sampling. Even in the non-linear landscape of BERT fine-tuning, LGD shows substantial epoch-wise convergence gains over standard Adam and SGD optimizers.

Conclusion and Future Work

LGD successfully breaks the "chicken-and-the-egg" loop of adaptive sampling by leveraging LSH for $O(1)$ importance sampling. This leads to higher-quality gradient estimates and faster wall-clock convergence across both linear and deep learning models. Future work will focus on developing native GPU implementations of LSH to further reduce overhead in deep learning workflows and extending the methodology to a broader range of non-linear loss functions.

Summary updated

BibTeX
@inproceedings{chen2019fast,
  author = {Beidi Chen and Yingchen Xu and Anshumali Shrivastava},
  title = {{Fast and Accurate Stochastic Gradient Estimation.}},
  booktitle = {NeurIPS},
  year = {2019},
  url = {https://openreview.net/forum?id=OGT7YQ00t8J6},
}
Figure