A compact, PyTorch-style machine learning framework written in pure C99.
Designed for speed, clarity, and portability - from desktop to embedded.
Documentation »
GPT-2 Example
·
Report Bug
·
Request Feature
Magnetron is a lightweight, research-grade machine learning framework that mirrors the usability of PyTorch - but built entirely from scratch.
Its C99 core, wrapped in a modern Python API, provides dynamic computation graphs, automatic differentiation, and high-performance operators with zero external dependencies.
Originally designed for constrained or experimental environments, Magnetron scales from small embedded systems to full desktop inference and training.
A CUDA backend and mixed-precision support are currently in development.
-
PyTorch-like API
Familiar syntax for building and training models - easy to pick up, minimal to extend. -
Dynamic autograd engine
Eager execution with full gradient tracking on computation graphs. -
Optimized C99 backend
Custom tensor engine with SIMD acceleration (SSE, AVX2, AVX-512, NEON) and multithreaded execution. -
Minimal dependencies
No third-party math libraries; only CFFI is required for the Python interface. -
Lightweight neural modules
IncludesLinear,Sequential,ReLU,Tanh,Sigmoid,LayerNorm,Embedding, and more. -
Rich data types with many operators
Supportsfloat16,float32,int8,uint8,int16,uint16,int32,uint32,int64,uint64, andboolean. -
Custom serialization format
Fast, portable model saving and loading through Magnetron’s own binary tensor format. -
Clean diagnostics
Readable validation and error messages for faster debugging and experimentation.
| Example | Description |
|---|---|
| GPT-2 Inference | Transformer-based text generation using pretrained GPT-2 weights. |
| Autoencoder | Image reconstruction using a small dense encoder–decoder network. |
| Linear Regression | Fits a linear model to noisy synthetic data. |
| XOR | Trains a small neural network to learn the XOR logical function. |
Make sure you are inside a Python virtual environment before installing.
With uv
uv pip install magnetronWith pip
pip install magnetronContributions are welcome!
Please open issues for ideas, or submit pull requests for new features.
PRs that only fix typos or minor formatting will not be accepted.
(c) 2025 Mario Sieg - mario.sieg.64@gmail.com
Distributed under the Apache 2 License.
See LICENSE for more information.