[Paper Review] SoftDTW-CUDA-Torch: Memory-Efficient GPU-Accelerated Soft Dynamic Time Warping for PyTorch
A memory-efficient PyTorch CUDA implementation of SoftDTW that removes the 1024-length limit, uses a log-space backward pass, and offers fused/unfused modes to trade memory for speed, with PyTorch autograd support and Soft-DTW barycenter.
We present softdtw-cuda-torch, an open-source PyTorch library for computing Soft Dynamic Time Warping (SoftDTW) on GPUs. Our implementation addresses three key limitations of existing GPU implementations of SoftDTW: a hard sequence-length cap of 1024, numerical instability in the backward pass for small smoothing parameters, and excessive GPU memory consumption from materializing pairwise distance tensors. We introduce (1) tiled anti-diagonal kernel execution that removes the sequence-length constraint, (2) a log-space back-ward pass that prevents floating-point overflow, and (3) a fused distance-computation mode that eliminates the O(BN M ) intermediate distance tensor, achieving up to 98% memory reduction compared to prior work. The library supports arbitrary sequence lengths, full PyTorch autograd integration, and Soft-DTW Barycenter computation. Code is available at https://github.com/BGU-CS-VIL/sdtw-cuda-torch.
Motivation & Objective
- Enable GPU-accelerated SoftDTW without a 1024-length cap.
- Improve numerical stability in the backward pass for small gamma.
- Reduce GPU memory usage by avoiding full distance tensor materialization.
- Maintain full PyTorch autograd compatibility and support Soft-DTW barycenter computation.
Proposed method
- Tiled anti-diagonal forward pass to remove the sequence-length constraint by launching a separate kernel per anti-diagonal.
- Log-space backward pass using logsumexp to prevent overflow, with final exp applied after backward DP.
- Fused distance computation mode that recomputes distances on-the-fly to reduce memory from O(BNM) to O(B(N+M)).
- Unfused mode precomputes and stores the full distance tensor for fast lookups during DP.
- Provide a SoftDTW barycenter computation via gradient-based optimization (Adam).

Experimental results
Research questions
- RQ1Can SoftDTW be computed on GPUs for arbitrarily long sequences without a hard length cap?
- RQ2Does reworking the backward pass into log-space improve numerical stability for small smoothing parameters?
- RQ3Can memory usage be substantially reduced by fusing distance computations on-the-fly, and what is the runtime trade-off?
- RQ4Is PyTorch autograd-compatible SoftDTW feasible for barycenter computations on large datasets?
Key findings
- The proposed tiled anti-diagonal execution removes the 1024-length constraint, enabling N,M > 1024 on GPU.
- The log-space backward pass prevents overflow and NaNs for small gamma values, improving numerical stability.
- Fused mode achieves up to 40–98% memory reduction compared to unfused, at the cost of 10–15× slower runtime.
- Unfused mode remains faster and is memory-plenty friendly, while fused mode is preferred when GPU memory is the bottleneck.
- The implementation supports full PyTorch autograd integration and Soft-DTW barycenter computation.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.