Skip to main content

Tuning hyperparameters with JAX

Project description

Hyperoptax Logo

Hyperoptax: Parallel hyperparameter tuning with JAX

PyPI version CI status codecov

⛰️ Introduction

Hyperoptax is a lightweight toolbox for parallel hyperparameter optimization of pure JAX functions. It provides a concise API that lets you wrap any JAX-compatible loss or evaluation function and search across spaces in parallel – all while staying in pure JAX.

🏗️ Installation

pip install hyperoptax

If you want to use the notebooks:

pip install hyperoptax[notebooks]

If you do not yet have JAX installed, pick the right wheel for your accelerator:

# CPU-only
pip install --upgrade "jax[cpu]"
# or GPU/TPU – see the official JAX installation guide

🥜 In a nutshell

Hyperoptax offers a simple API to wrap pure JAX functions for hyperparameter search and making use of parallelization (vmap only currently). See the notebooks for more examples.

from hyperoptax.bayesian import BayesianOptimizer
from hyperoptax.spaces import LogSpace, LinearSpace

@jax.jit
def train_nn(learning_rate, final_lr_pct):
    ...
    return val_loss

search_space = {"learning_rate": LogSpace(1e-5,1e-1, 100),
                "final_lr_pct": LinearSpace(0.01, 0.5, 100)}

search = BayesianOptimizer(search_space, train_nn)
best_params = search.optimize(n_iterations=100, 
                              n_parallel=10, 
                              maximize=False,
                              )

🔪 The Sharp Bits

Since we are working in pure JAX the same sharp bits apply. Some consequences of this for hyperoptax:

  1. Parameters that change the length of an evaluation (e.g: epochs, generations...) can't be optimized in parallel.
  2. Neural network structures can't be optimized in parallel either.
  3. Strings can't be used as hyperparameters.

🫂 Contributing

We welcome pull requests! To get started:

  1. Open an issue describing the bug or feature.
  2. Fork the repository and create a feature branch (git checkout -b my-feature).
  3. Install dependencies:
pip install -e ".[all]"
  1. Run the test suite:
python -m unittest discover -s tests
  1. Ensure the notebooks still work.
  2. Format your code with ruff.
  3. Submit a pull request.

Roadmap

I'm developing this both as a passion project and for my work in my PhD. I have a few ideas on where to go with this libary:

  • Sample hyperparameter configurations on the fly rather than generate a huge grid at initialisation.
  • Switch domain type from a list of arrays to a PyTree.
  • Callbacks!
  • Inspired by wandb's sweeps, use a linear grid for all parameters and apply transformations at sample time.
  • We are currently redoing the kernel calculation at each iteration when only the last row/column is actually needed. JAX requires sizes to be constant, so we need to do something clever...
  • Documentation!
  • Need to find a way to share the GP across workers on pmap for Bayesian.
  • length scale tuning of kernel tuned during optimization (as done in other implementations).

📝 Citation

If you use Hyperoptax in academic work, please cite:

@misc{hyperoptax2025,
  author = {Theo Wolf},
  title = {{Hyperoptax}: Parallel hyperparameter tuning with JAX},
  year = {2025},
  url = {https://github.com/TheodoreWolf/hyperoptax}
}

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

hyperoptax-0.1.6.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

hyperoptax-0.1.6-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file hyperoptax-0.1.6.tar.gz.

File metadata

  • Download URL: hyperoptax-0.1.6.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hyperoptax-0.1.6.tar.gz
Algorithm Hash digest
SHA256 cf588e86c6a5b7ef1cac36bf63b62b418ce451d71477b26a72dc585ab03262cc
MD5 67ec26c383b2ef66eb55c2c2f883e0fb
BLAKE2b-256 3275ca14fffcf46d59c3c3790fc232df5a597034d7fecd9c4d03f5bd54205831

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperoptax-0.1.6.tar.gz:

Publisher: python-publish.yml on TheodoreWolf/hyperoptax

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

File details

Details for the file hyperoptax-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: hyperoptax-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hyperoptax-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6ecb0d4350a15acb342d154d7bb412570e3de8a1cf65f8a243a82bd60cb3ef30
MD5 0ebee709dc136fabadd22d31fefa7166
BLAKE2b-256 e6b0e5771445f24810ca25aa2bcf8c8ff4e7a2f29fd51d6bf74f793e6744e12c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyperoptax-0.1.6-py3-none-any.whl:

Publisher: python-publish.yml on TheodoreWolf/hyperoptax

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