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.
v0.1 honest perf summary
| dataset | shape | sparho | LassoCV |
notes |
|---|---|---|---|---|
breast-cancer |
683×10 | 0.24 s | 0.01 s | overhead-bound; both finish instantly |
leukemia |
38×7129 | 23.1 s | 30.1 s | 1.3× faster; vector-α uniquely supported |
rcv1.binary |
20242×47236 sparse | 433 s, MSE 0.194 | 12 s, MSE 0.225 | better MSE, slower wall (see below) |
What v0.1 delivers:
- Correct gradient-based outer loop with full FD parity vs analytic hypergradients.
- Vector-α support (
WeightedL1, per-feature regularization) — somethingLassoCVcannot do. - Implicit-diff hypergradients via Rust kernels on the hot path; ridge- stabilized CG so the active-set-restricted linear solve does not diverge on ill-conditioned sparse designs.
- Clean Protocol-based API for sparse-ho refugees.
- 92 pytest, 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 better held-out MSE (0.194 vs 0.225). The wall-time
penalty (433 s vs 12 s) comes from the inner Lasso solver being cold-
started at every outer iter — see the v0.2 plan for warm-starting, which
the v0.1 spike (benchmarks/spike_warmstart.py) measured at ~2× on
dense cases.
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 ships sklearn + celer + callable adapters with
verified correctness and dense-high-d parity vs LassoCV. v0.2 closes the
two remaining perf gaps — inner-solver warm-starting and hypergradient
stability on large sparse designs — and adds a skein backend for
nonconvex weighted/group penalties.
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.1.0.tar.gz.
File metadata
- Download URL: sparho-0.1.0.tar.gz
- Upload date:
- Size: 31.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1bd9cc2d8d37ae76f8ab16af9025f9d695625027bc03f59970ccec25c6c7216
|
|
| MD5 |
5741b84fe79a8c679c66c112bf3dca8e
|
|
| BLAKE2b-256 |
b8fc7985554bbd72616a6800b89055c51e47c65359083d552e8dc8aec801ed01
|
Provenance
The following attestation bundles were made for sparho-0.1.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.1.0.tar.gz -
Subject digest:
c1bd9cc2d8d37ae76f8ab16af9025f9d695625027bc03f59970ccec25c6c7216 - Sigstore transparency entry: 1575464940
- Sigstore integration time:
-
Permalink:
dvillacis/sparho@bcbd3a00e7ffd13d177776cc0e4667f38edf8ca3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dvillacis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bcbd3a00e7ffd13d177776cc0e4667f38edf8ca3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sparho-0.1.0-cp311-abi3-win_amd64.whl.
File metadata
- Download URL: sparho-0.1.0-cp311-abi3-win_amd64.whl
- Upload date:
- Size: 162.7 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 |
0718ef35538c17976e0da9c495095565cefdd3550704f1806571ff4accb126dd
|
|
| MD5 |
c66560acd5ce6bde56e853cfc5892118
|
|
| BLAKE2b-256 |
c2ded10988c20442e6148f6ee5617e45fffb7ea0b2e69e123ba26ec84fd7ebc2
|
Provenance
The following attestation bundles were made for sparho-0.1.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.1.0-cp311-abi3-win_amd64.whl -
Subject digest:
0718ef35538c17976e0da9c495095565cefdd3550704f1806571ff4accb126dd - Sigstore transparency entry: 1575464981
- Sigstore integration time:
-
Permalink:
dvillacis/sparho@bcbd3a00e7ffd13d177776cc0e4667f38edf8ca3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dvillacis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bcbd3a00e7ffd13d177776cc0e4667f38edf8ca3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sparho-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: sparho-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 787.7 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 |
7dffee226714ecee04fb56ccf113d39ab4c6c02b0f192a0b5e3a019568ba6ac1
|
|
| MD5 |
f4bb9454c6c0f35587fce17bff7f45de
|
|
| BLAKE2b-256 |
8617be1da432f3d66831273957a7de9985b040c07ad7277e0bb1f943d487a168
|
Provenance
The following attestation bundles were made for sparho-0.1.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.1.0-cp311-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
7dffee226714ecee04fb56ccf113d39ab4c6c02b0f192a0b5e3a019568ba6ac1 - Sigstore transparency entry: 1575465000
- Sigstore integration time:
-
Permalink:
dvillacis/sparho@bcbd3a00e7ffd13d177776cc0e4667f38edf8ca3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dvillacis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bcbd3a00e7ffd13d177776cc0e4667f38edf8ca3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sparho-0.1.0-cp311-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: sparho-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 259.2 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 |
68524c49d67ae61c4f8c6e1e624674fc82b63dc644ce60f66a43b4fa2ca2ed96
|
|
| MD5 |
7c39d6e0987af5c98992a2cef1fa1034
|
|
| BLAKE2b-256 |
9df2aa0e1ac231786242f4705b71aa1c5ebd240c35456fc67a72917b45aff5dd
|
Provenance
The following attestation bundles were made for sparho-0.1.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.1.0-cp311-abi3-macosx_11_0_arm64.whl -
Subject digest:
68524c49d67ae61c4f8c6e1e624674fc82b63dc644ce60f66a43b4fa2ca2ed96 - Sigstore transparency entry: 1575465019
- Sigstore integration time:
-
Permalink:
dvillacis/sparho@bcbd3a00e7ffd13d177776cc0e4667f38edf8ca3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dvillacis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bcbd3a00e7ffd13d177776cc0e4667f38edf8ca3 -
Trigger Event:
push
-
Statement type: