Skip to main content

A pure-NumPy deep learning framework with reverse-mode automatic differentiation

Project description

BareTensor

Python NumPy PyTorch Parity License PyPI version

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 systemModule/Linear/Embedding with recursive param tracking and state_dict serialization
  • OptimizersSGD (vanilla) and Adam (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


Download files

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

Source Distribution

baretensor-0.2.0.tar.gz (503.6 kB view details)

Uploaded Source

Built Distribution

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

baretensor-0.2.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

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

Hashes for baretensor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e85532035ee9233ed3e20498ddde46d3fd8683cf79d5b29ed8269aa4d9ed6fad
MD5 d1f1c664dc679ceda62e59644e74779c
BLAKE2b-256 5320059cae0ea45660b2b614a43137fcb407a06bb1522f791ff35aef1b186bd8

See more details on using hashes here.

File details

Details for the file baretensor-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for baretensor-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d50e7d8d7cc3935693d220711d2c9500b6773eee5e339384582b1958d3910153
MD5 2f6c203112f394ae4316addc62800145
BLAKE2b-256 1617c046fc78b90f21e57b5f3d33b0410c7bae165f88d6f7b01c82def0b9d016

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