| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A lightweight deep learning training framework implemented from scratch in C++, featuring a PyTorch-style API.
For more details, please refer to the blog post: Write a nn training framework from scratch
TinyTorch implements automatic differentiation by building a dynamic computation graph. Each operation on a Tensor creates a Function node that records both the forward computation and the backward gradient rule. These nodes are linked via nextFunctions, forming a DAG. Calling backward() traverses this graph in reverse topological order, propagating gradients via the chain rule.
TinyTorch/ ├── src/ # Core library (Tensor, Function, nn.Module, Optimizer, ...) ├── examples/ # Standalone example programs │ ├── autograd/ # Automatic differentiation basics │ ├── module/ # Building models with nn.Module │ ├── optimizer/ # Using built-in optimizers │ ├── mnist/ # Full MNIST training pipeline │ ├── nccl/ # NCCL collective communication │ └── ddp/ # Distributed data-parallel training ├── test/ # Unit tests └── third_party/ # Third-party dependencies
mkdir build
cmake -B ./build -DCMAKE_BUILD_TYPE=Release
cmake --build ./build --config Release| Option | Default | Description |
|---|---|---|
| TINYTORCH_BUILD_EXAMPLES | ON | Build example programs |
| TINYTORCH_BUILD_TEST | OFF | Build unit tests |
| TINYTORCH_USE_CUDA | ON | Enable CUDA support |
| TINYTORCH_USE_NCCL | ON | Enable NCCL support |
Each example is an independent executable:
# Autograd basics
cd examples/autograd/bin && ./tinytorch_example_autograd
# nn.Module usage
cd examples/module/bin && ./tinytorch_example_module
# Optimizer usage
cd examples/optimizer/bin && ./tinytorch_example_optimizer
# MNIST training
cd examples/mnist/bin && ./tinytorch_example_mnistFor distributed examples (requires NCCL and multiple GPUs):
# NCCL all-reduce
cd examples/nccl/bin && ./tinytorch_example_nccl <local_rank> <rank> <world_size>
# Distributed data-parallel training
cd examples/ddp/bin && ./tinytorch_example_ddp <local_rank> <rank> <world_size>cd build
ctestThis code is licensed under the MIT License (see LICENSE).
| Back | FazBrowse Home | New Git URL |