Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kitajussus/zig-torch
implementation of zig api in pytorch to make it faster, for fun lets see what is going to happen
https://github.com/kitajussus/zig-torch
i love python pytorch pytorch-implementation zig
Last synced: 2 days ago
JSON representation
implementation of zig api in pytorch to make it faster, for fun lets see what is going to happen
- Host: GitHub
- URL: https://github.com/kitajussus/zig-torch
- Owner: kitajusSus
- License: mit
- Created: 2025-01-04T21:14:45.000Z (18 days ago)
- Default Branch: main
- Last Pushed: 2025-01-19T17:10:01.000Z (3 days ago)
- Last Synced: 2025-01-19T18:23:24.667Z (3 days ago)
- Topics: i, love, python, pytorch, pytorch-implementation, zig
- Language: Zig
- Homepage:
- Size: 19.4 MB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# important 7.01.2025
sorry guys for the confusion i could make with my reddit post about this repository. It has right now a lot of mistakes and now I am trying to fix this.# zig-pytorch
As a man who is trying to understand zig and write usefull code in other language than python (or try to write something usefull), I get an idea of creating something what is using zig to optize pytorch, make is faster, more reliable. I don't know if it's going to work, but I need to do it my own as a motivation do study.
# I've seen this in my dream
# 0. Basic know-how
PyTorch is written in C++ and gives API in this language, BUT ZIG GIVES US built in tools to compile code in C/C++. I can define functions from C++ in zig and use it in my code. [000_example.zig](mm.zig). As you see, something works, and the plan is rewrite/build from scrach pytorch functions in zig and do something with it.
## What do I need
- Write pytorch functions in zig.
- Write cpp api extension with obv declaration `extern "C" .. ` my Zig functions.
- Build real extension to pytorch with `torch.utilis.cpp_extension`. Create `.o` file.
- Check it everything work on python# 1. Creating basic functions from pytorch
## `torch.mm(input, mat2) -> Tensor`
This function takes two tensors 2d (matrix).# 00. notes
zig build command
` zig build-obj -OReleaseFast -fPIC mm.zig`
`zig build-obj -fcompiler-rt mm.zig -fPIC -lpthread`
important to create module
`pip install -e .` // `python setup.py install`but there is a progres:
```bash
(base)
Generowanie macierzy...Liczenie z zigtorch:
Starting multiplication: 10x10 * 10x10
Spawning thread 0: 0-5
thread 43064 panic: reached unreachable code
aborting due to recursive panic
fish: Job 1, 'python testmm.py' terminated by signal SIGABRT (Abort)
```
![image](https://github.com/user-attachments/assets/c5803144-53ac-427b-bf94-8dd3bcd84fe9)my 6 core procesor is crying
![image](https://github.com/user-attachments/assets/e1fd7747-1a49-495b-aa31-a92af5dc1ee6)# Updated Progress 8.01.2025
The issues mentioned above have been fixed. The current implementation is still not faster than PyTorch, but significant improvements have been made. The `mm.zig` file has been optimized, and the multithreading issues have been resolved. The setup process has been streamlined, and the performance comparison with PyTorch is now more accurate.# Next Steps
- Continue optimizing the `mm.zig` file to further improve performance.
- Explore additional techniques for optimizing matrix multiplication.
- Keep the community updated on progress and share any new findings.