Skip to main content

TensorStudio is a compact C++ tensor and autograd engine with a Python API for learning, experimentation, and lightweight ML workloads.

Project description

TensorStudio

CI Wheels PyPI

TensorStudio is a compact C++ tensor and autograd engine with a Python API for learning, experimentation, and lightweight ML workloads.

TensorStudio 1.2.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]"

Install optional extras for ONNX export and Pillow-backed image inputs:

python -m pip install "tensorstudio[onnx,vision]"

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())

Vision

TensorStudio includes a small vision namespace for image preprocessing and compact CNN classifiers. Image file decoding remains the job of Pillow or other image libraries; TensorStudio converts image-like arrays into channel-first tensors and runs the model with its native Conv2d and pooling kernels.

import numpy as np
import tensorstudio as ts
from tensorstudio import nn, optim

image = np.zeros((8, 8, 3), dtype=np.uint8)
x = ts.vision.to_tensor(image).reshape((1, 3, 8, 8))
x = ts.vision.normalize(x, mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))

model = ts.vision.TinyConvClassifier((3, 8, 8), num_classes=2)
target = ts.tensor([1], dtype="int64")
optimizer = optim.SGD(model.parameters(), lr=0.01)

optimizer.zero_grad()
loss = nn.CrossEntropyLoss()(model(x), target)
loss.backward()
optimizer.step()

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.2.0, TensorStudio beat NumPy on 26 small operation benchmark cases and lost on 77 NumPy-comparable cases. Against PyTorch CPU 2.12.1+cpu, TensorStudio won 75 local cases and lost 33. 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.0038 ms 0.0614 ms 2.1691x 35.3154x
mean (32,) 0.0029 ms 0.0131 ms 0.0186 ms 4.5638x 6.4709x
sum_axis1 (16, 16) 0.0027 ms 0.0029 ms 0.0085 ms 1.0894x 3.1408x
chain_relu (128,) 0.0112 ms 0.0051 ms 0.0726 ms 0.4575x 6.4533x
matmul (256, 256) 4.4121 ms 0.3779 ms 0.1669 ms 0.0856x 0.0378x
conv2d_3x3_padding1 (1, 1, 8, 8) 0.2374 ms 1.7112 ms 0.0186 ms 7.2091x 0.0784x
max_pool2d_2x2 (1, 1, 16, 16) 0.0237 ms 0.2764 ms 0.0082 ms 11.6685x 0.3462x
avg_pool2d_2x2 (1, 1, 16, 16) 0.0198 ms 0.7431 ms 0.0073 ms 37.4930x 0.3662x
elementwise_backward (1024,) 3.0196 ms n/a 0.2254 ms n/a 0.0746x

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.

For safer tensor and state_dict interchange, use TensorStudio's non-pickle NPZ helpers:

state = model.state_dict()
ts.save_npz(state, "weights.tsnpz")
model.load_state_dict(ts.load_npz("weights.tsnpz"))

ONNX Export

TensorStudio can export a supported nn.Sequential graph to ONNX when the optional onnx extra is installed:

import tensorstudio as ts
from tensorstudio import nn

model = nn.Sequential(
    nn.Conv2d(1, 2, kernel_size=3, padding=1),
    nn.ReLU(),
    nn.MaxPool2d(2),
    nn.Flatten(),
    nn.Linear(2 * 2 * 2, 3),
)

ts.export_onnx(model, "classifier.onnx", input_shape=(1, 1, 4, 4))

The v1.2 exporter supports Linear, Conv2d, Flatten, ReLU, Sigmoid, Tanh, MaxPool2d, and AvgPool2d. It is an exporter, not an ONNX runtime or importer.

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.py passes locally.
  • ruff check . passes.
  • mypy python/tensorstudio passes.
  • pytest -q passes on Windows, Linux, and macOS.
  • python -m build passes.
  • 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, and avg_pool2d style workloads.
  • Vision utilities are preprocessing and small CNN helpers, not a full computer vision library.
  • ONNX support is export-only for a limited set of TensorStudio modules.
  • 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 and broader export coverage
  • Improved memory allocator
  • SIMD kernels
  • Multithreaded ops

License

