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.3.tar.gz (6.6 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.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

magnetron-0.1.3-cp313-cp313-macosx_11_0_arm64.whl (496.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

magnetron-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

magnetron-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (496.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

magnetron-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

magnetron-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (496.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: magnetron-0.1.3.tar.gz
  • Upload date:
  • Size: 6.6 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.3.tar.gz
Algorithm Hash digest
SHA256 2d6928ccafd1b68c9e4e8ff63d9b337ad5909e02f2b135b8595702b0a62f7883
MD5 2f3b916b450f7170652d86217a950de4
BLAKE2b-256 0b2f52a233ac0454867d852b92dd299fc36de27aaaa6c1285cce203e8ab7b22d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magnetron-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e50b1e506778a0d4334c6f6064e13f1e5b6fe8cc0dca57784cba178632f7f1c2
MD5 bbe452426b0126f983b27e5ee849b369
BLAKE2b-256 895b356acc261cdec365d99135d4288dfee90356d9154cd922e6764342b88890

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magnetron-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 114b45e9100dd41e7ba65b8a321e832970093b6b350717db0df0c35c4e3492c5
MD5 f558c276b3e574c2fa8431906ac039b4
BLAKE2b-256 7987aa5057a7c2683e586f352d6e5ba31ae56e79c7a6129459e04837c43fe44d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magnetron-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 adb451a784abafa6bd2f2aad4046b44de4363dd4445fc07b685c7d11be6d5ef8
MD5 eb359d13fbe300a3e6739eedf43f27c6
BLAKE2b-256 614dc200aff2d7e54c9355a6d99eeea68f31e0d4283b8715ec35f1f3fea117e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magnetron-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8e6b06e92feed1f2028a133ae200fe6f51b916a0288471a78e56365e8a055f7
MD5 861d29e1773cb77fc3665d84e9976cda
BLAKE2b-256 a45e5d2247f511b05d93581d908537827851f1ab06e87a2aa53394555fbd16bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magnetron-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b4351f706522f4586207eaa23d10442aa6df35c248553a4291b7b435197a9d4
MD5 17622e8adc59c6f6783188897e86248b
BLAKE2b-256 0c3acc8948466793ed3b2496c07cc8d59d98b870747e3872ce1d2ba1f2af52ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magnetron-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2568fe7fe3ed5ce63264cf5f3d2fa6ddc159b9bf38fe962b394ee75bdab0801a
MD5 4a9bfaab0eb32fa6acdc8a314f5817c8
BLAKE2b-256 76e2cc454953582e0ba2fedd197f631c8c2d673eebe90942f12ea0b711808cb0

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