TAS (Training Autograd System) is a minimalist pytorch-like machine learning framework made with C#, built on top of SimpleLinearAlgebra, a dependency-free matrix library that also lives in this repo — together with the whole family of from-scratch neural networks that grew around them.
This project was made using as reference the work of @iamtrask and his book Grokking Deep Learning.
| Folder | What it is |
|---|---|
src/DLFramework | The TAS framework: tensors, autograd operations, layers, losses and optimizers |
SimpleLinearAlgebra | The matrix + rank-4 tensor library everything is built on — zero dependencies, works anywhere (including Unity) |
SimpleLinearAlgebra/examples | Three from-scratch neural networks written directly with matrices: mono-layer, multi-layer and a convolutional network trained end-to-end |
examples/TasXor | XOR trained with TAS, from raw tensors up to Sequential + SGD |
examples/AutogradDemo | Guided tour of the autograd engine — every gradient checked against the derivative by hand |
examples/SinRegression | An MLP fits y = sin(x) end-to-end and plots the result as ASCII art |
tests/ · SimpleLinearAlgebra/tests | xUnit suites for the framework and the library |
Everything targets netstandard2.0 with C# 7.3 and zero external dependencies, so both libraries work in modern .NET, .NET Framework, Mono and Unity — you can even copy the sources straight into an Assets/ folder.
Until 2026 these lived as five separate repos (
Simple_Linear_Algebra,Simple-vectorized-mono-layer-perceptron,Vectorized-multilayer-neural-network,Convolutional-Neural-Network-From-Scratchand this one); they were merged, modernized and tested here.
dotnet build TAS.sln # build everything
dotnet test TAS.sln # run the test suites
dotnet run --project examples/TasXor # XOR with TAS
dotnet run --project examples/AutogradDemo # guided tour of the autograd engine
dotnet run --project examples/SinRegression # fit sin(x), plotted in the terminal
dotnet run --project SimpleLinearAlgebra/examples/MonoLayerPerceptron # logic gates, by hand
dotnet run --project SimpleLinearAlgebra/examples/MultiLayerPerceptron # XOR, generalized
dotnet run --project SimpleLinearAlgebra/examples/ConvolutionalNeuralNetwork # Fashion-MNIST (auto-downloads)TAS is an automatic differentiation framework inspired by pytorch. It uses a dynamic computational graph that allows changes at runtime, which makes it perfect for experimentation at the expense of performance. The core of TAS are the Tensors, a generalization of the concept of matrix for superior dimensions — TAS currently supports tensors of up to 2 dimensions, which is enough for text analysis, reinforcement learning and classic dense networks.
usingLinearAlgebra;usingDLFramework;usingDLFramework.Operations;vardata=newTensor((Matrix)newdouble[,]{{0,0},{0,1},{1,0},{1,1}},true);The first argument is the Matrix that will be converted into a tensor; the second marks the tensor as autograd, which lets gradients flow through it.
Math operations chain naturally, and if the operands are autograd the result will be too:
varmultiplication=data.MatMul(weights);Backpropagate a gradient through the graph with Backward:
loss.Backward(newTensor(Matrix.Ones(loss.Data.X,loss.Data.Y)));weight.Data-=weight.Gradient.Data*0.1;weight.Gradient.Data*=0;The manual process above is wrapped by familiar abstractions — Sequential, Linear, SigmoidLayer/ReLuLayer, MeanSquaredError and StochasticGradientDescent:
varseq=newSequential();seq.Layers.Add(newLinear(2,5,r));seq.Layers.Add(newSigmoidLayer());seq.Layers.Add(newLinear(5,1,r));seq.Layers.Add(newSigmoidLayer());varsgd=newStochasticGradientDescent(seq.Parameters,1);varmse=newMeanSquaredError();for(vari=0;i<300;i++){varpred=seq.Forward(data);varloss=mse.Forward(pred,target);loss.Backward(newTensor(Matrix.Ones(loss.Data.X,loss.Data.Y)));sgd.Step();}examples/TasXor walks through five versions of the same XOR network, from raw tensors and manual gradient descent (FirstNN) to the full Sequential + SGD + MSE stack (FifthNN) — that progression is the best tour of the framework.
- Autograd operations: Add, Sub, Neg, Mul (element-wise), MatMul, Transpose, Expand, Sum
- Layers: Linear, Sigmoid, ReLu, Sequential
- Loss: Mean Squared Error
- Optimizer: Stochastic Gradient Descent
- Initializators: Gaussian and Uniform random
- Support for real tensors, not just matrices
- Performance adjustments
- More layers, loss functions and activation functions
- Evolutionary-Neural-Networks-on-unity-for-bots
- Chatbot-seq2seq-C-
- Multi-layer-perceptron
- AwesomeUnityProjects
This project was totally handcrafted, so the license is MIT — use it as you want.