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.
Metadata
Release files for sparho 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sparho-0.2.0.tar.gz | 31.7 kB | With provenance | Details for sparho-0.2.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sparho-0.2.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for sparho-0.2.0-cp311-abi3-win_amd64.whl |
| sparho-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details for sparho-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl |
| sparho-0.2.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for sparho-0.2.0-cp311-abi3-macosx_11_0_arm64.whl |
Total release size: 1.2 MB
Release files / sparho-0.2.0.tar.gz
| Download URL | sparho-0.2.0.tar.gz |
|---|---|
| Size | 31.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f3539914586b9c188883e34f80e4f56fb239f1d951803a122ec78268130d8bee
|
|
BLAKE2b-256 checksum How to use checksums |
6cca0b8eae33ab053f1dd096e5194ae7b64ce5f2e5ac04d7b2aa5fa52a984970
|
| 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 20, 2026.
Transparency logRelease files / sparho-0.2.0-cp311-abi3-win_amd64.whl
| Download URL | sparho-0.2.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 163.2 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
39f251aabcac49ec50e39df99099a640a6de631e9877948bfc173162aeb595a8
|
|
BLAKE2b-256 checksum How to use checksums |
64bf9941f24e91d875f156122b65acba711efaf1eed74ad6ec655529c27f2702
|
| 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 20, 2026.
Transparency logRelease files / sparho-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | sparho-0.2.0-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 788.3 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a884d20ad760407afbdbe5946f16e603d16fa0a625f2784e6dc269952507ba2e
|
|
BLAKE2b-256 checksum How to use checksums |
c3f877dd73d8541895789ccbd0a385b41347365e3c16d2cc846de7bb95918080
|
| 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 20, 2026.
Transparency logRelease files / sparho-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | sparho-0.2.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 259.7 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b6256d157a40a48dbcc76c45533130e2cdc53b0dea1d683efc98fcc8f24ca2e4
|
|
BLAKE2b-256 checksum How to use checksums |
d9b0a9aca240134b4ff6837a74b0c2424a9e7488ab54e70ffac34650a59ac0be
|
| 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 20, 2026.
Transparency logSecurity for sparho 0.2.0
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.
Full provenance
All 4 files in this release have been uploaded with provenance metadata.
Attestation for sparho-0.2.0.tar.gz
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 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.