libsdca for Python
Documentation · Shared reference
An accurate and fast implementation of classification losses: cross-entropy, multiclass and multilabel SVM hinges, top-k losses and knowledge distillation. The losses come as PyTorch and JAX loss layers and as NumPy functions. The package also has SDCA solvers for linear and kernel classifiers, with a scikit-learn estimator (project page, technical report).
Prebuilt wheels are available for Linux x86_64 and macOS arm64. The NumPy interface
needs no compiler. It requires NumPy and, on Linux, scipy-openblas32, which pip installs
as a dependency. PyTorch, scikit-learn and JAX are optional.
Installation
pip install libsdca # NumPy interface
pip install 'libsdca[sklearn]' # scikit-learn estimator SDCAClassifier
pip install 'libsdca[torch]' # PyTorch loss layers
pip install 'libsdca[jax]' # JAX CPU loss functions
pip install 'libsdca[jax-cuda]' # JAX CUDA losses (Linux, NVIDIA driver 580+)
| Task | Entry point | Described in |
|---|---|---|
| Train a scikit-learn classifier | libsdca.sklearn.SDCAClassifier |
Classifier |
| Train with full control (warm starts, label sets, target probabilities, history) | libsdca.fit, which returns a Model |
Training |
| Evaluate losses and gradients on NumPy arrays | libsdca.loss_and_grad |
Losses and gradients |
| Take a single SDCA step on the dual variables | libsdca.coordinate_update |
Losses and gradients |
| Use the losses as PyTorch layers | libsdca.torch.CrossEntropyLoss, TopKCrossEntropyLoss, ... |
PyTorch guide |
Use the losses in JAX with jit, grad and vmap |
libsdca.jax.cross_entropy, topk_hinge_loss, ... |
JAX guide |
Quick start
import numpy as np
import libsdca
X = np.array([[1., 0.], [0., 1.], [-1., -1.]])
y = np.array([0, 1, 2])
model = libsdca.fit(X, y)
print(model.status, model.predict(X))
Only model.status == "solved" guarantees the requested duality gap.
libsdca.torch.CrossEntropyLoss takes the arguments of torch.nn.CrossEntropyLoss, and the
package adds the other losses
(PyTorch guide):
import torch
from libsdca.torch import CrossEntropyLoss, TopKHingeLoss
logits = torch.randn(32, 5, requires_grad=True)
target = torch.randint(5, (32,))
(CrossEntropyLoss()(logits, target) + TopKHingeLoss(k=2)(logits, target)).backward()
NumPy and scikit-learn pages
| Page | Covers |
|---|---|
| Loss objects and targets | The loss objects, their parameters, and the target that each loss takes |
| scikit-learn classifier | SDCAClassifier: parameters, fitted attributes and methods |
Training with fit |
libsdca.fit: options, kernels, label sets, warm starts and the returned Model |
| Losses and gradients on arrays | loss_and_grad and coordinate_update, and the errors of the NumPy interface |
| Precision | Input dtypes and the precision option |
The index of all pages, including the PyTorch and JAX guides, is in the documentation.
Building from source
pip install . # links a system CBLAS if one is found, else the built-in products
SDCA_BLAS_BACKEND selects the BLAS of the build: AUTO, EXTERNAL or BUILTIN. The
commands are in
DEPENDENCIES.md.
A build that finds no BLAS uses the built-in products, and the first fit of a process
warns about it with a RuntimeWarning
(BLAS).
Metadata
Release files for libsdca 0.4.1
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 |
|---|---|---|---|---|
| libsdca-0.4.1.tar.gz | 1.0 MB | With provenance | Details for libsdca-0.4.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| libsdca-0.4.1-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details for libsdca-0.4.1-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
| libsdca-0.4.1-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for libsdca-0.4.1-py3-none-macosx_11_0_arm64.whl |
Total release size: 11.0 MB
Release files / libsdca-0.4.1.tar.gz
| Download URL | libsdca-0.4.1.tar.gz |
|---|---|
| Size | 1.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02933c1ededb84ee667cc5113aba30277856d4060f447297a3ec4ead0e5e949e
|
|
BLAKE2b-256 checksum How to use checksums |
c2ee324b6ed104399d0a409c3c5c8c7d02518066de22f148cc514d406bf167ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logRelease files / libsdca-0.4.1-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | libsdca-0.4.1-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
3afcb8d432f88fc6e97145e891ae311eacbbade400a0667edd63c4eb6109a05d
|
|
BLAKE2b-256 checksum How to use checksums |
7788ac2c6dde766e01898d6e515e9749ab7db545d7d2c303f0350aabacc3761a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logRelease files / libsdca-0.4.1-py3-none-macosx_11_0_arm64.whl
| Download URL | libsdca-0.4.1-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.8 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
bb40aebb6f4c14629db20aea8a4479ce913d949472e354310bb1ba24ab81227f
|
|
BLAKE2b-256 checksum How to use checksums |
3e9bbe355e9b2efe4834eb2646ae530c2c4bc28960dd8fbe66f16184014d1631
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 30, 2026.
Transparency logSecurity for libsdca 0.4.1
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 3 files in this release have been uploaded with provenance metadata.
Attestation for libsdca-0.4.1.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 Nov 30, 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.