Nonsmooth bilevel hyperparameter optimization via implicit differentiation
Project description
sparho
Nonsmooth bilevel hyperparameter optimization via implicit differentiation.
A maintained, performant successor to sparse-ho
(ICML 2020, dormant since 2022). Tunes hyperparameters of non-smooth estimators
(Lasso, ElasticNet, weighted Lasso, sparse logistic regression) by computing
the hypergradient via implicit differentiation rather than grid/random search.
Status: pre-alpha. Public API may change between minor versions until v1.0.
Why
Implicit-differentiation HP optimization can be orders of magnitude faster
than LassoCV-style grid search when you have a held-out criterion, but
the existing libraries are dormant (sparse-ho) or no longer maintained
(JAXopt). sparho is a clean-break, scipy-stack-native Rust+Python
implementation built for the same target audience.
Perf summary
v0.2 numbers (HOAG + warm-start + celer inner solver), single-threaded on
an Apple M-series; see benchmarks/README.md for the methodology and the
v0.1 historical row.
| dataset | shape | sparho | LassoCV |
notes |
|---|---|---|---|---|
breast-cancer |
683×10 | 0.26 s | 0.02 s | overhead-bound; both finish instantly |
leukemia |
38×7129 | 0.58 s | 19.0 s | 32.8× faster (was 1.3× at v0.1) |
rcv1.binary |
20242×47236 sparse | 211 s, MSE 0.194 | 22.6 s, MSE 0.225 | better MSE (see below); 2× wall faster than v0.1 |
What v0.2 delivers on top of v0.1:
hoag_searchouter loop (Pedregosa 2016): adaptive step from a Lipschitz proxy,+C·tolslack acceptance, exponentially-decreasing inner-tol schedule. ReplacesLineSearch.- Inner-solver warm-starting threaded through the
SolverProtocol + every adapter +CrossVal(warm_start=True). - celer adapter recommended for the high-d regime — compounding the
HOAG/warm-start win into 32.8× on
leukemiaand 1.65× faster than sklearn onrcv1.binary. - Dense-matvec fix in
implicit_forward(nocoo_tocsrround-trip on dense designs): 8.4× faster hypergradient solve onleukemia.
Everything v0.1 delivered still holds: gradient-based outer loop with
full FD parity, vector-α (WeightedL1) which LassoCV cannot do,
ridge-stabilized hypergradient-CG on ill-conditioned sparse designs,
clean Protocol-based API, mypy strict + clippy clean, single wheel via
maturin.
The rcv1 story. Implicit differentiation lets sparho search past
LassoCV's discrete grid: on rcv1.binary, sparho's outer loop drives
α down to 2.1·10⁻⁵, well below LassoCV's grid floor of 1·10⁻⁴,
and lands on a 14 % better held-out MSE (0.194 vs 0.225). The
wall-time gap halved at v0.2 (433 s → 211 s) thanks to warm-start +
celer; the remaining gap is irreducible inner-solver work at very small
α / large active set. sparho's win on this dataset is quality per
outer iter, not raw wall time.
Install (planned)
pip install sparho # release wheel, no Rust toolchain needed
pip install "sparho[celer]" # add celer as a fast Lasso adapter
Quickstart (planned API)
from sparho import Problem, grad_search
from sparho.adapters import SklearnLasso
from sparho.criteria import held_out_mse
from sparho.optimizer import grad_descent
from sparho.hypergrad import implicit_forward
problem = Problem.lasso(X, y)
result = grad_search(
problem,
hp0=1e-3,
solver=SklearnLasso(),
hypergrad=implicit_forward,
criterion=held_out_mse(idx_train, idx_val, X, y),
optimizer=grad_descent(lr=1.0),
)
print(result.best_hyperparam, result.best_coef)
See docs/migration_from_sparse_ho.md for translation from sparse-ho's API.
Design
- One
Problemdataclass. No abstract base class tower. Algorithms are free functions overProblem. Typing viatyping.Protocol. - Implicit-only at v0.1. ImplicitForward is the only hypergradient mode.
- Sparse-X first class. CSC iterated directly in Rust; no densification.
- Rust kernels via PyO3 + maturin + ABI3. Single binary wheel, no numba.
- Clean break from sparse-ho. Migration guide rather than compat shim.
Roadmap
See ROADMAP.md. v0.1 shipped sklearn + celer + callable adapters with
verified correctness and dense-high-d parity vs LassoCV. v0.2 closes
the inner-solver warm-starting and hypergradient-stability gaps and
lands the HOAG outer loop — 32.8× on leukemia, 2× wall on
rcv1.binary. v0.3 lands the sklearn-ecosystem wrappers (LassoHO,
ElasticNetHO, LogisticRegressionHO) so sparho slots into
Pipeline / EconML / MLflow, the SURE / GSURE criterion for
unsupervised tuning, a MultiTaskLasso / Group-L1 penalty, and adapters
for skein (nonconvex weighted/group) and skglm (MCP / SCAD / SLOPE /
Group / Huber / Poisson). See docs/feature_research.md for the
2026-05-20 landscape synthesis behind these picks.
License
BSD 3-Clause.
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 Distributions
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 sparho-0.2.0.tar.gz.
File metadata
- Download URL: sparho-0.2.0.tar.gz
- Upload date:
- Size: 31.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3539914586b9c188883e34f80e4f56fb239f1d951803a122ec78268130d8bee
|
|
| MD5 |
645c1d847dd097adf969ef648fab3a19
|
|
| BLAKE2b-256 |
6cca0b8eae33ab053f1dd096e5194ae7b64ce5f2e5ac04d7b2aa5fa52a984970
|
Provenance
The following attestation bundles were made for sparho-0.2.0.tar.gz:
Publisher:
release.yml on dvillacis/sparho
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sparho-0.2.0.tar.gz -
Subject digest:
f3539914586b9c188883e34f80e4f56fb239f1d951803a122ec78268130d8bee - Sigstore transparency entry: 1579667030
- Sigstore integration time:
-
Permalink:
dvillacis/sparho@8c40dfbf4706b2c670ec738479dc02a37f527c7d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dvillacis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c40dfbf4706b2c670ec738479dc02a37f527c7d -
Trigger Event:
push
-
Statement type:
File details
Details for the file sparho-0.2.0-cp311-abi3-win_amd64.whl.
File metadata
- Download URL: sparho-0.2.0-cp311-abi3-win_amd64.whl
- Upload date:
- Size: 163.2 kB
- Tags: CPython 3.11+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39f251aabcac49ec50e39df99099a640a6de631e9877948bfc173162aeb595a8
|
|
| MD5 |
17b3410e0b3f209409c5ad3f82d5dc96
|
|
| BLAKE2b-256 |
64bf9941f24e91d875f156122b65acba711efaf1eed74ad6ec655529c27f2702
|
Provenance
The following attestation bundles were made for sparho-0.2.0-cp311-abi3-win_amd64.whl:
Publisher:
release.yml on dvillacis/sparho
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sparho-0.2.0-cp311-abi3-win_amd64.whl -
Subject digest:
39f251aabcac49ec50e39df99099a640a6de631e9877948bfc173162aeb595a8 - Sigstore transparency entry: 1579667744
- Sigstore integration time:
-
Permalink:
dvillacis/sparho@8c40dfbf4706b2c670ec738479dc02a37f527c7d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dvillacis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c40dfbf4706b2c670ec738479dc02a37f527c7d -
Trigger Event:
push
-
Statement type:
File details
Details for the file sparho-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: sparho-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 788.3 kB
- Tags: CPython 3.11+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a884d20ad760407afbdbe5946f16e603d16fa0a625f2784e6dc269952507ba2e
|
|
| MD5 |
621d92e5e463cdd77a11a3cc4a0f722a
|
|
| BLAKE2b-256 |
c3f877dd73d8541895789ccbd0a385b41347365e3c16d2cc846de7bb95918080
|
Provenance
The following attestation bundles were made for sparho-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl:
Publisher:
release.yml on dvillacis/sparho
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sparho-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
a884d20ad760407afbdbe5946f16e603d16fa0a625f2784e6dc269952507ba2e - Sigstore transparency entry: 1579667521
- Sigstore integration time:
-
Permalink:
dvillacis/sparho@8c40dfbf4706b2c670ec738479dc02a37f527c7d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dvillacis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c40dfbf4706b2c670ec738479dc02a37f527c7d -
Trigger Event:
push
-
Statement type:
File details
Details for the file sparho-0.2.0-cp311-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: sparho-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 259.7 kB
- Tags: CPython 3.11+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6256d157a40a48dbcc76c45533130e2cdc53b0dea1d683efc98fcc8f24ca2e4
|
|
| MD5 |
5a66a76dfecbf90b35ba28df82ff1788
|
|
| BLAKE2b-256 |
d9b0a9aca240134b4ff6837a74b0c2424a9e7488ab54e70ffac34650a59ac0be
|
Provenance
The following attestation bundles were made for sparho-0.2.0-cp311-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on dvillacis/sparho
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sparho-0.2.0-cp311-abi3-macosx_11_0_arm64.whl -
Subject digest:
b6256d157a40a48dbcc76c45533130e2cdc53b0dea1d683efc98fcc8f24ca2e4 - Sigstore transparency entry: 1579667256
- Sigstore integration time:
-
Permalink:
dvillacis/sparho@8c40dfbf4706b2c670ec738479dc02a37f527c7d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dvillacis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c40dfbf4706b2c670ec738479dc02a37f527c7d -
Trigger Event:
push
-
Statement type: