A pure-NumPy deep learning framework with reverse-mode automatic differentiation
Project description
BareTensor
Autograd engine and transformer framework in pure Python/NumPy — verified against PyTorch's C++ backend to ≤ 1e⁻⁴.
Installation
pip install baretensor
Requires Python 3.10+ and NumPy ≥ 1.26.
Quick Start
from baretensor import Tensor
# Forward pass traces the graph automatically
x = Tensor([[1.0, 2.0]], requires_grad=True)
w = Tensor([[0.5], [-0.3]], requires_grad=True)
y = x @ w
y.backward()
print(w.grad) # exact analytical gradient, not an approximation
See the examples/ directory on GitHub for full working demos (XOR, MNIST, Transformer, MicroGPT, Adam vs SGD).
What's Here
- Autograd engine — dynamic DAG, topological sort, reverse-mode differentiation
- Analytical Jacobians — Softmax Cross-Entropy, LayerNorm, Batched MatMul. No numerical approximation
- Gradient un-broadcasting — correctly collapses broadcasted dimensions across batch axes
- Micro-GPT — autoregressive Transformer Decoder with causal masking, positional embeddings, scatter-add gradient routing
- Module system —
Module/Linear/Embeddingwith recursive param tracking andstate_dictserialization - Optimizers —
SGD(vanilla) andAdam(adaptive, bias-corrected, optional weight decay)
Verified Against PyTorch
| Feature | Status | Test |
|---|---|---|
| Linear + ReLU autograd | ✅ | test_linear_relu_autograd |
| Layer Normalization (3D) | ✅ | test_layer_norm_3d_autograd |
| Multi-Head Attention | ✅ | test_mha_autograd_parity |
| Softmax Cross-Entropy | ✅ | test_cross_entropy_parity |
| Causal Masking | ✅ | test_causal_mask_parity |
Architecture
class MicroGPT(Module):
def __init__(self, vocab_size, d_model, num_heads):
self.token_emb = Embedding(vocab_size, d_model)
self.transformer = TransformerEncoderBlock(d_model, num_heads)
self.lm_head = Linear(d_model, vocab_size)
def __call__(self, idx, mask=None):
x = self.token_emb(idx)
x = self.transformer(x, mask=mask)
return self.lm_head(x)
License
MIT — see LICENSE.
Full documentation at github.com/Omnivex3/BareTensor.
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 Distribution
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 baretensor-0.2.0.tar.gz.
File metadata
- Download URL: baretensor-0.2.0.tar.gz
- Upload date:
- Size: 503.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e85532035ee9233ed3e20498ddde46d3fd8683cf79d5b29ed8269aa4d9ed6fad
|
|
| MD5 |
d1f1c664dc679ceda62e59644e74779c
|
|
| BLAKE2b-256 |
5320059cae0ea45660b2b614a43137fcb407a06bb1522f791ff35aef1b186bd8
|
File details
Details for the file baretensor-0.2.0-py3-none-any.whl.
File metadata
- Download URL: baretensor-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d50e7d8d7cc3935693d220711d2c9500b6773eee5e339384582b1958d3910153
|
|
| MD5 |
2f6c203112f394ae4316addc62800145
|
|
| BLAKE2b-256 |
1617c046fc78b90f21e57b5f3d33b0410c7bae165f88d6f7b01c82def0b9d016
|