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 C and modern Python.
Designed for speed, clarity, and portability - from desktop to embedded.

Documentation »

Qwen3 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 bfloat16, 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
Qwen3 Inference Transformer-based text generation using pretrained Qwen3 weights, loaded from custom .mag file.
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) 2026 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.5.tar.gz (7.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.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

magnetron-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

magnetron-0.1.5-cp313-cp313-macosx_11_0_arm64.whl (877.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

magnetron-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

magnetron-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (877.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

magnetron-0.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

magnetron-0.1.5-cp311-cp311-macosx_11_0_arm64.whl (877.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

magnetron-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (7.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

magnetron-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (877.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for magnetron-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f3d90d2c8a31e865dad6352462c23819370510c5574c392c81b8bf18b2b763e1
MD5 848c13270c89798571a74a42ff6aa0a1
BLAKE2b-256 bb1d1f3504ca56065ecbc8349811a55f357edaa2b7e2811bf869df4b303f3bb3

See more details on using hashes here.

File details

Details for the file magnetron-0.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0a7891fd9e517a2790ffcf4f21b23027fd48010e03f4cafd6c9fda241ccb73f0
MD5 dc7e224e10fc387f0e12e99dff7db74e
BLAKE2b-256 36cae55294b1576327fd73142c8b5060a72214740e9b83fcf60ca346ed3ac87f

See more details on using hashes here.

File details

Details for the file magnetron-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c5a8352c4a748444053231c6ee60adf6081f8bd454f40f9fb8fd0d97d34b738a
MD5 4d9001e804b4fc2c49472b29d8eab7a1
BLAKE2b-256 5c433d69fce01b99c0edd0499c33256c67a44fac25cdf607caa497e3c625240b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magnetron-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66451093cb8320f91bee9f1f7ee4a6f2377ed51b8c3d960c1b560eeebe098f66
MD5 3017fa839d1f56ff50339c040a6c484f
BLAKE2b-256 1c577155d55c879f7b036a5bf7e07866b4f20802a810cd1399b3bd465d29affb

See more details on using hashes here.

File details

Details for the file magnetron-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8933e2daa8affabd4b9583bfb137a2a00134fcd5774b829ce386e013d338307b
MD5 736f0817e676f62092838368274ee4de
BLAKE2b-256 24190abbc25b3eefc688b5db8d587654cb1f70598407b21aa80f8015bb033873

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magnetron-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16eb5047affb283f097c4e669031ee189cc90b866a4114ea042338bc234dc8f8
MD5 ac4f44b397e1920a33aedb7c71427777
BLAKE2b-256 592fdec4f574535a84b5f90d64f48800ae00ee2633bc75f9c91b71720522d410

See more details on using hashes here.

File details

Details for the file magnetron-0.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8cf74f35d9ebac849da20a8ded1d6a810422e482bf9c93f0d99d678a70a109f2
MD5 db089280f800fb14a9c1a7d76ffea58b
BLAKE2b-256 809bdcd2714fc937adde483f3929578f352f609aec6a335c5e1b85852c67fde3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for magnetron-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 77cc7aa8ad98dbb57b253aca365ebc43a64f5bbe524927ae5de7447db7fddfba
MD5 165b5a01367786683878f7bb80dcb414
BLAKE2b-256 bab96331e7b3b762311beeff15a13fc46f67ef154e22cbba4b5a38a2a341370c

See more details on using hashes here.

File details

Details for the file magnetron-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 78ba8164108dac948e5e89e53cc98230c91dc8e45153ee7dd2ec8db8cb501eff
MD5 0002f1c592ed2e3f448a980c185e5a3f
BLAKE2b-256 9c5f9d03b32b1c33532965d83e365ba4826488a78fb6f273940d1c158a631f75

See more details on using hashes here.

File details

Details for the file magnetron-0.1.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for magnetron-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 de01c59f6c261fc15d34db25a696530eeaedff63f4834174287ba4a87add9df3
MD5 c105b2f53360915851a8df3d88c1c506
BLAKE2b-256 934d3dcc180e7fc484f97756bc5eda0f77de925cf205edcc1d5c5aaf38c903b2

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