Skip to main content

AFOR

AFOR is a tensor-wise adaptive forgetting optimizer for PyTorch. It adapts the second-moment decay coefficient from local gradient residuals, direction consistency, and online Z-score normalization.

Installation

pip install afor-optimizer

Usage

import torch
from AFOR import afor

model = torch.nn.Linear(10, 2)
optimizer = afor(
    model.parameters(),
    lr=1e-3,
    betas=(0.9, 0.999),
    beta2_min=0.99,
    dir_weight=1.0,
    weight_decay=1e-4,
)

inputs = torch.randn(16, 10)
targets = torch.randint(0, 2, (16,))
loss = torch.nn.functional.cross_entropy(model(inputs), targets)
loss.backward()
optimizer.step()
optimizer.zero_grad()

Main Parameters

  • lr: learning rate.
  • betas: first-moment and initial second-moment coefficients.
  • beta2_min: lower bound for the adaptive second-moment coefficient.
  • dir_weight: weight of gradient-direction consistency.
  • eps: numerical stability term.
  • weight_decay: decoupled weight decay.
  • fast_ref: use the larger fast/slow noise estimate as the noise reference.

AFOR currently supports dense gradients only.

License

Released under the MIT License. See LICENSE.

Download files

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

Source Distribution

afor_optimizer-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

afor_optimizer-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: afor_optimizer-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.18

File hashes

Hashes for afor_optimizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a519d28b1a67d620ee8055997d0325e56184065c99a5d2b17cc47917c26f513c
MD5 4476f7c521d345cd1632bde33aac8e37
BLAKE2b-256 a8be8993b2fdf6459403b3983f76fc5d765c09a45c12c49f059ecc3891d76902

See more details on using hashes here.

File details

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

File metadata

  • Download URL: afor_optimizer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.18

File hashes

Hashes for afor_optimizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb7cdd866e2e943f9315ca651786df82faf136255a743b288771436639c980bf
MD5 818cc54775d15005c2e1d39a90a23636
BLAKE2b-256 f056b94910837c9aa693b5b0f6c64d7a7b16550f6bf421e078e13768e40b5973

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page