TensorStudio is a compact C++ tensor and autograd engine with a Python API for learning, experimentation, and lightweight ML workloads.
Project description
TensorStudio
TensorStudio is a compact C++ tensor and autograd engine with a Python API for learning, experimentation, and lightweight ML workloads.
TensorStudio 1.0.1 is a CPU-only stable API foundation. It is eager-only,
intentionally small, and not a replacement for mature ML frameworks.
Install
From PyPI:
python -m pip install tensorstudio
From a source checkout:
python -m pip install -U pip
python -m pip install -e ".[dev]"
Build source and wheel distributions:
python -m build
python -m twine check dist/*
End users should install wheels and should not need CMake. Source builds require a C++20 compiler because the native extension is implemented in C++.
Platform Setup
Windows is the primary release target. Use Python from python.org and install Microsoft C++ Build Tools or Visual Studio with the Desktop development with C++ workload before building from source:
python -m pip install -U pip
python -m pip install -e ".[dev]"
pytest -q
Linux source builds need GCC or Clang, CMake, and Python development headers:
python -m pip install -U pip
python -m pip install -e ".[dev]"
pytest -q
macOS source builds need Xcode Command Line Tools:
xcode-select --install
python -m pip install -U pip
python -m pip install -e ".[dev]"
pytest -q
Quickstart
import tensorstudio as ts
x = ts.tensor([[1.0, 2.0], [3.0, 4.0]])
y = ts.ones((2, 2))
print((x + y).tolist())
print((x @ y).numpy())
print(x.reshape((4,)).tolist())
Tensor API
TensorStudio supports CPU tensors with float32, float64, int32, int64,
and bool dtypes.
import tensorstudio as ts
ts.manual_seed(7)
a = ts.zeros((2, 3))
b = ts.rand((2, 3))
c = ts.eye(3)
d = ts.linspace(0.0, 1.0, 5)
print(a.shape, a.strides, a.device, a.is_contiguous)
print((b.clamp(0.2, 0.8) + 1).mean().item())
print(c.tolist(), d.tolist())
print(ts.zeros_like(b).shape, ts.randn_like(b, seed=11).dtype)
Autograd
import tensorstudio as ts
x = ts.tensor([1.0, 2.0, 3.0], requires_grad=True)
loss = (x * x).mean()
loss.backward()
print(x.grad.tolist())
Use no_grad() when you want eager computation without recording a graph:
with ts.no_grad():
y = x * 2
Neural Networks
import tensorstudio as ts
from tensorstudio import nn, optim
ts.manual_seed(0)
model = nn.Sequential(nn.Linear(1, 8), nn.Tanh(), nn.Linear(8, 1))
optimizer = optim.SGD(model.parameters(), lr=0.05, momentum=0.9)
scheduler = optim.StepLR(optimizer, step_size=50, gamma=0.5)
criterion = nn.MSELoss()
x = ts.tensor([[0.0], [1.0], [2.0], [3.0]])
y = ts.tensor([[1.0], [3.0], [5.0], [7.0]])
for _ in range(100):
optimizer.zero_grad()
loss = criterion(model(x), y)
loss.backward()
optim.clip_grad_norm_(model.parameters(), max_norm=10.0)
optimizer.step()
scheduler.step()
print(loss.item())
print(model.state_dict().keys())
print(model.parameter_count())
DataLoader
import tensorstudio as ts
from tensorstudio.data import DataLoader, TensorDataset
dataset = TensorDataset(ts.arange(6).reshape((6, 1)), ts.arange(6))
loader = DataLoader(dataset, batch_size=2, shuffle=True, seed=42)
for features, targets in loader:
print(features.shape, targets.shape)
The v1 DataLoader is intentionally single-process so it works cleanly on Windows without multiprocessing setup.
Performance
TensorStudio is optimized for small-to-medium CPU eager workloads, but
performance is still experimental. Benchmarks live in benchmarks/ and can be
run locally:
python benchmark_all.py
python benchmarks/benchmark_report.py
benchmark_all.py writes benchmarks/results.md and includes explicit win
columns for NumPy, TensorFlow, PyTorch, and JAX when those libraries are
available locally.
On one Windows CPython 3.10 run for 1.0.1, TensorStudio beat NumPy on 13
small activation/reduction benchmark cases and lost on 76 NumPy-comparable
cases. Against PyTorch CPU 2.12.1+cpu, TensorStudio won 71 local cases and
lost 23. The strongest local wins were small eager operations where framework
dispatch overhead dominates; larger matrix multiplication, larger transcendental
activations, and larger autograd workloads remain faster in PyTorch and NumPy.
See benchmarks/results.md for the full table, platform details, and exact
timings.
Snapshot from that local run:
| operation | shape | TensorStudio | NumPy | PyTorch CPU | TS vs NumPy | TS vs PyTorch |
|---|---|---|---|---|---|---|
sigmoid |
(32,) |
0.0018 ms | 0.0036 ms | 0.0575 ms | 2.0414x | 32.2110x |
mean |
(32,) |
0.0016 ms | 0.0069 ms | 0.0112 ms | 4.4051x | 7.1262x |
chain_relu |
(128,) |
0.0086 ms | 0.0039 ms | 0.0567 ms | 0.4488x | 6.5977x |
matmul |
(256, 256) |
2.4215 ms | 0.4027 ms | 0.0832 ms | 0.1663x | 0.0343x |
elementwise_backward |
(1024,) |
2.3527 ms | n/a | 0.1887 ms | n/a | 0.0802x |
Speedup is competitor median / TensorStudio median, so values above 1.0x
favor TensorStudio.
Do not treat these results as universal. TensorStudio does not claim to be faster than NumPy, TensorFlow, PyTorch, or JAX overall.
Save And Load
import tensorstudio as ts
from tensorstudio import nn
model = nn.Linear(2, 1)
ts.save({"model": model.state_dict()}, "checkpoint.tsmodel")
checkpoint = ts.load("checkpoint.tsmodel")
Serialization uses pickle. Loading pickle files from untrusted sources is unsafe because pickle can execute arbitrary code.
Development
python -m pip install -e ".[dev,docs]"
python test_all.py --skip-build
ruff check .
mypy python/tensorstudio
pytest -q
python -m build
python -m twine check dist/*
The native extension module is tensorstudio._C, built with CMake, pybind11,
scikit-build-core, and C++20.
Release Checklist
python test_all.pypasses locally.ruff check .passes.mypy python/tensorstudiopasses.pytest -qpasses on Windows, Linux, and macOS.python -m buildpasses.python -m twine check dist/*passes.- Benchmarks are generated and performance claims match the data.
- Clean wheel installs pass on Windows, Linux, and macOS.
- Clean sdist installs pass on Windows, Linux, and macOS.
- Examples run on all platforms.
- Docs match the implemented feature set.
- No PyPI tokens are committed or printed.
- TestPyPI is verified before a real PyPI release.
Publishing
GitHub Actions build wheels with cibuildwheel. The publish workflow is designed
for PyPI trusted publishing with id-token: write; it should not hardcode PyPI
tokens or print secrets.
Current Limitations
- CPU backend only.
- Eager execution only.
- No CUDA or Metal backend yet.
- No BLAS-backed matrix multiplication yet.
- No graph compiler or distributed runtime.
- No convolution layers yet.
- No sparse tensors or advanced indexing.
- Limited dtype casting.
- Experimental performance; benchmarks are local references only.
- Pickle serialization is for trusted TensorStudio objects only.
Roadmap
- CUDA backend
- Graph/JIT mode
- Convolution ops
- Dataset utilities
- Model zoo examples
- ONNX import/export
- Improved memory allocator
- SIMD kernels
- Multithreaded ops
License
TensorStudio is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tensorstudio-1.0.1.tar.gz.
File metadata
- Download URL: tensorstudio-1.0.1.tar.gz
- Upload date:
- Size: 82.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afbe29362801f80fc2ec4ced78d109111aed134b28f40daee9fbbb498b1c2fe6
|
|
| MD5 |
c700f8a2218311e4c36d85697d451ffb
|
|
| BLAKE2b-256 |
007b2c004ddab5f91e84dedd48dfd6c7b3b15a7aeaed0127fb70a5064b22c9f0
|
File details
Details for the file tensorstudio-1.0.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 682.4 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67ddc24d4ee554f35007da75a528a049346aaf3acd23c779bb178b89d690797c
|
|
| MD5 |
7df2611d6c6bb3266dafefd7c1d3a3b1
|
|
| BLAKE2b-256 |
4209c6480fb1b6f449ebd403c1992b394d54915df412d7beb8225d12bbe07f8c
|
File details
Details for the file tensorstudio-1.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 873.2 kB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3af632fd9985c470f58e8259ce018309398455bc91e669d01d30afdc8f9e1f5e
|
|
| MD5 |
9055b3c58398fd5895e0a023a0766889
|
|
| BLAKE2b-256 |
0ddff1abd7aa74191fc8d0906192a11a9afdc62af7c5dd9fde235edc6baa36c9
|
File details
Details for the file tensorstudio-1.0.1-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 847.0 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9931b5094506c26d07cf6b776f2a27a01fa54dfe2b91fcc8fe771c7cd5813ba
|
|
| MD5 |
b5a833eae18b325a0cafc5570f3e58a3
|
|
| BLAKE2b-256 |
f683955e85c9f41655a18250fe26c60e88909701ccb4b6b135aab3ab22e6b8b7
|
File details
Details for the file tensorstudio-1.0.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 682.5 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90336ec8faf7b0079c1ef297ebe2d1176930fe80bea6327fa3e37a246b5c7bb4
|
|
| MD5 |
eb9bcc87316c5fb21322f0b34983c9e9
|
|
| BLAKE2b-256 |
b88e147c044aa0015ef71ed8f45c97b6ed4b29442ad7da1405e627bf2ffdf957
|
File details
Details for the file tensorstudio-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 873.2 kB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0002ab18d003b62838490edccfd9b2befe61ab23e2ecfb89d1306499dff740a
|
|
| MD5 |
07e1745ff5bc6403fea7c54f351e5ba6
|
|
| BLAKE2b-256 |
2d0e7776b12a5ab580bdf31bbe137188333d232148bc0d1699034cb87d9bd784
|
File details
Details for the file tensorstudio-1.0.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 846.9 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cab2d2dab57083bfff0979826c59a493a2db609702482db8fc8f5eff3380f20c
|
|
| MD5 |
df55cad0cdfc4386405c07769109bc48
|
|
| BLAKE2b-256 |
8f21167b97fecd0b6595903033473098e43a84e2962ba0a8d34a668213504cc1
|
File details
Details for the file tensorstudio-1.0.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 678.0 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cde28f012f3101ffc2a4647fd23520c7ccb514a7a70125b916b89a618ee6ce3
|
|
| MD5 |
4d99f99ba24ef1b792479e450546f677
|
|
| BLAKE2b-256 |
3116da948cbd882d092a6fb8a91e571ac972b3398a797aa85e6e030da9fcafbc
|
File details
Details for the file tensorstudio-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 868.7 kB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf5140e9de2baf076b026712d61f72515622cbc5c8aad392342e9bc72f786269
|
|
| MD5 |
9b694d6ca187ae5e410cd907e51e4bce
|
|
| BLAKE2b-256 |
d2a2a384d6b2c15390bd553830bbb9717bd25fcdb1702d3712ccf01e0eee0d2f
|
File details
Details for the file tensorstudio-1.0.1-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 843.9 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99be0aa387655e51a196920cc0c39c8470694f6fb3c72a6afc776bd799b24da0
|
|
| MD5 |
67a39ef13a1a303e1805523f30d0b27e
|
|
| BLAKE2b-256 |
236e8e5f2a14b8d13422a153b496a8537871a3c1947d92b5ef7cef75489c0f6e
|
File details
Details for the file tensorstudio-1.0.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 676.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b04a5b4ec48451040835335575c7f9453a55a512e514461c34e2433ff9e2945b
|
|
| MD5 |
cc3e99bb1c89ffcc0caf364d8a905391
|
|
| BLAKE2b-256 |
27fec53f78c9f5e9cf9223108704a18d19601b5396bfaa071bdf67d13bcec2cc
|
File details
Details for the file tensorstudio-1.0.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 867.6 kB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e500665d47721b51a82c533004f646286264c16a02326833b5c0650c85922eb9
|
|
| MD5 |
31f908a8c8e59e7f8148ce5ddfd60f1c
|
|
| BLAKE2b-256 |
ad9cad1f1a8ae19e5463cd64c07de87789f6bae8be651f640e95d0c7baedd770
|
File details
Details for the file tensorstudio-1.0.1-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: tensorstudio-1.0.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 841.7 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dc6e0c614e8067f035adba42e3f1f1d15a026557962be2384964fc0aa1aec10
|
|
| MD5 |
9dfa1d1a0be6399137c082f6226416f4
|
|
| BLAKE2b-256 |
41e2cf63d8abb78058296d2824a486875da71f96c91a29a9c06cab5357b14e55
|