Skip to main content

Grokfast - Pytorch (wip)

Explorations into "Grokfast, Accelerated Grokking by Amplifying Slow Gradients", out of Seoul National University in Korea. In particular, will compare it with NAdam on modular addition as well as a few other tasks, since I am curious why those experiments are left out of the paper. If it holds up, will polish it up into a nice package for quick use.

The official repository can be found here

Install

$ pip install grokfast-pytorch

Usage

import torch
from torch import nn

# toy model

model = nn.Linear(10, 1)

# import GrokFastAdamW and instantiate with parameters

from grokfast_pytorch import GrokFastAdamW

opt = GrokFastAdamW(
    model.parameters(),
    lr = 1e-4,
    weight_decay = 1e-2
)

# forward and backwards

loss = model(torch.randn(10))
loss.backward()

# optimizer step

opt.step()
opt.zero_grad()

Todo

  • run all experiments on small transformer
    • modular addition
    • pathfinder-x
    • run against nadam and some other optimizers
    • see if exp_avg could be repurposed for amplifying slow grads
  • add the foreach version only if above experiments turn out well

Citations

@inproceedings{Lee2024GrokfastAG,
    title   = {Grokfast: Accelerated Grokking by Amplifying Slow Gradients},
    author  = {Jaerin Lee and Bong Gyun Kang and Kihoon Kim and Kyoung Mu Lee},
    year    = {2024},
    url     = {https://api.semanticscholar.org/CorpusID:270123846}
}
@misc{kumar2024maintaining,
    title={Maintaining Plasticity in Continual Learning via Regenerative Regularization},
    author={Saurabh Kumar and Henrik Marklund and Benjamin Van Roy},
    year={2024},
    url={https://openreview.net/forum?id=lyoOWX0e0O}
}
@inproceedings{anonymous2024the,
    title   = {The Complexity Dynamics of Grokking},
    author  = {Anonymous},
    booktitle = {Submitted to The Thirteenth International Conference on Learning Representations},
    year    = {2024},
    url     = {https://openreview.net/forum?id=07N9jCfIE4},
    note    = {under review}
}

Metadata

Release files for grokfast-pytorch 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grokfast-pytorch 0.0.11
File Size Uploaded
grokfast_pytorch-0.0.11.tar.gz 146.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for grokfast-pytorch 0.0.11
File Interpreter ABI Platform
grokfast_pytorch-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 152.9 kB

Release files / grokfast_pytorch-0.0.11.tar.gz

Download URL grokfast_pytorch-0.0.11.tar.gz
Size 146.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ddd058ec2c0828f3ae26e8c23c0146cd0b8157864c77187368e11e1042abed84
BLAKE2b-256 checksum
How to use checksums
b1a1e30d47919b92c71655dec825789a948ebb820a73d2b9986a4ab036f85313
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release files / grokfast_pytorch-0.0.11-py3-none-any.whl

Download URL grokfast_pytorch-0.0.11-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0eb6390441c77d6c16145e433043500e774c7f62ccafdcec02af4bd5aa59d01
BLAKE2b-256 checksum
How to use checksums
a949432a7718e176528ff7d5eec86690201ff7792a7c203b8fd73c87fc7cbdc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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