Skip to main content

Noise-robust PyTorch optimizer with automatic confidence-based learning rate adaptation

Project description

CASMO: Confident Adaptive Selective Momentum Optimizer

Python 3.8+ License: MIT Paper: Theory

The Optimizer That Knows What To Learn.

Abstract

CASMO is a novel optimization algorithm designed to address the limitations of uniform gradient application in deep learning. Unlike standard optimizers (e.g., AdamW, SGD) that treat all gradients as equally valid, CASMO introduces Adaptive Gradient-Aware Regularization (AGAR). This mechanism dynamically quantifies the "signal-to-noise" ratio of gradients over time, allowing the optimizer to selectively dampen updates that correspond to noise, outliers, or conflicting information while accelerating learning on generalizable patterns.

This approach yields state-of-the-art stability in challenging regimes such as label noise, long-tail distributions, differential privacy, and continual learning.


� Key Innovation: The AGAR Mechanism

The core of CASMO is the Adaptive Gradient Alignment Ratio (AGAR), a metric that measures the consistency of gradient direction over a sliding window:

$$ \text{AGAR} = \frac{||\mathbb{E}[g]||^2}{||\mathbb{E}[g]||^2 + \text{Var}[g]} $$

  • High AGAR ($\approx 1$): Indicates consistent, reliable signal (e.g., generalizable features). CASMO applies full updates.
  • Low AGAR ($\approx 0$): Indicates high variance or conflict (e.g., label noise, privacy noise, catastrophic forgetting). CASMO automatically dampens the learning rate.

This allows CASMO to act as an automatic filter during training, improving robustness without manual hyperparameter tuning or data filtering.


⚡ Quick Start

Installation

git clone https://github.com/abderahmane-ai/CASMO.git
cd CASMO
pip install -e .

Usage

CASMO is a drop-in replacement for torch.optim.AdamW.

from casmo import CASMO

# Initialize with standard parameters
optimizer = CASMO(
    model.parameters(), 
    lr=1e-3, 
    weight_decay=0.01,
    granularity='group'  # Recommended for efficiency
)

# Standard PyTorch training loop
for batch in dataloader:
    optimizer.zero_grad()
    loss = model(batch)
    loss.backward()
    optimizer.step()

🧪 Benchmarks & Reproducibility

We provide a comprehensive suite of benchmarks demonstrating CASMO's superiority in specific failure modes of standard optimizers. Each benchmark contains full reproduction scripts and detailed analysis.

Benchmark Domain Challenge Link
B2 Generalization Grokking with 30% Label Noise View Benchmark
B3 Long-Tail CIFAR-100 Class Imbalance (100:1) View Benchmark
B4 Privacy DP-SGD with High Noise ($\epsilon \approx 0.37$) View Benchmark
B6 Fine-Tuning Noisy Instruction Tuning (LLMs) View Benchmark
B7 Continual Learning Catastrophic Forgetting (Seq. Tasks) View Benchmark

🛠️ Configuration

Parameter Default Description
lr 1e-3 Base learning rate.
weight_decay 0.0 Decoupled weight decay (same as AdamW).
granularity 'group' 'group' (Fast, recommended) or 'parameter' (Precise).
tau_init_steps 500 Steps for initial AGAR calibration (auto-tuned).
c_min 0.1 Minimum confidence floor (prevents dead neurons).

Citation

If you use CASMO in your research, please cite:

@software{casmo2025,
  title={CASMO: Confident Adaptive Selective Momentum Optimizer},
  author={Ainouche, Abderahmane},
  year={2025},
  url={https://github.com/abderahmane-ai/CASMO}
}

Made with ❤️ for the ML research community.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

casmo_optimizer-0.1.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

casmo_optimizer-0.1.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file casmo_optimizer-0.1.0.tar.gz.

File metadata

  • Download URL: casmo_optimizer-0.1.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for casmo_optimizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0a801b4ccf50b573fbc63a92e4dac1f1bfbf038f34bfa29f1b6ba0b23ff5931d
MD5 8aba10b24fb5d05163611e07e2798cd6
BLAKE2b-256 b30d21e5709933b6dcd3e7d71ae54c07645fa611f2e62f61c24feb04463750af

See more details on using hashes here.

File details

Details for the file casmo_optimizer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for casmo_optimizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f41b181303cf4d319266e470a72af735a3c977c70fd70742b15cd6de5022a2b
MD5 420e0fe9afb914fe58858a5dd73b2cf3
BLAKE2b-256 a4976ef4e183cc48419082bbb9a9293fd42a8d93450b54ff022edcab60db237d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page