Tensotron 0.1.0-alpha

This is a prerelease version of Tensotron.
dotnet add package Tensotron --version 0.1.0-alpha
                    
NuGet\Install-Package Tensotron -Version 0.1.0-alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tensotron" Version="0.1.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tensotron" Version="0.1.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="Tensotron" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tensotron --version 0.1.0-alpha
                    
#r "nuget: Tensotron, 0.1.0-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tensotron@0.1.0-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tensotron&version=0.1.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Tensotron&version=0.1.0-alpha&prerelease
                    
Install as a Cake Tool

Tensotron

A PyTorch-faithful, float32 tensor and autograd library for .NET, GPU-accelerated with ILGPU.

The law: for every op it implements, Tensotron matches PyTorch exactly - naming, semantics, broadcasting, gradients (including behavior at kinks/ties/special values). Porting PyTorch code is near-mechanical within the supported surface, which is a deliberate subset of torch.

Scope: feed-forward training/inference - MLPs, CNNs, small RL nets. Not yet implemented: RNN/LSTM/GRU, attention/transformers, Embedding, ConvTranspose, Conv1d/Conv3d, dtypes beyond float32, and PyTorch state_dict interop.

Highlights

  • Define-by-run autograd - toposort backward over a named op graph; Tensor.Backward().
  • Broad op surface, every deterministic op torch-parity tested - elementwise math + activations, broadcasting, reductions, 2D/N-D batched matmul, movement/structure ops, indexing (gather/scatter_add/index_select), Conv2d, MaxPool2d/AvgPool2d, LayerNorm / BatchNorm / GroupNorm, and the common losses (MSE, L1, Huber, BCE-with-logits, NLL, cross-entropy, KL-div).
  • Training stack - Module/Sequential/Linear, SGD/Adam/AdamW/RMSProp, LR schedulers, Kaiming/Xavier init, DataLoader, and full-checkpoint save/load (params + buffers + optimizer & LR-scheduler state, so training resumes exactly).
  • Runs without a GPU - Auto (the default) uses CUDA when present and otherwise falls back to a hand-written managed/SIMD CPU backend (TENSOTRON_BACKEND=simd; no per-op device dispatch, ~645× the ILGPU scalar CPU path at batch-1) — the fast path for small-model CPU inference/training. Its matmul has opt-in row parallelism (TENSOTRON_CPU_THREADS=auto, ~5–12× on big-batch GEMMs; off by default). ILGPU's scalar CPU accelerator (TENSOTRON_BACKEND=cpu) is kept only as a slow correctness-verification reference and warns loudly when selected.

Status

0.1.0-alpha. Large matmul runs on cuBLAS SGEMM (CUDA; matches PyTorch FP32 throughput at scale), with tiled/naive ILGPU kernels otherwise. The runtime is async: kernels queue on ILGPU's in-order default stream and synchronize only at host pulls (ToArray/Item), not per launch. A size-bucketed caching allocator (opt-in via Dispose/DisposeGraph) reuses device buffers, and shape/stride metadata is uploaded once and cached. Adam/SGD are fused single-kernel updates. Buffers are IDisposable (deterministic opt-in release); zero-copy views never free their parent's buffer. The per-op host-side autograd graph (a Tensor/GradNode per op every step) is the dominant cost for very small models — ~95% host-bound — with an opt-in escape hatch: TensorRuntime.Capture/CapturedGraph.Replay records a fixed-shape step once; on CUDA the recorded launches fold into one native CUDA-graph cuGraphLaunch (~6–8× per step), with a buffer-to-buffer software replay fallback (~2–2.7×) off CUDA. Cross-op kernel fusion is not implemented. float32-only storage by design (so no FP16/BF16 path), but TF32 tensor-core matmul is an available one-line knob (TensorRuntime.AllowTf32), currently left off for exact FP32.

Quick start

using Tensotron;

var x = Tensor.FromArray(new[] { 1f, 2f, 3f }, 3).RequireGrad();
var y = (x * x).Sum();   // y = sum(x_i^2)
y.Backward();
// x.Grad == [2, 4, 6]

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Tensotron:

Package Downloads
Bascule.RL

A Godot-free, batched-PPO reinforcement-learning core for .NET, built on the Tensotron tensor + autograd engine. Multi-channel ControlSpec, in-process training and inference, byte-exact model save/load — no Python, no socket bridge, no native runtime.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-alpha 84 7/1/2026