Performance¶
This page covers what decides the speed and memory use of tensordev: the choice of an execution
path, the native CPU kernels, device placement, the execution argument, JIT compilation, and the
memory of plans, long paths and gradients. The last section shows benchmark tables and how to
reproduce them.
The examples use this setup:
import jax
jax.config.update("jax_enable_x64", True)
import numpy as np
import tensordev as td
from tensordev.util import random_trigonometric_polynomial_paths
X = random_trigonometric_polynomial_paths(batch=4, steps=32, dim=2, key=0)
Choosing an execution path¶
A signature of increments \(\Delta_1,\dots,\Delta_S\) is computed in one of three ways:
- Scan, the default (
parallel=False): \(S_k=S_{k-1}\otimes\exp(\Delta_k)\) for \(k=1,\dots,S\) in one loop. It keeps one running tensor per path, and its \(S\) steps run one after another. parallel=True: the factors \(\exp(\Delta_1),\dots,\exp(\Delta_S)\) are formed first and multiplied in a balanced tree of depth \(\lceil\log_2 S\rceil\). There are fewer sequential steps, but the factors and partial products take memory of the order of \(S\cdot P\) for \(P\) coordinates (Long paths and gradients), and compilation takes longer.execution="wordwise": the wordwise kernel on one NVIDIA GPU, for eager calls without derivatives.
FSSK signatures and states use the scan or the wordwise kernel. Measured with paths of 200 steps in float32 unless noted, on an Apple M3 and an NVIDIA A40:
| Situation | Path | Measurements |
|---|---|---|
| CPU | Scan | parallel=True takes 3–15 times as long, its gradients 6–12 times, and at batch 32 it needs 310–360 times the memory. |
| NVIDIA GPU, eager signature | execution="wordwise" |
0.6–1.2 ms against 1.6–18 ms for the jitted scan (batch 1 and 32, 2–20 letters); parallel=True is faster only where it takes less than 0.65 ms. In float64 at batch 32, 2.2–2.9 times faster than the scan. |
NVIDIA GPU, eager q = 1 FSSK |
execution="wordwise" at state dimension 3; at state dimension 8 only in float32 up to truncation 8 |
State dimension 3: 1.7–11 times faster than the scan (truncation 4–12). State dimension 8: faster only in float32 up to truncation 8, at truncation 12 slower by 1.6 (float32) and 3.2 (float64). |
GPU under jax.jit, jax.grad or jax.vmap, or a GPU without wordwise support |
parallel=True for small batches, the scan for large batches and long paths |
Gradients at batch 1 are 1.1–23 times faster than with the scan, at batch 32 between 0.3 and 9 times as fast. Gradients with parallel=True compile in 13–520 s, against at most 12 s with the scan. |
Native CPU kernels¶
The wheels for Linux (x86_64 and aarch64) and macOS on Apple Silicon contain compiled CPU kernels,
which JAX calls through the XLA FFI. The Linux wheels are built and tested in manylinux_2_28
containers, so glibc 2.28 is the tested baseline. The kernels compute one operation, the
signature step \(g \mapsto g\otimes\exp_\otimes(\Delta)\) of
Path signatures, truncated at the bidegree \((N, M)\) of a partially
symmetrized core. A step uses them when
- the core is partially symmetrized (
partially_symmetrized=True), in standard coordinates, withdims=(1, q)andq > 1; - the data are
float32orfloat64; - the work per path \(W=\sum_{(n,m)\neq(0,0)}(N+M-n-m+1)\,w_{n,m}\), with \(w_{n,m}\) the number of coordinates of block \((n, m)\), is at least 3000 for \(q = 2\) and 1500 for \(q \ge 3\), and \(W\) times the number of paths is at least 32768;
- JAX runs the computation on the CPU.
Otherwise the same call runs the JAX implementation, without an error or a warning.
The kernels are part of the JAX program. They work inside jax.jit, and both execution="auto"
and execution="jax" use them where they apply. Derivatives are computed by the JAX
implementation, so jax.grad works the same way with and without them:
core = td.make_core(dims=(1, 2), max_trunc=(4, 4), partially_symmetrized=True)
X3 = random_trigonometric_polynomial_paths(batch=8, steps=64, dim=3, key=1)
sig = td.path_signature(X3, core=core)
print(sig[2, 1].shape) # (8, 6): the bidegree (2, 1) block of each path
grad = jax.grad(lambda x: core.tensor_to_flat(td.path_signature(x, core=core)).sum())(X3)
print(grad.shape) # (8, 65, 3)
The kernels are loaded from the private module tensordev._native_cpu, which a wheel with native
kernels bundles, or from the standalone companion module tensordev_native_cpu, which
python -m pip install ./native installs from a clone. This prints whether either is installed:
import importlib.util
print(any(importlib.util.find_spec(name) is not None
for name in ("tensordev._native_cpu", "tensordev_native_cpu")))
To build the kernels when installing from a clone of the repository, set TENSORDEV_BUILD_NATIVE:
TENSORDEV_BUILD_NATIVE=1 python -m pip install .
This needs a C++17 compiler; the build environment fetches CMake and the JAX headers. A failed native build is reported, not replaced by a wheel without kernels. The native README explains platform wheels, the macOS deployment target and the binary interface. For the plain installation see Installation.
Device placement¶
With a CUDA-enabled JAX installation, device placement follows JAX. To compute only a signature on a GPU, move the path and leave the rest of the application on the CPU:
gpu = jax.devices("gpu")[0]
X_gpu = jax.device_put(X, gpu)
sig_gpu = td.path_signature(X_gpu, trunc=4)
GPU computations use JAX on the selected device.
jax.devices() lists the devices that JAX sees, and JAX_PLATFORMS=cpu keeps a process on the
CPU.
On NVIDIA GPUs of the Ampere generation and newer, XLA runs float32 matrix products in TF32
by default, which keeps about three significant digits. tensordev requests full float32
precision for its own matrix products, so its results do not depend on this setting. Your own
JAX code around tensordev still follows it; to change it for the whole process:
import jax
jax.config.update("jax_default_matmul_precision", "highest")
Wordwise GPU execution¶
Wordwise execution (execution="wordwise") parallelizes over words and paths
for ordinary signatures and q=1 FSSK signatures, across all supported core
types. This alpha option requires eager float32/float64 calls on one NVIDIA
GPU (compute capability 8.0+); its test suite passes on an NVIDIA A40. The default
execution="auto" does not select it, and unsupported requests raise; see the function
docstrings for restrictions.
Alpha
Check the results of execution="wordwise" against execution="jax".
The execution argument is accepted by path_signature, calls of a
Signature, fssk_vsig,
fssk_state, and the methods vsig, states, update_with_path and
update_with_increment of StateSpaceSignature.
| Value | Implementation |
|---|---|
"auto" (default) |
The JAX implementation on every device, as with "jax". |
"jax" |
The JAX implementation; never selects the wordwise kernels. |
"wordwise" |
The alpha NVIDIA kernels. A call that does not meet the requirements below raises ValueError instead of falling back. |
Requirements of execution="wordwise":
| Requirement | Detail |
|---|---|
| Workload | Ordinary signatures (path_signature, Signature), or FSSK signatures and states with q = 1. |
| Core | A JAX core of any type: total degree (including the default core), bidegree, shear, partially symmetrized. |
| Call | Eager: not inside jax.jit, jax.grad or jax.vmap. |
| Options | For signatures, parallel=False and accumulate_in_tree=False, the defaults. |
| Input | A JAX array of float32 or float64 on one NVIDIA GPU with CUDA compute capability 8.0 or newer. |
| Derivatives | Not supported. For gradients use "auto" or "jax", which differentiate the JAX implementation. |
On a CPU, a wordwise request raises, and "auto" agrees with "jax":
X_cpu = jax.device_put(X, jax.devices("cpu")[0])
try:
td.path_signature(X_cpu, trunc=4, execution="wordwise")
except ValueError as error:
print(error)
# execution='wordwise' requires input on a single NVIDIA GPU with CUDA compute capability
# 8.0 or newer. Use execution='jax' or 'auto' for portable execution.
sig_auto = td.path_signature(X_cpu, trunc=4)
sig_jax = td.path_signature(X_cpu, trunc=4, execution="jax")
np.testing.assert_allclose(td.tensor_to_flat(sig_auto), td.tensor_to_flat(sig_jax))
On a supported GPU the request is the same call with the path on that device, for example
td.path_signature(X_gpu, trunc=4, execution="wordwise") with X_gpu as in
Device placement.
For a piecewise linear path with increments \(\Delta_k\) and \(S_k=\pi_{\le N}\mathrm{Sig}(X)_{0,t_k}\), Chen's identity gives the coefficient of a word \(w=i_1\cdots i_n\) after step \(k\) as
A word needs only its own prefixes, so words and paths are processed in parallel. One kernel
serves ordinary and q = 1 FSSK signatures. With a state \(P_v\in\mathbb{R}^R\) for every word \(v\)
and \((A_\Delta X)_{u\ell}=X_u\,\Delta^{\ell}\) for a word \(u\) and a letter \(\ell\), a step is
with the coefficients E, psi, phi of the FSSK recursion; the
signature is \(R=1\), \(E=1\), \(\psi_{n-1}=\varphi_{n-1}=1/n!\), the formula above. For a partially
symmetrized core the words are replaced by their classes, and \(A_\Delta\) sums over the letters
that a class can end with.
One launch computes all levels. A lane of the GPU owns a set of words that contains their prefixes:
| Core | Words of one lane |
|---|---|
| Total degree | A word of length \(N-L\), its prefixes and its extensions by at most \(L\) letters. |
| Ordered bidegree | A word of length \(N-1\), its prefixes and its extensions by one prime letter, or by one double-prime letter. |
| Partially symmetrized | A class of the top bidegree and the classes of its prefixes. |
A word owned by several lanes is computed by each of them and stored by one. The approach is from
pathsig (Acknowledgements); the
technical note adapts it to the bidegree layouts.
JIT and compilation¶
tensordev functions are JAX code. Wrap a computation in jax.jit to compile it as one
program: the first call traces and compiles it, and later calls with inputs of the same shape and
dtype reuse the compiled program. A new shape or dtype compiles again.
signature = jax.jit(lambda x: td.path_signature(x, trunc=4))
sig = signature(X) # traces and compiles
sig = signature(2.0 * X) # same shape and dtype: reuses the program
sig = signature(X[:, :17]) # new shape: compiles again
print(td.tensor_to_flat(sig).shape) # (4, 31)
Without jax.jit, the first call also compiles, because the implementation compiles its inner
loops; later calls are faster. The benchmark tables show both
phases.
A traced function keeps the core it was traced with. The module-level operations, the default
core and its default truncation are read during tracing, so a later td.set_default_core does not
reach a function that is already compiled:
signature = jax.jit(lambda x: td.path_signature(x))
td.set_default_core(dims=2, max_trunc=3)
print(td.tensor_to_flat(signature(X)).shape) # (4, 15): truncation 3
td.set_default_core(dims=2, max_trunc=2)
print(td.tensor_to_flat(signature(X)).shape) # (4, 15): still truncation 3
print(td.tensor_to_flat(td.path_signature(X)).shape) # (4, 7): an eager call sees the new core
td.reset_default_core()
Set the default core before you trace, or pass core= explicitly. See
Tensor algebra for set_default_core and reset_default_core.
Memory¶
Plans of bounded cores¶
core_expected_memory gives the plan memory of a core
configuration without building the core; see
Shuffle plans and memory.
Long paths and gradients¶
For a path with \(S\) increments and a truncation with \(P\) coordinates, the options of
path_signature behave as follows.
| Option | Memory |
|---|---|
parallel=False (default) |
Streams the increments through a scan and keeps one running tensor of \(P\) coordinates per path. Work memory is of the order of the input plus these running tensors; it does not grow with \(S \cdot P\). |
parallel=True |
Forms the exponential of every increment first, then combines them with an associative scan. More parallelism; memory grows with \(S \cdot P\). |
block_size=B |
\(B\) must divide \(S\). Computes the signatures of the \(S/B\) blocks side by side and, with accumulate=True, chains them with Chen's identity. The output has a block axis of length \(S/B\). It does not lower the peak memory. |
jax.grad |
Reverse-mode differentiation keeps intermediate tensors of every step: memory grows with \(S \cdot P\). |
XLA reports the temporary memory of a compiled function. With \(S = 1024\) and \(P = 31\) (two dimensions, truncation 4), on the CPU with JAX 0.10.0:
def work_kib(fn, x):
"""Temporary memory of the compiled function, as estimated by XLA, in KiB."""
return jax.jit(fn).lower(x).compile().memory_analysis().temp_size_in_bytes / 2**10
X_long = random_trigonometric_polynomial_paths(batch=4, steps=1024, dim=2, key=0)
loss = lambda x: td.tensor_to_flat(td.path_signature(x, trunc=4)).sum()
print(round(work_kib(lambda x: td.path_signature(x, trunc=4), X_long))) # 128
print(round(work_kib(lambda x: td.path_signature(x, trunc=4, parallel=True), X_long))) # 2486
print(round(work_kib(lambda x: td.path_signature(x, trunc=4, block_size=64), X_long))) # 145
print(round(work_kib(jax.grad(loss), X_long))) # 803
blocks = td.path_signature(X_long, trunc=4, block_size=64)
print(td.tensor_to_flat(blocks).shape) # (4, 16, 31): the running signature after each block
For long paths, keep the default parallel=False. If a gradient does not fit in memory, process
the batch in smaller pieces.
Benchmarks¶
The scripts in benchmarks/ are
diagnostics, not tests: timings depend on the machine, the JAX version and the backend. They write
JSON files, and docs/scripts/benchmarks.py turns these into the tables below. Each table states
where it was measured.
Bidegree versus total degree¶
benchmarks/bidegree_efficiency.py compares a bidegree core with the total-degree core on a
four-dimensional path, split as \((2, 2)\). It times ordinary signatures (td.path_signature) and
Volterra signatures (td.vsig with a FractionalKernel with \(\beta = 0.7\) and \(A = I_4\),
scheme="quadratic", order=0). The bidegree core is ordered and in standard coordinates
(make_core(dims=(2, 2), max_trunc=(N, N))), so the native CPU kernels play no part.
A matched comparison sets total degree \(2N\) against bidegree \((N, N)\): both keep words up to
length \(2N\), but the bidegree core drops the words with more than \(N\) letters from either half of
the alphabet. The payload column of the first table shows the coordinate counts of
Bidegree tensors for \(d' = d'' = 2\), counting the scalar.
With --include-mismatched the script adds total degree 6 against bidegree
\((4, 4)\), labelled non-equivalent: \((4, 4)\) also keeps words of lengths 7 and 8, so that row is no
speed comparison.
The script times these phases separately:
- setup of the core and the kernel;
- in
outer-jitmode, lowering and compilation of the whole call, before it runs; - the first execution; in
directmode, which calls the public function without an outerjax.jit, it includes the compilation done inside the call; - warm executions after a few untimed warm-up calls.
Every output array is synchronized before a timer stops. The JSON file also records XLA's cost and
memory analysis of the outer-jit rows; these are diagnostic estimates, not timings, and are not
in the tables.
Warm calls: medians of 7 timed calls after 2 warm-up calls, in milliseconds. The payload counts the coordinates of the output, including the scalar. The ratio is the total-degree time divided by the bidegree time; above 1 the bidegree core is faster.
| Workload | Comparison | Mode | Payload, total / bidegree | Total degree | Bidegree | Ratio |
|---|---|---|---|---|---|---|
| Signature, 512 increments | total 6 vs (3, 3) | direct |
5,461 / 2,229 | 4.26 | 4.08 | 1.05 |
| Signature, 512 increments | total 6 vs (3, 3) | outer-jit |
5,461 / 2,229 | 3.83 | 4.55 | 0.84 |
| Signature, 512 increments | total 8 vs (4, 4) | direct |
87,381 / 31,381 | 62.6 | 32.6 | 1.92 |
| Signature, 512 increments | total 8 vs (4, 4) | outer-jit |
87,381 / 31,381 | 63.1 | 15.4 | 4.09 |
| Volterra signature, 24 increments | total 6 vs (3, 3) | direct |
5,461 / 2,229 | 47.3 | 24.5 | 1.93 |
| Volterra signature, 24 increments | total 6 vs (3, 3) | outer-jit |
5,461 / 2,229 | 55.7 | 20.7 | 2.70 |
| Volterra signature, 24 increments | total 8 vs (4, 4) | direct |
87,381 / 31,381 | 886 | 85.1 | 10.40 |
| Volterra signature, 24 increments | total 8 vs (4, 4) | outer-jit |
87,381 / 31,381 | 923 | 74.9 | 12.33 |
First call and compilation, in milliseconds. In direct mode the first call includes the compilation done inside the call; in outer-jit mode lowering and compilation are timed before the first call.
| Workload | Core | direct: first call |
outer-jit: lowering |
compilation | first call |
|---|---|---|---|---|---|
| Signature, 512 increments | total 6 | 183 | 14.4 | 44.7 | 4.05 |
| Signature, 512 increments | bidegree (3, 3) | 316 | 44.9 | 178 | 5.29 |
| Signature, 512 increments | total 8 | 193 | 18.1 | 70.3 | 68.0 |
| Signature, 512 increments | bidegree (4, 4) | 756 | 80.4 | 340 | 25.3 |
| Volterra signature, 24 increments | total 6 | 745 | 65.6 | 447 | 51.7 |
| Volterra signature, 24 increments | bidegree (3, 3) | 1,114 | 255 | 972 | 21.3 |
| Volterra signature, 24 increments | total 8 | 1,640 | 64.5 | 432 | 954 |
| Volterra signature, 24 increments | bidegree (4, 4) | 2,150 | 229 | 1,392 | 73.7 |
Machine: macOS-26.3.1-arm64-arm-64bit, JAX backend cpu (cpu:0); Python 3.12.12, JAX 0.10.0, jaxlib 0.10.0; float64, preset standard, Volterra scheme quadratic.
To reproduce, run from a clone of the repository (the script imports helpers from notebooks/):
# quick check
PYTHONPATH=src python benchmarks/bidegree_efficiency.py \
--preset smoke --cases matched6 --modes outer-jit
# the tables above
PYTHONPATH=src python benchmarks/bidegree_efficiency.py \
--preset standard --output benchmarks/results/bidegree_efficiency.json
python docs/scripts/benchmarks.py
The script also writes a CSV file next to the JSON file. --dtype float32,
--volterra-scheme fft and --clear-caches (clear the JAX caches before every row, for cold
starts) change the setup; --help lists all options.
Wordwise versus JAX¶
benchmarks/wordwise_gpu.py checks the alpha wordwise kernels against the JAX implementation and
times both on one NVIDIA GPU with compute capability 8.0 or newer. It can cover ordinary
signatures and q = 1 FSSK recursions (hidden states and the readout), total-degree, bidegree and
partially symmetrized cores in standard and shear coordinates, float32 and float64, and
terminal, accumulated and independent block outputs. Differentiation is not benchmarked, because
transformed calls use the JAX implementation.
Warm calls: medians of 30 timed calls after 5 warm-up calls, in milliseconds, for a batch of 4 paths with 16 increments. Wordwise and JAX calls are compiled with jax.jit and alternate; the automatic call is the public function called eagerly. The ratio is the wordwise median divided by the JAX median, with its paired bootstrap 95% interval; below 1 the wordwise kernel is faster. The error is the largest absolute difference from the JAX result. The gate passes when the wordwise median is at least 20% below the JAX median and the upper end of the interval is at least 10% below 1.
| Workload | Core | dtype | Blocks | Wordwise | JAX | Automatic | Wordwise / JAX | Error | Gate |
|---|---|---|---|---|---|---|---|---|---|
| Signature | total-standard 3 | float32 | terminal | 0.167 | 0.499 | 2.93 | 0.34 (0.31–0.37) | 0.0e+00 | passed |
| Signature | bidegree-partial-standard (2, 1) | float32 | terminal | 0.260 | 0.657 | 4.38 | 0.40 (0.39–0.40) | 0.0e+00 | passed |
| FSSK state | total-standard 3 | float32 | terminal | 0.181 | 0.377 | 1.00 | 0.48 (0.42–0.50) | 1.2e-10 | passed |
| FSSK readout | total-standard 3 | float32 | terminal | 0.653 | 0.832 | 1.69 | 0.78 (0.76–0.80) | 2.3e-10 | passed |
| FSSK state | bidegree-partial-standard (2, 1) | float32 | terminal | 0.259 | 0.546 | 1.16 | 0.47 (0.45–0.48) | 1.2e-10 | passed |
| FSSK readout | bidegree-partial-standard (2, 1) | float32 | terminal | 0.731 | 0.941 | 1.91 | 0.78 (0.77–0.79) | 2.3e-10 | passed |
Lowering and compilation of the jitted calls, and the first automatic call, which includes its compilation, in milliseconds.
| Workload | Core | dtype | Blocks | Wordwise: lowering | compilation | JAX: lowering | compilation | Automatic: first call |
|---|---|---|---|---|---|---|---|---|
| Signature | total-standard 3 | float32 | terminal | 800 | 229 | 51.5 | 195 | 675 |
| Signature | bidegree-partial-standard (2, 1) | float32 | terminal | 198 | 218 | 78.2 | 252 | 668 |
| FSSK state | total-standard 3 | float32 | terminal | 625 | 589 | 307 | 426 | 605 |
| FSSK readout | total-standard 3 | float32 | terminal | 1,086 | 1,410 | 535 | 1,286 | 2,385 |
| FSSK state | bidegree-partial-standard (2, 1) | float32 | terminal | 680 | 525 | 301 | 721 | 1,198 |
| FSSK readout | bidegree-partial-standard (2, 1) | float32 | terminal | 883 | 1,376 | 713 | 1,715 | 3,235 |
Device: NVIDIA A40 (compute capability 8.6, PJRT C API cuda 12090); host Linux-3.10.0-1160.el7.x86_64-x86_64-with-glibc2.36; Python 3.12.12, tensordev source checkout, JAX 0.10.0, jaxlib 0.10.0, NumPy 2.5.4; recorded 2026-11-24.
To reproduce, on a machine with a supported GPU:
PYTHONPATH=src python benchmarks/wordwise_gpu.py \
--workloads ordinary fssk \
--families total-standard bidegree-partial-standard \
--fssk-outputs state readout \
--warmups 5 --repeats 30 \
--output benchmarks/results/wordwise_gpu.json
python docs/scripts/benchmarks.py
--families, --dtypes, --block-modes, --coefficient-modes and --initial-states select
the rest of the matrix; --help lists all options.