Abstract
Many popular first-order optimization methods (e.g., Momentum, AdaGrad, Adam) accelerate the convergence rate of deep learning models. However, these algorithms require auxiliary parameters, which cost additional memory proportional to the number of parameters in the model. The problem is becoming more severe as deep learning models continue to grow larger in order to learn from complex, large-scale datasets. Our proposed solution is to maintain a linear sketch to compress the auxiliary variables. We demonstrate that our technique has the same performance as the full-sized baseline, while using significantly less space for the auxiliary variables. Theoretically, we prove that count-sketch optimization maintains the SGD convergence rate, while gracefully reducing memory usage for large-models. On the large-scale 1-Billion Word dataset, we save 25% of the memory used during training (8.6 GB instead of 11.7 GB) by compressing the Adam optimizer in the Embedding and Softmax layers with negligible accuracy and performance loss. For an Amazon extreme classification task with over 49.5 million classes, we also reduce the training time by 38%, by increasing the mini-batch size 3.5x using our count-sketch optimizer.
Introduction
As deep learning models scale to billions of parameters, the bottleneck isn't just the model itself—it’s the "optimizer tax." Popular first-order optimizers like Adam require storing two auxiliary variables (the first and second moments of gradients) for every parameter. If your model has 100 million parameters, Adam effectively requires memory for 300 million.
This memory overhead forces a difficult trade-off: practitioners must either use smaller models or reduce their mini-batch sizes. Reducing batch size is particularly painful because it prevents GPUs from running at full efficiency and slows down convergence. The authors tackle this by asking: Can we store these auxiliary variables in a compressed format that still allows the optimizer to work effectively?
Methods
The authors propose using the Count-Sketch—a classic data structure from the "streaming algorithms" world—to maintain optimizer states.
The Count-Sketch Tensor
Standard sketching usually compresses a vector into a smaller one. However, to keep things fast on modern hardware (GPUs), the authors developed a Count-Sketch Tensor. Instead of hashing every single value, they preserve the last dimension of the parameter tensor (the "embedding dimension" $d$) and only sketch the "feature" or "class" dimension. This allows for contiguous memory access and takes advantage of SIMD (Single Instruction, Multiple Data) instructions, ensuring that compression doesn't come at the cost of massive computational slowdowns.
Handling Different Optimizers
- Momentum/Adam (1st Moment): These can be positive or negative. The authors use a standard Count-Sketch with random sign functions to provide an unbiased estimate.
- Adagrad/Adam (2nd Moment): These are strictly non-negative (squared gradients). For these, they use a Count-Min Sketch.
- The Cleaning Heuristic: Count-Min sketches naturally overestimate values due to collisions. To fix this, the authors introduce a "cleaning" step where they periodically multiply the sketch by a decay constant $\alpha$, preventing the estimated learning rates from prematurely "shrinking" to zero.
Key Insights and Ideas
- Linearity is Key: Sketching works here because the update operations for auxiliary variables (like adding a new gradient to a running sum) are linear.
- Power-Law Distributions: The authors observed that gradient magnitudes typically follow a power-law distribution. Sketching is mathematically ideal for this scenario because it accurately captures "heavy hitters" (the most important gradients) while gracefully handling the "noise" of smaller values.
- Superiority over Low-Rank: They compared their method against Low-Rank (NMF) approximations and found that Count-Sketches were both more accurate and faster, especially for variables that can take negative values (like Momentum).
Key Results
The researchers evaluated their method across a wide range of tasks, including language modeling (Wikitext, LM1B), computer vision (ImageNet, MegaFace), and extreme classification (Amazon dataset with 49.5M classes).
- Memory Savings: On the 1-Billion Word dataset, they reduced memory usage by 25% (from 10.8 GB down to 7.7 GB) with virtually no loss in accuracy.
- Training Speedup: In the Amazon extreme classification task, the memory savings allowed them to increase the mini-batch size by 3.5x. This resulted in a 38% reduction in total training time.
- Accuracy Preservation: Across almost all tests, the "Sketched" optimizers performed on par with the full-sized baselines. In some cases (like Wikitext-103), the sketched version actually achieved slightly better test perplexity.
Limitations and Future Work
While the method excels at sparse layers (like embeddings and large softmax layers), the authors note that for purely dense convolutional networks (like ResNet), the memory savings are less dramatic because the gradients aren't as sparse. Additionally, the "cleaning" heuristic for Count-Min sketches introduces new hyperparameters (cleaning frequency and decay rate) that might require tuning for specific architectures. Future directions include combining this sketching technique with sparse hidden layers to allow for even more massive models that grow sub-linearly in memory cost.
Summary updated