Skip to main content

gradhpo — gradient-based hyperparameter optimization in JAX

Test status PEP-8 (flake8) Docs status PyPI version License

gradhpo is a JAX library for short-horizon gradient-based hyperparameter optimization via bilevel optimization. It packages five algorithms behind a single BilevelOptimizer interface:

  • HyperDistill — online HPO with EMA hypergradient distillation (Lee et al., ICLR 2022).

  • T1-T2 with DARTS — T1-T2 with finite-difference (DARTS) approximation of the second-order term (Luketina et al., 2016; Liu et al., 2018).

  • Greedy — generalized greedy gradient-based HPO with inner-loop unrolling.

  • FO — first-order baseline that uses only the direct gradient dL_val/dλ.

  • One-Step — one-step lookahead baseline (HyperDistill with γ=0).

All step() methods are JIT-compiled and accept arbitrary JAX pytrees for both parameters and hyperparameters, so the same code works for a single learning rate, a per-parameter LR vector, or any other structured hyperparameter.

Installation

pip install gradhpo

Requires Python ≥ 3.9. JAX, optax, scikit-learn and the rest of the runtime dependencies are pulled in automatically.

Source install:

git clone https://github.com/intsystems/gradhpo.git
pip install ./gradhpo/src

Editable / dev install (recommended for contributors):

git clone https://github.com/intsystems/gradhpo.git
cd gradhpo
pip install -e ./src
pip install pytest pytest-cov flake8

Quick start

import jax
import jax.numpy as jnp
from gradhpo import OnlineHypergradientOptimizer

def loss_fn(params, hyperparams, batch):
    x, y = batch
    pred = x @ params['w']
    mse = jnp.mean((pred - y) ** 2)
    reg = jax.nn.softplus(hyperparams['log_lam']) * jnp.sum(params['w'] ** 2)
    return mse + reg

def update_fn(w, lam, batch):
    g = jax.grad(loss_fn)(w, lam, batch)
    return jax.tree.map(lambda p, gp: p - 0.01 * gp, w, g)

opt = OnlineHypergradientOptimizer(
    update_fn=update_fn, gamma=0.99, estimation_period=10, T=20,
)
state = opt.init({'w': jnp.zeros(10)}, {'log_lam': jnp.array(0.0)})

state = opt.run(
    state, M=30,
    get_train_batch=get_train, get_val_batch=get_val,
    train_loss_fn=loss_fn, val_loss_fn=loss_fn,
    lr_hyper=1e-3,
)

The same interface works for T1T2Optimizer, GreedyOptimizer, FOOptimizer and OneStepOptimizer. See the documentation for a side-by-side comparison and a full notebook.

Documentation

  • Full docs: https://intsystems.github.io/gradhpo/

  • API reference: BilevelOptimizer, BilevelState, all algorithms, pytree/VJP utilities.

  • Tutorial with a 2-layer MLP and a per-parameter learning rate vector.

Project information

Citation

If you use gradhpo in academic work, please cite:

Eynullayev, A., Rubtsov, D., & Karpeev, G. (2026).
gradhpo: Gradient-Based Hyperparameter Optimization.
MIPT Intelligent Systems.

Metadata

Release files for gradhpo 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gradhpo 0.1.3
File Size Uploaded
gradhpo-0.1.3.tar.gz 17.6 kB Details

Built distribution (wheel)

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

Total release size: 39.6 kB

Release files / gradhpo-0.1.3.tar.gz

Download URL gradhpo-0.1.3.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4023ee8a315969f5fc314ca5e6511ccc0e2db4692f637e5f914440f46d35cbf6
BLAKE2b-256 checksum
How to use checksums
2ca2150f6be8273550158e2ce23a0c1a5e66a91c4da79c548be71eb7f7351cef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 14, 2026.

Transparency log

Release files / gradhpo-0.1.3-py3-none-any.whl

Download URL gradhpo-0.1.3-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c97ddecc5c043d83d550d8c857c78a127277011b0912e0ee1130dea1feed96ce
BLAKE2b-256 checksum
How to use checksums
b11a6695ab7fb5dfb3e9ccce854417f0b92e261bac859f547fd74d99f6f7a04b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

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