Skip to content

libsdca 0.4.1

Latest

Choose a tag to compare

@mlapin mlapin released this 30 Nov 21:35
8d7c9dd

Install from PyPI or crates.io:

pip install libsdca==0.4.1
cargo add libsdca@0.4.1

The 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,
    LogSoftmax and Softmax, and libsdca.jax.log_softmax and softmax. They take the
    arguments of the functions in torch.nn.functional and jax.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_gradient takes 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_loss tests 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.compile on 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 bfloat16 student logits
    that are a slice or a padded view of a larger tensor.

Fixes

  • torch.compile with dynamic shapes: every PyTorch loss now compiles under
    torch.compile(..., fullgraph=True) with dynamic=True, and after a recompilation for a
    new batch size or sequence length. In 0.4.0 this raised Dynamo's Unsupported error, or
    fell back to eager code without fullgraph.
  • torch.compile on 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 as CrossEntropyLoss()
    no longer prints a Dynamo warning about functools.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, a functools.partial, a
    compiled function) raises a TypeError that shows the expected call.
  • No Triton warning on the first CUDA call: with Triton 3.9, the first CUDA call warned
    that TRITON_DEFAULT_FP_FUSION was 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.