The official implementation of the Frequency SGD with Momentum (FSGDM) optimizer in PyTorch.
Project description
FSGDM
FSGDM (Frequency Stochastic Gradient Descent with Momentum) is an optimizer implemented in PyTorch that dynamically adjusts the momentum filtering characteristics using an empirically effective dynamic magnitude response.
Paper: On the Performance Analysis of Momentum Method: A Frequency Domain Perspective
Authors: Xianliang Li, Jun Luo, Zhiwei Zheng, Hanxiao Wang, Li Luo, Lingkun Wen, Linlong Wu, Sheng Xu
This repository contains the official PyTorch implementation of FSGDM.
Usage
Install torch and run
pip install fsgdm
or simply copy the fsgdm.py file to your codebase.
Then use the FSGDM optimizer in the following fashion
from fsgdm import fsgdm
optimizer = FSGDM(
model.parameters(),
lr = lr,
weight_decay = weight_decay,
c_scaling = c_scaling,
v_coeffcicent = v_coeffcicent,
n_stages = n_stages,
sigma = sigma
)
Replace lr, weight_decay, c_scaling, v_coefficient, n_stages, and sigma with values suitable for your task.
Hyperparameter choices:
- lr & weight_decay: We recommend using the same values as those typically used for SGDM in PyTorch.
- c_scaling & v_coefficient: These parameters should lie in the optimal zone. For CNNs, a good rule of thumb is to aim for the region where
30.992/v_coefficient ≈ 1 + 1/c_scaling. - n_stages: The number of training stages. Users can experiment with different values to find the best configuration for specific tasks.
- sigma: The number of gradient update steps. Users need to compute this value manually.
Remark: The optimal hyperparameter zones can vary across different tasks. We welcome contributions that explore these optimal zones for various learning tasks.
Examples
Examples of using the fsgdm package can be found in the examples folder. These include:
- Image classification (CIFAR-100) using ResNet50*
- More examples to be added
*This example is modified from the code generated by GPT-4o.
Frequency Domain Analysis Framework in a Nutshell
The momentum method can be interpreted as a time-invariant filter for gradients, where adjustments to momentum coefficients modify the filter characteristics.
The high-frequency gradient components correspond to large and more abrupt changes in the gradient; while the low-frequency components indicate smooth and more gradual adjustments.
Significant findings for DNN training:
- High-frequency gradient components are undesired in the late stages of training
- Preserving the original gradient in the early stages improves performance
- Gradually amplifying low-frequency gradient components during training enhances performance
For a more detailed explanation, please refer to our paper.
Paper
If you find FSGDM useful in your research, please cite our paper in the following format.
@inproceedings{
li2025on,
title={On the Performance Analysis of Momentum Method: A Frequency Domain Perspective},
author={Xianliang Li and Jun Luo and Zhiwei Zheng and Hanxiao Wang and Li Luo and Lingkun Wen and Linlong Wu and Sheng Xu},
booktitle={The Thirteenth International Conference on Learning Representations},
year={2025},
url={https://openreview.net/forum?id=tznvtmSEiN}
}
License
See the License file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fsgdm-1.0.tar.gz.
File metadata
- Download URL: fsgdm-1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bea1f0ebc217f6d32f8aa504fd3f85a223806e2e1ab70bae3358283939be3d3
|
|
| MD5 |
2f9651dfe3e45a64e8daca99fffc5768
|
|
| BLAKE2b-256 |
3563f32576e4d8df68563182bddb24c07ba64c3551bbbb6ed90ff317a17c7bca
|
File details
Details for the file fsgdm-1.0-py3-none-any.whl.
File metadata
- Download URL: fsgdm-1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed0ad174647f2200ea92ca057cb1990df9cf3df3e51a7f22b8487d317441494a
|
|
| MD5 |
ad19769ab5907be3a69e14866c03024f
|
|
| BLAKE2b-256 |
ea902ca02d2230b3f908c147124a25dbb5ed2816927b6bf42dc1fbe326d22628
|