This page explains how to benchmark the tensor factor engine on synthetic data. The benchmark is designed to be reproducible without proprietary market data.
python -m pip install -e '.[dev]'
python scripts/benchmark_tensor_factors.py \
--device cpu --n-dates 750 --n-stocks 1000 --window 20 \
--repeat 10 --warmup 3 --threads 1 --interop-threads 1 --seed 42 \
--json-out artifacts/benchmark-v1.jsonThis is the canonical cross-platform protocol v1 CPU command. It writes a
machine-readable report to artifacts/benchmark-v1.json. On systems with GNU
Make, make benchmark is an equivalent shortcut.
python scripts/benchmark_tensor_factors.py \
--device cpu \
--n-dates 750 \
--n-stocks 1000 \
--window 20 \
--repeat 10 \
--warmup 3 \
--threads 1 \
--interop-threads 1 \
--seed 42 \
--json-out artifacts/benchmark-v1.jsonProtocol v1 fixes the panel, seed, rolling window, repetitions, and PyTorch thread pools. Submit this CPU result and the generated JSON before optional variants so reports remain comparable across machines.
Run the same fixed workload on CUDA separately:
python scripts/benchmark_tensor_factors.py --device cudaGPU results belong in their own comparison group. Do not interpret a CPU/GPU or multi-thread/single-thread difference as a controlled hardware ranking.
python scripts/benchmark_tensor_factors.py \
--device auto \
--n-dates 1500 \
--n-stocks 3000 \
--window 20 \
--repeat 10 \
--warmup 3 \
--threads 1 \
--interop-threads 1 \
--seed 42The script prints a Markdown table with environment details, mean runtime, runtime standard deviation, and peak CUDA memory when available.
The benchmark covers representative operations:
cs_rank(close)- rolling
ts_mean - rolling
ts_rank - rolling
ts_corr ewmacompute_legacy_seton a six-factor subset
The goal is to compare factor-engine behavior across machines and devices, not to claim universal throughput. Results depend on PyTorch version, CPU, GPU, CUDA runtime, memory bandwidth, panel shape, factor subset, and mask density.
When sharing benchmark results, include:
- commit SHA
- command
- Python version
- PyTorch version
- CPU and GPU model
- CUDA availability, CUDA version, and CUDA device name
- protocol version, thread counts, seed, panel size, window, repeat, and warmup
- whether the run used CPU, CUDA, or both
Small panels may not benefit from GPU execution because transfer overhead and kernel launch overhead dominate runtime. Larger panels and wider universes are more likely to show GPU advantages, especially for rolling operations and multi-factor computation.
Use this benchmark as an engineering diagnostic. It is separate from backtest quality, factor IC, or trading performance.