Repository navigation
Releases
Releases · mlapin/libsdca
libsdca 0.3.0
Install from PyPI or crates.io:
pip install libsdca==0.3.0
cargo add libsdca@0.3.0The attached files are the published PyPI wheels and sdist and the crates.io crate.
Highlights
- Unified interfaces: Python package (
fit,loss_and_grad,coordinate_update),
scikit-learn estimator (SDCAClassifier), PyTorch modules and functions, JAX loss
functions, Rust crate, C ABI (include/sdca/c_api.h), C++11 headers, and MATLAB/Octave
gateways sharing one set of objective, option and status names (API.md). - Numerical stability: Losses and gradients preserve tiny probability tails down to the
subnormal limit (avoiding softmax collapse), and distillation gradients are exact zero at
equal logits (numerics,
known limits). - Fused CUDA and CPU kernels: On an A100 (
8192 × 32000and8192 × 128256),
cross-entropy takes0.93–0.98×torch.compiletime (0.33–0.41×eager), top-5
cross-entropy0.23–0.26×, and distillation0.62–0.81×(performance). - Certified convergence:
status == "solved"requires the duality gap of the returned
weights and the feasible projection of the returned duals, evaluated indoublewith a
first-order rounding estimate, to meet
tol(API.md).
Interfaces and losses
-
PyTorch (
libsdca,libsdca.torch):CrossEntropyLoss(drop-in for
torch.nn.CrossEntropyLoss, except integer class labels only and no label smoothing),TopKCrossEntropyLoss,MulticlassHingeLoss,
TopKHingeLoss($\alpha$ and$\beta$ ),MultilabelCrossEntropyLoss,
MultilabelHingeLoss,ProximalCrossEntropyLoss,DistillationLoss,
ProximalDistillationLoss,SDCALoss, andLinearCrossEntropyLoss(chunked linear head- cross-entropy without materializing
(N, V)logits) acrossfloat16,bfloat16,
float32andfloat64on CPU and CUDA, withtorch.compile(fullgraph=True)and
DTensorsupport (TORCH.md).
- cross-entropy without materializing
-
JAX (
libsdca.jax): Classification and distillation losses forjit,gradand
vmap, with zero-copy XLA FFI custom calls on CPU (JAX.md). -
Python & scikit-learn:
fit,loss_and_grad,distillation_loss_and_grad,
proximal_distillation_loss_and_grad,coordinate_update, andSDCAClassifier
(python/README.md). -
Rust, C, C++ and MATLAB: Rust crate
libsdca(rust/README.md),
versioned C ABIlibsdca::sdca_c(docs/C.md), CMake target
libsdca::libsdca(docs/CPP.md), and MEX gatewaysmatsdca_fit,
matsdca_lossandmatsdca_prox(docs/MATLAB.md).
Performance and solver improvements
-
CUDA kernels: Fused Triton kernels for all losses with C++
cuLaunchKernelautograd
dispatch, multi-row CTA tiling for short rows, streaming tiles up to$2^{25}$ classes, and
in-place backward gradient writes into unreferenced logits tensors. -
CPU kernels: JIT-compiled ATen/OpenMP C++ extension with C++ autograd nodes and SIMD
float32exponentials +float64row statistics for narrow cross-entropy and top-k
cross-entropy ($k \le 64$ ). -
Shrinking and screening (
shrinking="auto"): Combines LIBLINEAR-style active-set
shrinking with gap-safe screening for hinge fits, adapting the evaluation schedule to
shrunk epoch work (0.14–0.59×LinearSVCruntime; API.md). -
$O(n \log n)$ projections and Taylor root warm-starts: Top-k cone, simplex, knapsack
and top-k entropy projections run in$O(n \log n)$ , and proximal / entropy root solves
converge in1.0–1.3row evaluations on average.
Numerics and precision
- Single rounding: 16-bit gradients are scaled by the upstream cotangent and reduction
factor in working precision before a single rounding to the output dtype, and hinge / top-k
target gradients are formed from the unrounded competitor sum. - Double iterate for
float32fits (precision="float64"default): Keeps internal
solver weights and duals indouble(8(d + n)mbytes) and rounds once at each
evaluation sofloat32fits reachfloat64gap tolerances down tofloat32output
rounding (3.5e-7ondigits; passprecision="float32"for purefloat32speed and
memory; numerics.md). - Compensated reductions & hardened projections: Compensated sums in multilabel
cross-entropy and distillation, warm-start residual preservation at large score offsets,
and checkedfloat64/ extended-precisionmultilabel_hingeprojections
(API.md).
Packaging and build
- Portable
py3-nonewheels for Linuxx86_64(manylinux_2_28) and macOS 11+ (arm64)
with built-in BLAS; configurable BLAS (SDCA_BLAS_BACKEND=AUTO|EXTERNAL|BUILTIN);
CMake 3.12+ package config; and GitHub Actions CI on Linux and macOS.
Follow-up work
This pre-release contains the code used in the following technical report:
M. Lapin, M. Hein, and B. Schiele. Loss Functions for Top-k Error: Analysis and Insights. In arXiv:1512.00486, 2015.