Skip to main content

smartclip

PyPI version CI Docs Build Docs Python Versions License: MIT

Adaptive gradient clipping for PyTorch, TensorFlow, and JAX.

SmartClip keeps training stable with adaptive, per-step clipping you can enable in one line of code.

See the full documentation for details of the algorithms, framework usage examples, and logging metrics.

Supported Algorithms

Install

pip install smartclip

Optional extras provide helpers for specific frameworks (install framework wheels first per vendor docs):

pip install "smartclip[torch]"    # PyTorch + Lightning/Transformers helpers
pip install "smartclip[tf]"       # TensorFlow/Keras helpers
pip install "smartclip[jax]"      # JAX/Flax/Optax helpers

Quickstart

PyTorch

import torch
import smartclip as sc

model = MyModel().to("cpu")
opt = torch.optim.AdamW(model.parameters(), lr=3e-4)

with sc.clip_context(model, opt):  # Defaults to AutoClip
    for x, y in loader:
        opt.zero_grad(set_to_none=True)
        loss = model(x).loss_fn(y)
        loss.backward()
        opt.step()  # clipped automatically

TensorFlow/Keras

import tensorflow as tf
import smartclip as sc

model = MyModel()
opt = tf.keras.optimizers.Adam(3e-4)

with sc.clip_context(model, opt, clipper=sc.ZScoreClip(zmax=3.0)):  # Use the zscore algorithm
    model.fit(ds, epochs=5)

JAX/Optax

import jax
import optax
from flax import linen as nn
import smartclip as sc

model = MyModel()  # Flax Module
tx = optax.adam(3e-4)

with sc.clip_context(model, tx):  # wraps tx.update
    grads = jax.grad(loss_fn)(params, batch)
    updates, opt_state = tx.update(grads, opt_state, params)  # clipped automatically
    params = optax.apply_updates(params, updates)

See documentation for full guides for TensorFlow, JAX, Lightning, Keras, and HF Trainer.

Contributing

We welcome issues and pull requests. See contribute.md for developer setup, testing, docs, and release workflows.

License

MIT

Metadata

Release files for smartclip 0.1.1

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

Source distribution (sdist)

Source distribution for smartclip 0.1.1
File Size Uploaded
smartclip-0.1.1.tar.gz 32.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for smartclip 0.1.1
File Interpreter ABI Platform
smartclip-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 65.6 kB

Release files / smartclip-0.1.1.tar.gz

Download URL smartclip-0.1.1.tar.gz
Size 32.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c0dff18670d92a33b16b95b857a911f6addfcf0c24895279c537c5be969d0dfc
BLAKE2b-256 checksum
How to use checksums
43c637a8bc1c786fb3d16d9af1708e5ca4ac9fd8113c95c9a7f3ddbb97f636b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 13, 2025.

Transparency log

Release files / smartclip-0.1.1-py3-none-any.whl

Download URL smartclip-0.1.1-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3002e3b47c946cf6686a80096b455176fc30572fc48f595c05d3df5ac778d580
BLAKE2b-256 checksum
How to use checksums
b1e722adae999f4d443ab78f52185737251ad38a45d5c4bcb09818419ced31e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 13, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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