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.1.0 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(b.sum(axis=1).tolist())
print(ts.concat([b, b], axis=0).shape, b.astype("float64").dtype)
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 development run reporting 1.1.0, TensorStudio
beat NumPy on 23 small operation benchmark cases and lost on 80
NumPy-comparable cases. Against PyTorch CPU 2.12.1+cpu, TensorStudio won 74
local cases and lost 34. The strongest local wins were small eager operations,
small contiguous axis reductions, and the simple NumPy convolution/pooling
references where framework dispatch or Python loops dominate; larger matrix
multiplication, PyTorch convolution and pooling, larger axis reductions, 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.0017 ms | 0.0036 ms | 0.0580 ms | 2.1201x | 33.8536x |
mean |
(32,) |
0.0018 ms | 0.0078 ms | 0.0127 ms | 4.2927x | 7.0047x |
sum_axis1 |
(16, 16) |
0.0021 ms | 0.0029 ms | 0.0068 ms | 1.3727x | 3.2193x |
chain_relu |
(128,) |
0.0086 ms | 0.0039 ms | 0.0559 ms | 0.4478x | 6.5042x |
matmul |
(256, 256) |
4.1154 ms | 0.3679 ms | 0.0931 ms | 0.0894x | 0.0226x |
conv2d_3x3_padding1 |
(1, 1, 8, 8) |
0.1788 ms | 1.2241 ms | 0.0131 ms | 6.8478x | 0.0731x |
max_pool2d_2x2 |
(1, 1, 16, 16) |
0.0146 ms | 0.2649 ms | 0.0062 ms | 18.1659x | 0.4242x |
avg_pool2d_2x2 |
(1, 1, 16, 16) |
0.0139 ms | 0.5486 ms | 0.0052 ms | 39.5974x | 0.3748x |
elementwise_backward |
(1024,) |
2.3885 ms | n/a | 0.1947 ms | n/a | 0.0815x |
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.
- Convolution and pooling support are currently limited to CPU NCHW
conv2d,max_pool2d, andavg_pool2dstyle workloads. - Reductions support all-element or single-axis reductions, not tuple-axis reductions yet.
- No sparse tensors or advanced indexing.
- Dtype casting is basic and does not include a full promotion/casting policy.
- Experimental performance; benchmarks are local references only.
- Pickle serialization is for trusted TensorStudio objects only.
Roadmap
- CUDA backend
- Graph/JIT mode
- Broader convolution ops, adaptive/global pooling, and image-model examples
- Richer 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.1.0.tar.gz.
File metadata
- Download URL: tensorstudio-1.1.0.tar.gz
- Upload date:
- Size: 98.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
effc28c7897fcdb3e6ca4eae38a4a9647f5dfe00caef484166e30db5f6effe2e
|
|
| MD5 |
b322d612a727212fe703e15b9d707a7f
|
|
| BLAKE2b-256 |
6c93fcb1f9d689e1ec64753b828920faae70aba333d9a9ef6b7411954c38e33a
|
File details
Details for the file tensorstudio-1.1.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 723.4 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da0cbeb9d53010163349bc7b60d12a58f8c7d8cf2e8cf3a3934a4266efb5a5e0
|
|
| MD5 |
639e987f91ad747355f6bf774520eb6e
|
|
| BLAKE2b-256 |
e39ab9c210b3e8f05e33cc24534d83cc49e055fdcbce6b71625f5fcd9946cdaf
|
File details
Details for the file tensorstudio-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 923.5 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.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e151b7c8e41abf2c1f800148865f3637e1d5c3848eda7a55886700a7f9d37dd
|
|
| MD5 |
0305c99b3e1b5180c3f7aa9ab4c58465
|
|
| BLAKE2b-256 |
e6dea08280a8276a120ad820a25decdd6a4aca91e5952c891cfca2968edf6195
|
File details
Details for the file tensorstudio-1.1.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 890.7 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c874654489a2c4300f76439bc0b5e917d606ee670607cda00bdc03f1e7bde7c3
|
|
| MD5 |
b0dff06dff75f3b39c6ca12db71c042a
|
|
| BLAKE2b-256 |
dfc5d97e163ab60f4f29f18d4e46b013d20914826e2353df9da237e1d0bca87e
|
File details
Details for the file tensorstudio-1.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 723.2 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e69119202dc17a2110c3e52080e87d5e57fd7b92ccbe4f4bde789d78a314ed1
|
|
| MD5 |
875d1b26f04c8efd09fcd3ac3922e46e
|
|
| BLAKE2b-256 |
39acf37301037ebed00181b45c90040d8a317c23816c50d07aea2912ad03a8f8
|
File details
Details for the file tensorstudio-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 923.4 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.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbbe9b7798c8861d5be64717c1809fb2bd3af637208c884b6a7748cff0d53a81
|
|
| MD5 |
7926a3fdbc2df3293d1523f7958187d1
|
|
| BLAKE2b-256 |
cc784e6bb8ed8d8ebc9ec95098dc1efd599ec2fb16667f79841d6d89ecf497e6
|
File details
Details for the file tensorstudio-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 890.7 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fdaae42bd0ad21d82d6d20a03523989586316dfc77a4e0ed9c4b2fce87c6c10
|
|
| MD5 |
13b4c73fe036028402911d4437b5d670
|
|
| BLAKE2b-256 |
84fbef760fdd5e038b4ff82487cc2825a10ce664abb05456d3dd1e7f462a260d
|
File details
Details for the file tensorstudio-1.1.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 719.4 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4179d1014a338d9667e8c59a7f235b84c457e30ced5ccf7a676593078f58dd19
|
|
| MD5 |
866486caca640e46514b51b4efd0aa51
|
|
| BLAKE2b-256 |
9a4165174bb16973f9598733262889eebc6a1da7199122df6a3972e99f61f01b
|
File details
Details for the file tensorstudio-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 919.1 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.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbb2872420c7e64e388746972b669b398c3d57f116a039fecf4f5dd59d51f23b
|
|
| MD5 |
ac8bdcfd88afcda4bb27fed252d76481
|
|
| BLAKE2b-256 |
ce682c0411a7e55fad66f96a91b8e1c6a0d0ac8aa547f5f49335a8bf1e650cf9
|
File details
Details for the file tensorstudio-1.1.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 888.3 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c68c884901f4187744e739385ebc9569b409a88949f4a577ab567bd9b821536
|
|
| MD5 |
a6348f65444b04e5f76d029bf2d90972
|
|
| BLAKE2b-256 |
85db256c34b923c3b0f3c6eb07e171406a7878a3725bf3f8c7ab65dbd9211c68
|
File details
Details for the file tensorstudio-1.1.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 803.9 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 |
3a155e1fbe679ea984efa61d81faa00a01a3add1e1e3f608e76d6bd39e04086a
|
|
| MD5 |
374e71705fd7ad4b946bc986bd2f1e02
|
|
| BLAKE2b-256 |
309424d51cbb708a4e2cef191493818bad6fa755e004dfde4c5e9d50b1a7ceaf
|
File details
Details for the file tensorstudio-1.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 917.7 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.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b96896f7046573222301fde99b82c49b8b04f49410209b6dc47b6b52f8885bb
|
|
| MD5 |
412f5699eb9cdc0ece0b1c317146b247
|
|
| BLAKE2b-256 |
255cc053e5fe175095f53fcaaeeb007dd0670bd77664e19b58e1597a6c3fe973
|
File details
Details for the file tensorstudio-1.1.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: tensorstudio-1.1.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 886.7 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b24a883190b137e9aefc1d62c36a77e9165bc4e40530abc8d0a9d4cf06d8027
|
|
| MD5 |
2fda010698446498f5bd4acd43f9be8d
|
|
| BLAKE2b-256 |
5d8522b624a18e2040f48a354ada11d5f712b06949b5bd333644b1bbe8962f64
|