Skip to main content

optimuon

A performance-optimized Muon optimizer for PyTorch.

Features:

  • Foreach-native: uses torch._foreach_* ops for momentum, weight decay, and parameter updates.
  • Batched Newton-Schulz: groups matrices by shape for parallel orthogonalization.
  • Auto-parameter routing: automatically partitions model parameters into Muon-eligible (≥2D hidden weights) and auxiliary (embeddings, heads, norms, biases).
  • Composite optimizer: CompositeMuon combines Muon with any arbitrary auxiliary optimizer (not just AdamW).
  • Three LR modes: Keller Jordan's "original" (with aspect-ratio scaling), Moonshot AI's "match_rms_adamw", and "none" (no scaling).
  • Momentum conventions: "ema" (m = beta*m + (1-beta)*g, default) and "classical" (m = beta*m + g).
  • Corrections: MARS, cautious updates, cautious weight decay, NorMuon, gradient/update clipping (all toggleable).
  • Weight normalization: optional Frobenius-norm clamping to sqrt(fan_out) (from KJ's original Muon).
  • Half-precision momentum: optional lower-precision momentum buffers for memory savings.
  • Polar Express: optimal per-step Newton-Schulz coefficients (default).
  • Distributed: torch.distributed gradient sharding via all_gather.

Installation

uv pip install git+https://github.com/emaballarin/optimuon

Quick start

Standalone Muon (manual parameter selection)

from optimuon import Muon

# Muon for ≥2D hidden weight matrices only
muon = Muon(muon_params, lr=0.02, momentum=0.95, weight_decay=0.01)

# Separate AdamW for everything else
import torch
adamw = torch.optim.AdamW(other_params, lr=3e-4)

# Training loop
for batch in dataloader:
    loss = model(batch).loss
    loss.backward()
    muon.step()
    adamw.step()
    muon.zero_grad()
    adamw.zero_grad()
from optimuon import CompositeMuon

optimizer = CompositeMuon(
    model,
    muon_lr=0.02,
    muon_kwargs={"weight_decay": 0.01, "foreach": True},
    aux_optimizer_class=torch.optim.AdamW,
    aux_optimizer_kwargs={"lr": 3e-4, "betas": (0.9, 0.95), "weight_decay": 0.01},
    verbose=True,
)

for batch in dataloader:
    loss = model(batch).loss
    loss.backward()
    optimizer.step()
    optimizer.zero_grad()

With corrections

from optimuon import CompositeMuon

optimizer = CompositeMuon(
    model,
    muon_lr=0.02,
    muon_kwargs={
        "weight_decay": 0.01,
        "mars": True,           # MARS gradient correction
        "cautious": True,       # cautious update masking
        "grad_clip": 1.0,       # gradient norm clipping
        "weight_norm": True,    # Frobenius-norm clamping
    },
    aux_optimizer_class=torch.optim.AdamW,
    aux_optimizer_kwargs={"lr": 3e-4},
)

With a custom auxiliary optimizer

from optimuon import CompositeMuon

optimizer = CompositeMuon(
    model,
    muon_lr=0.02,
    aux_optimizer_factory=lambda param_groups: SomeExoticOptimizer(param_groups, lr=1e-3),
)

Manual routing utilities

from optimuon import partition_params

result = partition_params(model)
print(f"Muon: {result.muon_names}")
print(f"Aux:  {result.aux_names}")

References

License

MIT

Metadata

Release files for optimuon 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 optimuon 0.1.1
File Size Uploaded
optimuon-0.1.1.tar.gz 18.8 kB Details

Built distribution (wheel)

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

Total release size: 40.0 kB

Release files / optimuon-0.1.1.tar.gz

Download URL optimuon-0.1.1.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
70501ad618fa27a0907d140c539d038ee26b34094e69d8061430d708eca1fb3f
BLAKE2b-256 checksum
How to use checksums
3e5aac275fff4b023924ecf6b5799b68064d08de730868d579b0b659cff6213d
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 Apr 1, 2026.

Transparency log

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

Download URL optimuon-0.1.1-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f574251affc7a44fa71b39e27d3466f5b1143c88e02fe05c398d5cc410727c14
BLAKE2b-256 checksum
How to use checksums
2c2228bc6b3d6400a7d4755e28d3706a93bef334fc594bd25942c1b33d2952f6
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 Apr 1, 2026.

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