TensorStudio is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tensorstudio-1.2.0.tar.gz (109.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tensorstudio-1.2.0-cp313-cp313-win_amd64.whl (731.9 kB view details)

Uploaded CPython 3.13Windows x86-64

tensorstudio-1.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (932.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tensorstudio-1.2.0-cp313-cp313-macosx_11_0_arm64.whl (899.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

tensorstudio-1.2.0-cp312-cp312-win_amd64.whl (731.7 kB view details)

Uploaded CPython 3.12Windows x86-64

tensorstudio-1.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (932.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tensorstudio-1.2.0-cp312-cp312-macosx_11_0_arm64.whl (899.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

tensorstudio-1.2.0-cp311-cp311-win_amd64.whl (727.8 kB view details)

Uploaded CPython 3.11Windows x86-64

tensorstudio-1.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (927.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tensorstudio-1.2.0-cp311-cp311-macosx_11_0_arm64.whl (897.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

tensorstudio-1.2.0-cp310-cp310-win_amd64.whl (812.3 kB view details)

Uploaded CPython 3.10Windows x86-64

tensorstudio-1.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (926.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

tensorstudio-1.2.0-cp310-cp310-macosx_11_0_arm64.whl (895.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file tensorstudio-1.2.0.tar.gz.

File metadata

  • Download URL: tensorstudio-1.2.0.tar.gz
  • Upload date:
  • Size: 109.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for tensorstudio-1.2.0.tar.gz
Algorithm Hash digest
SHA256 0922db9886a13fef48904129728e12182936b158b054ff7c23413d9463b41d1f
MD5 113474e911652766269c08c3076c13e1
BLAKE2b-256 09a6ece69d6191c9e1ebd3cfc9f5812ab0adec5edee8c1a22d616a45aee45a6d

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 041c82b67c40b44304c583a8aa83ff90f8bf3fc98541f9dfee6477078b8476af
MD5 bf5318dd85e7b4d111bf7a1f75ef7da4
BLAKE2b-256 89283dd840bd222cad6b523307457ea444a6c5c87427915edcd7d899a169558f

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d6b4f0e65fcce9ded8ec64d7034321b443430c60e462efd1aa9c3d2d0a80de4
MD5 a5b9e16616d3900024d1f98c4206629c
BLAKE2b-256 5307874507fc32e93819c305790657526bfd9c3d1765e3d75824da365378c522

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c669bf700de006de57dde6a759ef4aaf2e6fbe6336456e84024b15202b3539ee
MD5 aef1fe3af28b764fde34fdae4d8e37a6
BLAKE2b-256 a076cab1a912e57a774f4c5dab672906b94fdf1369c874ebf010d3da6de3988e

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 65ae26af7545c257e6975f1ecd3e6611f16867afff168eed90cd29307f1e3f66
MD5 5267ba1ed459c721416b6332a60c680b
BLAKE2b-256 06cb931bd4cd4e3a95c63b606297a182c964c1bb62b03768c47e599af1257a45

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8cb4e08a45329bc634d2677a8c8c067d0298542c82090dc5540cf6aff328793e
MD5 5a48ab52855fd3820bdc694fcea45f21
BLAKE2b-256 79ddb2c67ea239bb56307c3f86d0d67b6c8223b61c92ae79890e2ff076273162

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58c5ae7258aad16711f4931270c6f8b35284b04fc853b2a800639d8723fadb5c
MD5 f1b2e0ed1bf5201ed1c36020b6bfce59
BLAKE2b-256 88c354d8d2483315b3f29adfacbf42084723eccc3d663ea97d51e6f348d3d065

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8111a7a3249d43db68543299b844dc828c4fefd2ff8c60af0f7e86bdce678a71
MD5 bbac00a30bab61b679113461ea04c46b
BLAKE2b-256 c9944850fdb897045752f7e3f4198541a9c6238120b2967d74e458148aa42be7

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c860a45570441075450e9f21e69c404ae8ac091ba5ff12487f4cec48a85586e6
MD5 fc9d1d8819f3abea897a6c8998bef104
BLAKE2b-256 c7826b40fdf997a5c2d3e2441f5c3dbd4c75126060ca138add024989c7360d59

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 efee3599a320462dc82e20c6ea767e0e87a79259fe564d3a1ebae9e1f9e46ab4
MD5 eec6e8ce7d2adcde547a6e35f4039885
BLAKE2b-256 5bb929be1102074c92caa58acea89eb88c35b28f88fe645ba0e9e02ce0ee9cab

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 dda9b62bbdd370631debfab3308e46339310e296b700ef1917054e5384f22945
MD5 d52586abce24986d4afa341913a931db
BLAKE2b-256 f1fe0c949c28db0340bb6b623c6de0d89a33cc0622c45e6a4ae17f194ecd8f30

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 491e905f04ae02a4104c5029cbb84bc31081726bf792c03a9c9babdcba5cae3d
MD5 0acbde98dc822f9670ff5a2b2cd1bdd0
BLAKE2b-256 6f00ac8fe5ed7d77e1fd1aca37e8fd570a694d6dd7de92174c7146f9cc6bebb4

See more details on using hashes here.

File details

Details for the file tensorstudio-1.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tensorstudio-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25417d73235467f0dc63924ca6bf4a02f150d89cc33a94512c98bc5831d53ae8
MD5 1b4455bb24b1a8e90ee1145a54d24fbc
BLAKE2b-256 31eecad2307f0650298f68073b22d4a0411caa17fc6911ff96cc629c2e090430

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page