Skip to main content

High-performance, lightweight deep-learning library with a PyTorch like API and GPU support.

Project description

Stargazers Forks Issues GitHub Actions Workflow Status


Magnetron Logo

magnetron

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


📖 About

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.


⚡ Highlights

  • 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
    Includes Linear, Sequential, ReLU, Tanh, Sigmoid, LayerNorm, Embedding, and more.

  • Rich data types with many operators
    Supports float16, float32, int8, uint8, int16, uint16, int32, uint32, int64, uint64, and boolean.

  • 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 Models

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.

📦 Installation

Make sure you are inside a Python virtual environment before installing.

With uv

uv pip install magnetron

With pip

pip install magnetron

🤝 Contributing

Contributions 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.

📜 License

(c) 2025 Mario Sieg - mario.sieg.64@gmail.com
Distributed under the Apache 2 License. See LICENSE for more information.

🧩 Similar Projects

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

magnetron-0.1.4.tar.gz (6.5 MB view details)

Uploaded Source

Built Distributions

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

magnetron-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

magnetron-0.1.4-cp313-cp313-macosx_11_0_arm64.whl (521.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

magnetron-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

magnetron-0.1.4-cp312-cp312-macosx_11_0_arm64.whl (521.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

magnetron-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

magnetron-0.1.4-cp311-cp311-macosx_11_0_arm64.whl (521.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file magnetron-0.1.4.tar.gz.

File metadata

  • Download URL: magnetron-0.1.4.tar.gz
  • Upload date:
  • Size: 6.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.12

File hashes

Hashes for magnetron-0.1.4.tar.gz
Algorithm Hash digest
SHA256 3e2b94c64f127b8e30ea28fa06396e0c04ce41019f7551602cdae6e2fdfbb0ed
MD5 0bd19a316e9641adaa8265bdd86f84d9
BLAKE2b-256 25e1a8771ce3dce9e1580c425eb9f7f34ab89a878b423b7b687070093d8d33bf

See more details on using hashes here.

File details

Details for the file magnetron-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8aa9e899ca13c2ef0bcf97fbb01aad42799c28e6d7a2d4a055141e2b702dec9b
MD5 7f89e17d610b8157e24ff1dfc3eddc31
BLAKE2b-256 ba607f1b3a1363e8e82441951dcb62fa8c37dfdb5b9ea78923393fde896e7bca

See more details on using hashes here.

File details

Details for the file magnetron-0.1.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd1e747dd176bb02aa3aeb56a3c7e20be08dc27bed995330e5e68ce9c2b7be3f
MD5 75a77d2cbfab747a8c144988c2d5cec1
BLAKE2b-256 231dafbc566a7bfbd39b8b696602111462021918dbf9320b7af4073bfec4b2b7

See more details on using hashes here.

File details

Details for the file magnetron-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 63e0dbc0b92fa308477cdb97a62de3b2f45891130bdfcd971f3fbca496fe3056
MD5 4d52b5b01e3c00eb626b6f5935364955
BLAKE2b-256 478f3e879580fef673930636945b1e71882697b59dc399ddc122d1a953a896e0

See more details on using hashes here.

File details

Details for the file magnetron-0.1.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f44a774c2f44215c7b546c0e3cbcd56abe8378a6358bdda600204daa96fae68
MD5 f4d85370af3f2d0a21126d3fbbf2a75c
BLAKE2b-256 7ef322f6d085ff914d8ddf304ebd3cbf0036fad3111fa643e8b103e98f07223d

See more details on using hashes here.

File details

Details for the file magnetron-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06344b782d01032e81a2ab2dc115151ba07dc2ec86bda183a776adb5424c987f
MD5 76ce38e5e36117fe52ad8be128fa9d10
BLAKE2b-256 0f2292dc48afaa72d748f350daf4006a85a0c2b02b85b83993ec8ab4b1625c94

See more details on using hashes here.

File details

Details for the file magnetron-0.1.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5c476361cf61ebd83ec48bb7b848d41f24e0c13d7abb1e6a97a822313b40873
MD5 d838912877606c65e52d8f9a8af36295
BLAKE2b-256 971dd686e58e9ec769fd76086710a6c87232daf69eab95f3934e5625c47db025

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