{"id":24198983,"url":"https://github.com/mariosieg/magnetron","last_synced_at":"2025-04-08T12:03:11.002Z","repository":{"id":270863842,"uuid":"911371111","full_name":"MarioSieg/magnetron","owner":"MarioSieg","description":"(WIP) A small but powerful, homemade PyTorch from scratch.","archived":false,"fork":false,"pushed_at":"2025-04-08T09:25:35.000Z","size":26662,"stargazers_count":544,"open_issues_count":0,"forks_count":24,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-08T12:02:24.505Z","etag":null,"topics":["artificial-intelligence","cpp","cuda","high-performance-computing","machine-learning","neuronal-network","python","pytorch","research-project","tensorflow","tiny"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarioSieg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"MarioSieg"}},"created_at":"2025-01-02T21:25:56.000Z","updated_at":"2025-04-08T11:27:58.000Z","dependencies_parsed_at":"2025-01-18T17:20:40.152Z","dependency_job_id":"fed0b5de-6b3c-4351-af5e-7da011c832ae","html_url":"https://github.com/MarioSieg/magnetron","commit_stats":null,"previous_names":["mariosieg/magnetron"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarioSieg%2Fmagnetron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarioSieg%2Fmagnetron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarioSieg%2Fmagnetron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarioSieg%2Fmagnetron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarioSieg","download_url":"https://codeload.github.com/MarioSieg/magnetron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247838441,"owners_count":21004580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","cpp","cuda","high-performance-computing","machine-learning","neuronal-network","python","pytorch","research-project","tensorflow","tiny"],"created_at":"2025-01-13T20:19:35.425Z","updated_at":"2025-04-08T12:03:10.981Z","avatar_url":"https://github.com/MarioSieg.png","language":"C++","funding_links":["https://github.com/sponsors/MarioSieg"],"categories":[],"sub_categories":[],"readme":"[![Contributors][contributors-shield]][contributors-url]\n[![Forks][forks-shield]][forks-url]\n[![Stargazers][stars-shield]][stars-url]\n[![Issues][issues-shield]][issues-url]\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/MarioSieg/magnetron/cmake-multi-platform.yml?style=for-the-badge)\n\n\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/MarioSieg/magnetron\"\u003e\n    \u003cimg src=\"media/magnetron-logo.svg\" alt=\"Logo\" width=\"200\" height=\"200\"\u003e\n  \u003c/a\u003e\n\n\u003ch3 align=\"center\"\u003emagnetron\u003c/h3\u003e\n  \u003cp align=\"center\"\u003e\n    Minimalistic homemade PyTorch alternative, written in C99 and Python.\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/MarioSieg/magnetron/tree/master/python/examples/simple\"\u003e\u003cstrong\u003eExplore the docs »\u003c/strong\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/MarioSieg/magnetron/blob/master/python/examples/simple/xor.py\"\u003eView Demo\u003c/a\u003e\n    |\n    \u003ca href=\"https://github.com/MarioSieg/magnetron/issues/new?labels=bug\u0026template=bug-report---.md\"\u003eReport Bug\u003c/a\u003e\n    |\n    \u003ca href=\"https://github.com/MarioSieg/magnetron/issues/new?labels=enhancement\u0026template=feature-request---.md\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eTable of Contents\u003c/summary\u003e\n  \u003col\u003e\n    \u003cli\u003e\n      \u003ca href=\"#about-the-project\"\u003eAbout The Project\u003c/a\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\n      \u003ca href=\"#getting-started\"\u003eGetting Started\u003c/a\u003e\n      \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#prerequisites\"\u003ePrerequisites\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#roadmap\"\u003eRoadmap\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#contributing\"\u003eContributing\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\u003c/li\u003e\n  \u003c/ol\u003e\n\u003c/details\u003e\n\n## News\n- **[2025/01/14]** 🎉 CPU backend now uses multiple threads with dynamic scaling and thread pooling.\n- **[2025/01/02]** 🎈 Magnetron released on GitHub.\n\n## About\n\n![ScreenShot](media/xor.png)\nThis project started as a learning experience and a way to understand the inner workings of PyTorch and other deep learning frameworks.\u003cbr\u003e\nThe goal is to create a minimalistic but still powerful deep learning framework that can be used for research and production.\u003cbr\u003e\nThe framework is written in C99 and Python and is designed to be easy to understand and modify.\u003cbr\u003e\n\n### Work in Progress\n* The project is still in its early stages and many features are missing.\n* Developed by a single person in their free time.\n* The project is not yet fully optimized for performance.\n\n## Getting Started\n\nTo get a local copy up and running follow these simple steps.\u003cbr\u003e\nMagnetron itself has **no** Python dependencies except for CFFI to call the C library from Python.\u003cbr\u003e\nSome examples use matplotlib and numpy for plotting and data generation, but these are not required to use the framework.\n\n### Prerequisites\n* Linux, MacOS or Windows\n* A C99 compiler (gcc, clang, msvc)\n* Python 3.6 or higher\n\n### Installation\n*A pip installable package will be provided, as soon as all core features are implemented.*\n1. Clone the repo\n2. `cd magnetron/python` (VENV recommended).\n3. `pip install -r requirements.txt` Install dependencies for examples.\n4. `cd magnetron_framework \u0026\u0026 bash install_wheel_local.sh \u0026\u0026 cd ../` Install the Magnetron wheel locally, a pip installable package will be provided in the future.\n5. `python examples/simple/xor.py` Run the XOR example.\n\n## Usage\nSee the [Examples](python/examples) directory for examples on how to use the framework.\nFor usage in C and C++ see the [Unit Tests](test) directory in the root of the project.\n\n## Features\n* 6 Dimensional, linearized tensors\n* Automatic Differentiation\n* Multithreaded CPU Compute, SIMD optimized operators (SSE4, AVX2, AVX512, ARM NEON)\n* Modern Python API (similar to PyTorch)\n* Many operators with broadcasting support and in-place variants\n* High level neural network building blocks\n* Dynamic computation graph (eager evaluation)\n* Modern PRNGs: Mersenne Twister and PCG\n* Validation and friendly error messages\n* Custom compressed tensor file formats\n\n### Example\nCode from the XOR example:\n```python\ndef forward(self, x: Tensor) -\u003e Tensor:\n    return (self.weight @ x + self.bias).sigmoid()\n```\n\n### Operators\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eOperation\u003c/th\u003e\n      \u003cth\u003e\u003cdiv align=\"center\"\u003eDescription\u003c/div\u003e\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eclone(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eCreates a copy of the tensor\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eview(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eReshapes without changing data\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003etranspose(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eSwaps tensor dimensions\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003epermute(x, d0, ...)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eReorders tensor dimensions\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003emean(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eMean across dimensions\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003emin(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eMinimum value of tensor\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003emax(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eMaximum value of tensor\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003esum(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eSum of elements\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eabs(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise absolute value\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eneg(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise negation\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003elog(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise natural logarithm\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003esqr(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise square\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003esqrt(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise square root\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003esin(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise sine\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ecos(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise cosine\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003esoftmax(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eSoftmax along dimension\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003esigmoid(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise sigmoid\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003erelu(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eReLU activation\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003egelu(x)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eGELU activation\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eadd(x, y)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise addition\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003esub(x, y)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise subtraction\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003emul(x, y)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise multiplication\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ediv(x, y)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eElement-wise division\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ematmul(A, B)\u003c/td\u003e\n      \u003ctd\u003e\u003cdiv align=\"center\"\u003eMatrix multiplication\u003c/div\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n## Roadmap\n\nThe goal is to implement training and inference for LLMs and other state of the art models, while providing a simple and small codebase that is easy to understand and modify.\n\n- [ ] Compute on GPU (Cuda)\n- [ ] Low-precision datatypes (f16, bf16, int8)\n- [ ] Distributed Training and Inference\n- [ ] CPU and GPU kernel JIT compilation\n- [ ] Better examples with real world models (LLMs and state of the art models)\n\n## Contributing\nContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.\nIf you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag \"enhancement\".\n\n## License\nDistributed under the Apache 2 License. See `LICENSE.txt` for more information.\n\n## Similar Projects\n\n* [GGML](https://github.com/ggerganov/ggml)\n* [TINYGRAD](https://github.com/tinygrad/tinygrad)\n* [MICROGRAD](https://github.com/karpathy/micrograd)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n[contributors-shield]: https://img.shields.io/github/contributors/MarioSieg/magnetron.svg?style=for-the-badge\n[contributors-url]: https://github.com/MarioSieg/magnetron/graphs/contributors\n[forks-shield]: https://img.shields.io/github/forks/MarioSieg/magnetron.svg?style=for-the-badge\n[forks-url]: https://github.com/MarioSieg/magnetron/network/members\n[stars-shield]: https://img.shields.io/github/stars/MarioSieg/magnetron.svg?style=for-the-badge\n[stars-url]: https://github.com/MarioSieg/magnetron/stargazers\n[issues-shield]: https://img.shields.io/github/issues/MarioSieg/magnetron.svg?style=for-the-badge\n[issues-url]: https://github.com/MarioSieg/magnetron/issues\n[license-shield]: https://img.shields.io/github/license/MarioSieg/magnetron.svg?style=for-the-badge\n[license-url]: https://github.com/MarioSieg/magnetron/blob/master/LICENSE.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariosieg%2Fmagnetron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmariosieg%2Fmagnetron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmariosieg%2Fmagnetron/lists"}