rnnt-loss

The RNN-Transducer forward-backward on the GPU, loadable through kernels. The reference baselines are torchaudio.functional.rnnt_loss (the warp-transducer lineage), an independently written fp64 lattice, and torch autograd through a pure-torch logsumexp lattice. Companion to dpx-decode, the max-plus side of the same lattice family.

Training an RNN-T, the architecture behind most streaming speech recognizers, needs the log-sum over every monotone alignment of U labels to T frames and its gradient: a forward-backward pass over a [T, U+1] lattice whose rows and columns are both sequential. This kernel parallelizes the one direction that is free, the anti-diagonal, and runs the whole lattice as one block per utterance, beating the torchaudio implementation by 1.4x to 1.9x with the margin growing on the long utterances speech training is made of.

Alpha sweeps the lattice in anti-diagonal wavefronts, beta flows back, and their sum ignites the alignment ridge

The real lattice of a 100-frame, 40-label utterance: alpha filling one anti-diagonal per step, beta swept in reverse, and alpha + beta, the posterior over alignments that the gradient is made of, blazing along the alignment ridge. The loss matches an independent fp64 lattice to 1e-4 with forward+backward in 0.28 ms.

Usage

import torch
from kernels import get_kernel

rnnt = get_kernel("phanerozoic/rnnt-loss", version=1, trust_remote_code=True)

# joint is [B, T, U+1, V] from the joint network
loss = rnnt.rnnt_loss_from_logits(joint, labels, input_lengths, label_lengths,
                                  blank=0, reduction="mean")
loss.backward()

# or pass log-probabilities directly, keeping the log_softmax where you want it
loss = rnnt.rnnt_loss(torch.log_softmax(joint, -1), labels,
                      input_lengths, label_lengths, blank=0)

version selects the release branch; trust_remote_code is required by kernels for publishers without the trusted-publisher mark.

API

Symbol Purpose
rnnt_loss(log_probs, labels, input_lengths, label_lengths, blank, reduction) transducer loss from log-normalized joint output
rnnt_loss_from_logits(logits, ...) wrapper that applies log_softmax first
RNNTLoss(blank, reduction) nn.Module form, stateless
ops.rnnt_forward(...) (loss [B], alpha, beta), the state reused by backward
ops.rnnt_backward(...) gradient with respect to log_probs

log_probs is [B, T, U+1, V] fp32, normalized over V; labels is [B, U] int64; lengths are [B].

Method

alpha[t, u] depends on alpha[t-1, u] and alpha[t, u-1], so rows and columns are both sequential; the anti-diagonal is not: every cell on t + u = k depends only on cells with t + u = k-1. One block per utterance sweeps T + U diagonals with a barrier between them, and beta sweeps the same diagonals in reverse. With both variables in hand the gradient is pointwise: only two entries per lattice cell are nonzero (the blank and the emitted label), so the gradient kernel writes 2 * T * (U+1) values and is embarrassingly parallel. Inputs are log-probabilities so the joint's log_softmax stays in autograd where it fuses with the rest of the joint.

Measured

fp32, full forward and backward through logits, against torchaudio.functional.rnnt_loss on the same host:

B T U V torchaudio this speedup
8 100 20 128 0.406 ms 0.259 ms 1.57x
16 200 40 256 3.388 ms 2.345 ms 1.44x
32 300 50 512 24.069 ms 14.943 ms 1.61x
16 500 80 256 19.856 ms 10.470 ms 1.90x

Work per barrier is min(T, U+1) cells, so long-utterance shapes keep more of the block busy per synchronization; the advantage grows with T.

Correctness

  • torchaudio: loss agrees to 4.5e-7 relative worst case across batch 2 to 16, T to 200, U to 40, V to 128, padded and ragged lengths; gradients through log_softmax to 1.3e-5 relative.
  • An fp64 lattice: the forward recurrence agrees with a scalar float64 Python lattice, written independently, to 6.6e-6 absolute.
  • Autograd: gradients agree to 1.2e-6 relative against autograd through a pure-torch logsumexp lattice.
  • Gradient structure: summed over the vocabulary the gradient vanishes at every reachable cell to 1e-3, the posterior-mass identity.
  • A single frame with an empty transcript returns exactly -log p(blank); repeated forward passes are bitwise identical.

Requirements and limits

  • NVIDIA GPU with compute capability 8.0+.
  • fp32 lattice arithmetic; no bf16 path, since the accumulation would lose the small-probability tail the loss is made of.
  • alpha and beta are each [B, T, U+1] fp32, held between forward and backward; the [B, T, U+1, V] joint output dominates memory regardless.
  • One block per utterance: batch size is what fills the device.

