{"id":24448487,"url":"https://github.com/kitajussus/zig-torch","last_synced_at":"2025-10-01T14:30:39.050Z","repository":{"id":271029501,"uuid":"912187778","full_name":"kitajusSus/zig-torch","owner":"kitajusSus","description":"implementation of zig api in pytorch to make it faster, for fun lets see what is going to happen","archived":false,"fork":false,"pushed_at":"2025-01-19T17:10:01.000Z","size":20327,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T18:23:24.667Z","etag":null,"topics":["i","love","python","pytorch","pytorch-implementation","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kitajusSus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2025-01-04T21:14:45.000Z","updated_at":"2025-01-17T03:51:13.000Z","dependencies_parsed_at":"2025-01-04T23:17:22.754Z","dependency_job_id":"e84d18cc-ec49-4f4f-bccb-93ae59ad3d97","html_url":"https://github.com/kitajusSus/zig-torch","commit_stats":null,"previous_names":["kitajussus/zig-torch"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitajusSus%2Fzig-torch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitajusSus%2Fzig-torch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitajusSus%2Fzig-torch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kitajusSus%2Fzig-torch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kitajusSus","download_url":"https://codeload.github.com/kitajusSus/zig-torch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234875543,"owners_count":18900158,"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":["i","love","python","pytorch","pytorch-implementation","zig"],"created_at":"2025-01-21T00:22:22.157Z","updated_at":"2025-10-01T14:30:39.040Z","avatar_url":"https://github.com/kitajusSus.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# important 27.02.2025\nIve changed few things, now I preffere to do firstyly something in zig and later on I will look for options to make bindings to python. \n\nmm.zig is main file with matrix multiplication function. the main problem is that i dont know how to build this, to make it work as a independent library in python, I lost an idea to make \"faster pytorch\", now im focused to something that can be used with or without pytorch. \n\n\n# zig-pytorch\nAs 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. \n# I've seen this in my dream\n# 0. Basic know-how\nPyTorch 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. \n## What do I need\n- Write pytorch functions in zig.\n- Check it everything work on python \n\n# 1. Creating basic functions from pytorch\n## `torch.mm(input, mat2) -\u003e Tensor`\nThis function takes two tensors 2d (matrix).\n\n\n\n\n\n\n\n\n\n## Development Workflow\n\n1. **Plan**: Define the functionality you want to implement\n2. **Test-Driven Development**: Write tests in Zig first\n3. **Implement**: Create the Zig implementation\n4. **Benchmark**: Compare performance with PyTorch\n5. **C API**: Expose functionality through C API\n6. **Python Bindings**: Create Python wrappers\n7. **Document**: Update documentation\n\n## Building the Project\n\n### Building the Zig Library\n\n```bash\n# Build the Zig library\nzig build\n\n# Run Zig tests\nzig build test\n\n# Build in release mode for better performance\nzig build -Drelease-fast\n```\n# 00. notes\n\n**zig build command**\n- ` zig build-obj -OReleaseFast -fPIC mm.zig`\n- `zig build-obj -fcompiler-rt mm.zig -fPIC  -lpthread`\n\n**important to create module**\n- `pip install -e .` // `python setup.py install`\n\n\n**Building the Python Package**\n```bash\n# Install in development mode\npip install -e .\n\n# Build and install\npython setup.py install\n```\n\n\n# Adding New functions\n\n\nex: Creating a New Operation\n\n- create a new file in src/ (e.g., src/add.zig)  [example add.zig](src/add.zig)\n- Implement your function\n- Create a test file in tests/ (e.g., tests/testadd.zig)\n- Update build.zig to include your new files\n- Expose through C API in src/native.zig\n\n```bash\n# Basic build\nzig build\n\n# Build with optimization for release\nzig build -Drelease-fast\n\n# Run tests\nzig build test\n\n# Clean build artifacts\nrm -rf zig-out/\n```\n\n\n\n\n## Testing 19.05.2025\nZIG 0.15.Development\n```bash\nŁadowanie biblioteki z: /home/kitajussus/github/zig-torch/src/libmm.so\nCreating Matrix A (50x50) and B (50x50) type float32...\n\n ZIG MULTIPLYING : !!!!!!!!!!!!!!!!!\nMultiply with zig (50x50) x (50x50) took : 0.713 ms\n\n Multiply with Numpy (for comparison):\nTime for numpy: 2.430 ms\n\nChecking...\nZIG IS NOT MULTYPLYING ONLY ZEROES!!!! IT IS WORKING\n\n Zig matrix  ( first 5x5 OR LESS):\n[[13.51593   10.569702  13.364006  12.218889   9.840366 ]\n [12.826249   9.629739  14.659329  10.829753  10.374571 ]\n [13.49235   10.976502  14.516691  12.262626  11.237597 ]\n [11.469961   9.874568  11.2643795 10.609412  10.377689 ]\n [12.426827  10.05384   12.000959  11.205995   9.461213 ]]\nNumpy Matrix ( first 5x5 OR LESS):\n[[13.51593   10.569702  13.364005  12.218888   9.840365 ]\n [12.826249   9.629739  14.659329  10.829753  10.374571 ]\n [13.49235   10.976501  14.516692  12.262625  11.2375965]\n [11.469961   9.874568  11.2643795 10.609412  10.377689 ]\n [12.426826  10.053841  12.000959  11.205995   9.461213 ]]\n\nTest FFI zakończony.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkitajussus%2Fzig-torch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkitajussus%2Fzig-torch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkitajussus%2Fzig-torch/lists"}