Repository navigation
Install from PyPI or crates.io:
pip install libsdca==0.4.1
cargo add libsdca@0.4.1The attached files are the published PyPI wheels and sdist and the crates.io crate.
Changes since 0.4.0. The technical report
gives the benchmarks and numerical comparisons.
Added
- Log-softmax and softmax drop-ins:
libsdca.torch.log_softmax,softmax,
LogSoftmaxandSoftmax, andlibsdca.jax.log_softmaxandsoftmax. They take the
arguments of the functions intorch.nn.functionalandjax.nn. For a confident
prediction they keep the log-probability of the leading class and the gradient, where
the frameworks' functions round both to zero
(PyTorch, JAX). - Gradient checks in PyTorch:
libsdca.torch.check_cross_entropy_gradienttakes the
logits and labels of a batch of your run and compares the gradient of your cross-entropy
with an accurate reference. It reports the entries that were rounded to zero or have the
wrong sign.check_losstests any loss function for the properties that the gradient of
a cross-entropy or distillation loss must have
(gradient checks).
Performance
- Less memory in compiled training: under
torch.compile(PyTorch 2.6 or later), the
backward pass of a loss on CUDA, and of 16-bit logits on the CPU, writes the gradient
into the memory of the logits when nothing else reads them, as eager code already did. A
compiled training step then holds one buffer of the size of the logits less
(memory). - Less overhead per call under
torch.compileon CUDA: a loss call with static shapes
is traced as a single call, which shortens small calls. - Faster distillation on CUDA with few classes, and with
bfloat16student logits
that are a slice or a padded view of a larger tensor.
Fixes
torch.compilewith dynamic shapes: every PyTorch loss now compiles under
torch.compile(..., fullgraph=True)withdynamic=True, and after a recompilation for a
new batch size or sequence length. In 0.4.0 this raised Dynamo'sUnsupportederror, or
fell back to eager code withoutfullgraph.torch.compileon PyTorch 2.5: compiling a loss raised an internal Dynamo error. It
now compiles. Dynamic shapes need PyTorch 2.6 or later.- Loss modules under
torch.compile: compiling a module such asCrossEntropyLoss()
no longer prints a Dynamo warning aboutfunctools.lru_cache. The results were not
affected. - First-use builds report their progress: compiling the CPU kernels can take several
minutes. The log now says so, and a process that waits for the build of another process
says that it waits (build tools). explain_backend: passing a wrapper of a loss (a lambda, afunctools.partial, a
compiled function) raises aTypeErrorthat shows the expected call.- No Triton warning on the first CUDA call: with Triton 3.9, the first CUDA call warned
thatTRITON_DEFAULT_FP_FUSIONwas unset, and the results depended on that variable.
The kernels now set it themselves, so the results and the speed match 0.4.0.
Documentation
- The documentation is now a set of short pages, one topic each, with an index in
docs/. The PyTorch and JAX guides list every function with its
parameters.