References

Graves, "Sequence Transduction with Recurrent Neural Networks" (2012); the warp-transducer reference implementation and its torchaudio descendant.

License

Apache-2.0.

Downloads last month
-
apache-2.0
Supported hardwares new
CUDA
8.08.68.99.010.012.0
GPU
B300
288GB
NVIDIA SXM
B200
192GB
NVIDIA SXM
H200
141GB
NVIDIA SXM
H100
80GB
GPU
H800
80GB
GPU
H20
96GB
GPU
L40s
48GB
GPU
L40
48GB
GPU
L20
48GB
GPU
L4
24GB
DGX Spark
GB10
128GB
GPU
RTX PRO 6000 WS
96GB
GPU
RTX PRO 6000 Max-Q
96GB
GPU
RTX PRO 5000
48GB
GPU
RTX PRO 4500 WS
32GB
GPU
RTX PRO 4000
24GB
GPU
RTX PRO 4000 SFF
24GB
GPU
RTX PRO 2000
16GB
GPU
RTX 6000 Ada
48GB
GPU
RTX 5880 Ada
48GB
RTX
RTX 5000 Ada
32GB
GPU
RTX 4500 Ada
24GB
RTX
RTX 4000 Ada
20GB
RTX
RTX 4000 SFF Ada
20GB
GPU
RTX 3500 Ada Mobile
12GB
GPU
RTX 2000 Ada
16GB
GPU
RTX A6000
48GB
GPU
RTX A5000
8GB
GPU
RTX A5000 Max-Q
16GB
GPU
RTX A5000 Mobile
16GB
GPU
RTX A4000
16GB
GPU
RTX A4000 Max-Q
8GB
GPU
RTX A4000 Mobile
8GB
GPU
RTX A3000 Mobile
6GB
GPU
RTX A2000
6GB
GPU
RTX A2000 Embedded
4GB
GPU
RTX A2000 Max-Q
4GB
GPU
RTX A2000 Mobile
4GB
GPU
A800
40GB
GPU
A100
80GB
GPU
A40
48GB
GPU
A30
24GB
GPU
A10
24GB
GPU
A2
16GB
RTX
RTX 5090
32GB
RTX
RTX 5090 D
32GB
RTX
RTX 5090 Mobile
24GB
RTX
RTX 5080
16GB
RTX
RTX 5080 Mobile
16GB
RTX
RTX 5070
12GB
RTX
RTX 5070 Mobile
8GB
RTX
RTX 5070 Ti
16GB
RTX
RTX 5070 Ti Mobile
12GB
RTX
RTX 5060 Ti
16GB
RTX
RTX 5060
8GB
RTX
RTX 5060 Mobile
8GB
RTX
RTX 5050
8GB
RTX
RTX 5050 Mobile
8GB
RTX
RTX 4090
24GB
RTX
RTX 4090D
24GB
RTX
RTX 4090 Mobile
16GB
RTX
RTX 4080 SUPER
16GB
RTX
RTX 4080
16GB
RTX
RTX 4080 Mobile
12GB
RTX
RTX 4070
12GB
RTX
RTX 4070 Mobile
8GB
RTX
RTX 4070 Ti
12GB
RTX
RTX 4070 Super
12GB
RTX
RTX 4070 Ti Super
16GB
RTX
RTX 4060
8GB
RTX
RTX 4060 Ti
8GB
RTX
RTX 4090 Laptop
16GB
RTX
RTX 4080 Laptop
12GB
RTX
RTX 4070 Laptop
8GB
RTX
RTX 4060 Laptop
8GB
RTX
RTX 4050 Laptop
6GB
RTX
RTX 3090
24GB
RTX
RTX 3090 Ti
24GB
RTX
RTX 3080
12GB
RTX
RTX 3080 Ti
12GB
RTX
RTX 3080 Mobile
16GB
RTX
RTX 3070
8GB
RTX
RTX 3070 Ti
8GB
RTX
RTX 3070 Ti Mobile
8GB
RTX
RTX 3060 Ti
8GB
RTX
RTX 3060
12GB
RTX
RTX 3060 Mobile
6GB
RTX
RTX 3050 Mobile
4GB
GPU
RTX 2050 Mobile
4GB
Jetson
Jetson AGX Orin 64GB
64GB
Jetson
Jetson AGX Orin 32GB
32GB
Jetson
Jetson Orin NX 16GB
16GB
Jetson
Jetson Orin NX 8GB
8GB
Jetson
Jetson Orin Nano 8GB
8GB
Jetson
Jetson Orin Nano 4GB
4GB
OS
linux
Arch
x86_64
Kernel Builder
19aaa64