In the world of time-series analysis and sequential data, the signature transform is a bit of a hidden gem. Derived from rough path theory, it is a mathematical powerhouse that summarizes the "shape" of a path in a way uniquely suited for machine learning. However, until recently, using it inside a neural network was like trying to run a modern game on a 90s calculator—the math was there, but the software was a massive bottleneck.
Enter Signatory, a library introduced at ICLR 2021 by Patrick Kidger and Terry Lyons. It is designed to make signature transforms as fast and easy to use as a standard convolution or LSTM layer.
TL;DR
Signatory is a high-performance, differentiable library that brings the signature and logsignature transforms to the PyTorch ecosystem with full GPU support. By introducing novel "fused" algorithms and handwritten gradients, it achieves speedups of over 200x in deep learning workflows compared to previous state-of-the-art libraries.
What Problem Does This Paper Address?
The signature transform is a way to extract features from sequential data (like stock prices or handwriting) that captures the order and "area" of the motion. Unlike a Fourier transform, which looks at frequencies, the signature transform is "universally nonlinear," meaning it can approximate any continuous function of a path.
While powerful, signatures were historically used as a preprocessing step. You would calculate the signature on a CPU, save it, and then train a model on those static features. Recently, researchers started embedding these transforms inside neural networks as differentiable layers. The problem? Existing libraries (like esig or iisignature) were CPU-only, single-threaded, and didn't support backpropagation natively. This made training "Deep Signature" models agonizingly slow, as data had to constantly shuffle between the GPU and CPU.
Methods
The authors didn't just port old math to the GPU; they re-engineered the algorithms from the ground up:
- Fused Multiply-Exponentiate: The standard way to compute a signature involves many separate matrix exponentials and tensor products. Signatory introduces a "fused" operation that combines these using a scheme similar to Horner’s method for polynomials. This reduces the asymptotic complexity from $O(N d^N)$ to $O(d^N)$, where $d$ is the number of channels and $N$ is the depth.
- Handwritten Backpropagation: Instead of relying on PyTorch’s automatic differentiation (which can be memory-heavy), the authors wrote the gradients by hand in C++. They utilized a reversibility property of signatures—similar to the adjoint method in Neural ODEs—allowing them to recover intermediate states during the backward pass rather than storing them all in memory.
- Efficient Logsignature Basis: The logsignature is a more compact version of the signature. Signatory uses a new, computationally efficient basis that is faster to calculate than the traditional "Lyndon basis" while remaining perfectly suited for machine learning layers.
- LibTorch Integration: The library is built on C++ primitives but wrapped for Python, ensuring it plays nicely with the PyTorch ecosystem.
Datasets and Benchmarks
The paper evaluates Signatory using:
- Synthetic Benchmarks: Extensive tests varying the number of channels (2–7) and transform depth (2–9) to measure raw computational speed and memory usage.
- Geometric Brownian Motion (GBM): A toy dataset of paths with different volatilities used for a binary classification task. This served as a "Deep Learning Example" to show how the library performs during actual model training.
Key Insights and Ideas
- Algorithmic Fusing Matters: Moving from $O(N d^N)$ to $O(d^N)$ isn't just a "constant factor" improvement; it changes how the computation scales as the transform gets deeper.
- The "GPU-CPU Yo-Yo" is the Real Killer: In the deep learning example, Signatory was 210x faster than the previous best library. Most of this gain didn't just come from the GPU's raw power, but from keeping the data on the GPU and avoiding the massive overhead of moving tensors back and forth to the CPU for the signature calculation.
- Mathematical "Purity" vs. ML Efficiency: The authors realized that for deep learning, we don't necessarily need the mathematically standard Lyndon basis for logsignatures. As long as the basis is consistent and followed by a linear layer, a more computationally efficient basis works just as well.
Key Results
- Raw Speed: On a GPU, Signatory is up to 132x faster than
iisignaturefor forward passes and 166x faster for backward passes in large-scale computations.
- CPU Performance: Even on a single-threaded CPU (no parallelism), Signatory is roughly 5.5x faster than previous libraries thanks to the fused algorithm.
- Memory Efficiency: By using the reversibility property during backpropagation, Signatory can handle much longer sequences or deeper transforms without running out of VRAM.
Limitations and Future Work
The authors note a few areas for improvement:
- Numerical Stability: The $O(1)$ precomputation strategy for querying arbitrary intervals can suffer from numerical issues if the sequences are extremely long.
- Parallel Backprop: While the forward pass is highly parallelized, the current implementation of backpropagation (using the reversibility trick) is not yet parallelized across the sequence length, though it is parallelized across the batch.
- Expansion: The library focuses on PyTorch; support for other frameworks like JAX or TensorFlow was not discussed in this paper.
Signatory is currently available as an open-source project and has become a foundational tool for researchers working at the intersection of rough path theory and deep learning.
Summary updated