Skip to main content

Keras OptiRoulette meta-optimizer (PyTorch backend only)

Project description

OptiRoulette-Keras (Torch Backend)

This package accompanies the paper "OptiRoulette Optimizer: A New Stochastic Meta-Optimizer for up to 5.3x Faster Convergence".

A standalone, pip-installable Keras meta-optimizer that brings OptiRoulette's training logic to Keras compile/fit flows:

  • 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.

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.

Important: the metrics above are from the current OptiRoulette paper draft (PyTorch experiment suite), not from a full Keras multi-seed validation.

Status

OptiRoulette-Keras is currently an experimental / pre-release package. It has not yet been validated through full scientific multi-seed experiment suites.

Backend Requirement

You must use Keras with the torch backend:

export KERAS_BACKEND=torch

Set this before importing keras.

Install

pip install OptiRoulette-Keras

Examples

Quick Use (compile/fit)

import os
os.environ["KERAS_BACKEND"] = "torch"

import keras
from optiroulette_keras import create_roulette_callback

model = keras.Sequential([
    keras.layers.Input(shape=(32, 32, 3)),
    keras.layers.Conv2D(32, 3, activation="relu"),
    keras.layers.GlobalAveragePooling2D(),
    keras.layers.Dense(100),
])

# If you do not pass arguments, bundled optimized.yaml defaults are used
# (optimizers, roulette, pool, LR rules, seed fallback).
# Advanced optimizers (e.g. ranger, adan) are resolved via pytorch-optimizer adapter.
controller, roulette_cb = create_roulette_callback()
# Note: this call is still required. Without it, there is no OptiRoulette switching.
# verbose levels:
# 0 -> no OptiRoulette output (default)
# 1 -> print only active optimizer
# 2 -> include all OptiRoulette metrics in fit/progbar logs

model.compile(
    optimizer=controller.active_optimizer,
    loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
    metrics=["accuracy"],
)
model.fit(train_loader, validation_data=val_loader, epochs=10, callbacks=[roulette_cb])

Custom arguments example:

controller, roulette_cb = create_roulette_callback(
    optimizer_specs={
        "adam": {"learning_rate": 1e-3},
        "adamw": {"learning_rate": 1e-3, "weight_decay": 0.01},
        "sgd": {"learning_rate": 5e-2, "momentum": 0.9, "nesterov": True},
    },
    roulette={"warmup_epochs": 0, "warmup_optimizer": None, "warmup_config": {}},
    switch_granularity="epoch",
)

If you do not pass these arguments, defaults from bundled optimized.yaml are used.

API

from optiroulette_keras import (
    OptiRoulette,
    OptiRouletteOptimizer,
    OptiRouletteCallback,
    create_roulette_callback,
    PoolConfig,
    ensure_torch_backend,
    get_default_config,
    get_default_seed,
    get_default_optimizer_specs,
    get_default_pool_setup,
    get_default_roulette_config,
)

Package Layout

This folder is a standalone PyPI package inside the same repository:

  • packages/optiroulette-keras/pyproject.toml
  • packages/optiroulette-keras/src/optiroulette_keras/*
  • packages/optiroulette-keras/tests/*

Build

From this folder:

python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*

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_keras-0.1.2.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

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

optiroulette_keras-0.1.2-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file optiroulette_keras-0.1.2.tar.gz.

File metadata

  • Download URL: optiroulette_keras-0.1.2.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for optiroulette_keras-0.1.2.tar.gz
Algorithm Hash digest
SHA256 305dc2828d9a48ef5eb37cac58d2761f2eebae698d020e3eb063807a2e0a52b7
MD5 9e92a30da92c00d1a8a4f0631c55ab7c
BLAKE2b-256 fbaf38bd1ab3c20f6f26b4d4d7a45d47c46679956ee148bf670673bf731de292

See more details on using hashes here.

Provenance

The following attestation bundles were made for optiroulette_keras-0.1.2.tar.gz:

Publisher: publish-pypi-keras.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_keras-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for optiroulette_keras-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dd09b7af1a0366697df8a03826aa178946fb6d5b0ca8b1b8c9ab46dc8ee99ac1
MD5 cca0bf609e242be9b13f80a3415ae81a
BLAKE2b-256 3a480a8a846d3e263902b9cdcd7853eea34863a5fea762f2c91dab1c0cdb55d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for optiroulette_keras-0.1.2-py3-none-any.whl:

Publisher: publish-pypi-keras.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