PyTorch optimizer with random switching, LR scaling and pool swaps
Project description
OptiRoulette Optimizer
This repository accompanies the paper "OptiRoulette Optimizer: A New Stochastic Meta-Optimizer for up to 5.3x Faster Convergence".
A standalone, pip-installable PyTorch meta-optimizer that brings OptiRoulette's training logic to any project:
- random optimizer switching
- warmup -> roulette phase handling
- optimizer pool with active/backup swapping
- compatibility-aware replacement
- learning-rate scaling rules when switching
- momentum/state transfer on swap
The default behavior is loaded from the bundled optimized.yaml profile (same optimizer pool logic used in this project).
Research Highlights
Based on the current paper draft, OptiRoulette is a stochastic meta-optimizer that combines:
- warmup optimizer locking
- randomized sampling from an active optimizer pool
- compatibility-aware LR scaling during optimizer transitions
- failure-aware pool replacement
Reported mean test accuracy vs a single-optimizer AdamW baseline:
| Dataset | AdamW | OptiRoulette | Delta |
|---|---|---|---|
| CIFAR-100 | 0.6734 | 0.7656 | +9.22 pp |
| CIFAR-100-C | 0.2904 | 0.3355 | +4.52 pp |
| SVHN | 0.9667 | 0.9756 | +0.89 pp |
| Tiny ImageNet | 0.5669 | 0.6642 | +9.73 pp |
| Caltech-256 | 0.5946 | 0.6920 | +9.74 pp |
Additional paper-reported highlights:
- Target-hit reliability: in the reported 10-seed suites, OptiRoulette reaches key validation targets in 10/10 runs, while the AdamW baseline reaches none of those targets within budget.
- Faster time-to-target on shared milestones (example: Caltech-256 @ 0.59, 25.7 vs 77.0 epochs), with budget-capped lower-bound speedups up to 5.3x for non-attained baseline targets.
- Paired-seed analysis is positive across datasets, except CIFAR-100-C test ROC-AUC, which is not statistically significant in the current 10-seed study.
Install
pip install OptiRoulette
Examples
Quick Use
import torch
from optiroulette import OptiRoulette
model = torch.nn.Linear(128, 10)
optimizer = OptiRoulette(model.parameters())
for epoch in range(5):
optimizer.on_epoch_start(epoch)
for batch_idx in range(100):
optimizer.on_batch_start(batch_idx)
optimizer.zero_grad()
x = torch.randn(32, 128)
y = torch.randint(0, 10, (32,))
loss = torch.nn.functional.cross_entropy(model(x), y)
loss.backward()
optimizer.step()
# pass validation accuracy for warmup plateau logic (optional)
optimizer.on_epoch_end(val_acc=0.6)
API
from optiroulette import (
OptiRoulette,
OptiRouletteOptimizer,
PoolConfig,
get_default_config,
get_default_seed,
get_default_optimizer_specs,
get_default_pool_setup,
get_default_roulette_config,
)
Configuration Reference
For a full settings guide (constructor arguments, optimizer_specs,
pool_config, warmup/roulette options, and defaults precedence), see:
docs/configuration.md
For package maintainers (release/publish steps), see:
docs/release.md
Defaults behavior
OptiRoulette(model.parameters()) uses:
- default optimizer specs from bundled
optimized.yaml - default roulette settings from bundled
optimized.yaml - default pool config + active/backup names from bundled
optimized.yaml - default LR scaling rules from bundled
optimized.yaml - default optimizer RNG seed from bundled
optimized.yaml(system.seed, fallback42)
If you provide manual optimizer/pool settings, those are used instead of defaults:
optimizer = OptiRoulette(
model.parameters(),
optimizer_specs={"adam": {"lr": 1e-3}},
)
Manual custom pool example (only your chosen optimizers are used):
optimizer = OptiRoulette(
model.parameters(),
optimizer_specs={
"adam": {"lr": 1e-3},
"adamw": {"lr": 8e-4, "weight_decay": 0.01},
"lion": {"lr": 1e-4, "betas": (0.9, 0.99)},
},
active_names=["adam", "adamw"],
backup_names=["lion"],
)
Optional: override pool behavior too:
optimizer = OptiRoulette(
model.parameters(),
optimizer_specs={
"adam": {"lr": 1e-3},
"adamw": {"lr": 8e-4, "weight_decay": 0.01},
"lion": {"lr": 1e-4, "betas": (0.9, 0.99)},
},
pool_config={
"num_active": 2,
"num_backup": 1,
"failure_threshold": -0.2,
"consecutive_failure_limit": 3,
},
active_names=["adam", "adamw"],
backup_names=["lion"],
)
Third-Party Dependencies
This package depends on pytorch-optimizer for additional optimizer implementations.
See THIRD_PARTY_LICENSES.md for a short third-party license notice.
Disclaimer
The OptiRoulette name refers exclusively to a machine-learning optimizer and has no affiliation, sponsorship, or technical relation to roulette manufacturers, casinos, or any physical/software gambling products or services.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optiroulette-0.1.0.tar.gz.
File metadata
- Download URL: optiroulette-0.1.0.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4097282940558493c4c93d9113264171611e23ce7bb963f9519f2566ea0f350
|
|
| MD5 |
c0ebd30d5cae53b96bb19956253d51e4
|
|
| BLAKE2b-256 |
e6b4ac77c23c50249440cec27660538aea5da36bd794776f69fb3acfa38ded8e
|
Provenance
The following attestation bundles were made for optiroulette-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on MStamatis/OptiRoulette
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optiroulette-0.1.0.tar.gz -
Subject digest:
d4097282940558493c4c93d9113264171611e23ce7bb963f9519f2566ea0f350 - Sigstore transparency entry: 972542512
- Sigstore integration time:
-
Permalink:
MStamatis/OptiRoulette@914f2da14e3d58aad4d32822b4b8e71cbaae8479 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MStamatis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@914f2da14e3d58aad4d32822b4b8e71cbaae8479 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file optiroulette-0.1.0-py3-none-any.whl.
File metadata
- Download URL: optiroulette-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
463dc646ca63e73e3efc5fa9882508c3287c37dabb623cab1ed047a212d6f9f5
|
|
| MD5 |
a6c250a642ae0d3778a4d385656b39b7
|
|
| BLAKE2b-256 |
5dd18b6f8624a38107c2d1c75e2c1e82ba98ebb638814ba580ff9f3d42815542
|
Provenance
The following attestation bundles were made for optiroulette-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on MStamatis/OptiRoulette
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optiroulette-0.1.0-py3-none-any.whl -
Subject digest:
463dc646ca63e73e3efc5fa9882508c3287c37dabb623cab1ed047a212d6f9f5 - Sigstore transparency entry: 972542516
- Sigstore integration time:
-
Permalink:
MStamatis/OptiRoulette@914f2da14e3d58aad4d32822b4b8e71cbaae8479 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MStamatis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@914f2da14e3d58aad4d32822b4b8e71cbaae8479 -
Trigger Event:
workflow_dispatch
-
Statement type: