Skip to main content

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, fallback 42)

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


Download files

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

Source Distribution

optiroulette-0.1.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

optiroulette-0.1.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

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

Hashes for optiroulette-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d4097282940558493c4c93d9113264171611e23ce7bb963f9519f2566ea0f350
MD5 c0ebd30d5cae53b96bb19956253d51e4
BLAKE2b-256 e6b4ac77c23c50249440cec27660538aea5da36bd794776f69fb3acfa38ded8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for optiroulette-0.1.0.tar.gz:

Publisher: publish-pypi.yml on MStamatis/OptiRoulette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for optiroulette-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 463dc646ca63e73e3efc5fa9882508c3287c37dabb623cab1ed047a212d6f9f5
MD5 a6c250a642ae0d3778a4d385656b39b7
BLAKE2b-256 5dd18b6f8624a38107c2d1c75e2c1e82ba98ebb638814ba580ff9f3d42815542

See more details on using hashes here.

Provenance

The following attestation bundles were made for optiroulette-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on MStamatis/OptiRoulette

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page