{"id":13477557,"url":"https://github.com/sinkingsugar/nimtorch","last_synced_at":"2025-08-13T19:07:45.396Z","repository":{"id":42517543,"uuid":"142994387","full_name":"sinkingsugar/nimtorch","owner":"sinkingsugar","description":"PyTorch - Python + Nim","archived":false,"fork":false,"pushed_at":"2019-06-08T14:44:48.000Z","size":2131,"stargazers_count":466,"open_issues_count":10,"forks_count":20,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-07-27T19:17:01.815Z","etag":null,"topics":["artificial-intelligence","artificial-neural-networks","cuda","machine-learning","nim","pytorch","wasm"],"latest_commit_sha":null,"homepage":"","language":"Nim","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/sinkingsugar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-31T09:43:26.000Z","updated_at":"2025-05-31T12:15:46.000Z","dependencies_parsed_at":"2022-08-22T20:00:55.124Z","dependency_job_id":null,"html_url":"https://github.com/sinkingsugar/nimtorch","commit_stats":null,"previous_names":["fragcolor-xyz/nimtorch"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/sinkingsugar/nimtorch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinkingsugar%2Fnimtorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinkingsugar%2Fnimtorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinkingsugar%2Fnimtorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinkingsugar%2Fnimtorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinkingsugar","download_url":"https://codeload.github.com/sinkingsugar/nimtorch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinkingsugar%2Fnimtorch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268500608,"owners_count":24260163,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","artificial-neural-networks","cuda","machine-learning","nim","pytorch","wasm"],"created_at":"2024-07-31T16:01:44.445Z","updated_at":"2025-08-13T19:07:45.338Z","avatar_url":"https://github.com/sinkingsugar.png","language":"Nim","funding_links":[],"categories":["Nim","Algorithms"],"sub_categories":["Deep Learning"],"readme":"![NimTorch](media/NimTorchBanner.png)\n\n| Master | Release |\n|-------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------\n| [![Build Status](https://travis-ci.com/fragcolor-xyz/nimtorch.svg?branch=master)  ](https://travis-ci.com/fragcolor-xyz/nimtorch  ) | [![Build Status](https://travis-ci.com/fragcolor-xyz/nimtorch.svg?branch=release)  ](https://travis-ci.com/fragcolor-xyz/nimtorch  )\n\n\nPytorch - Py + Nim\n\nA Nim frontend for pytorch, aiming to be mostly auto-generated and internally using ATen.\n\n**Because Nim compiles to C++, this is not a wrapper or binding library. It generates 1-to-1 native ATen code.**\n\nThe only requirement from pytorch is ATen's core tensor library. Because of this, nimtorch is extremely versatile and can compile on any kind of device.\n\n## Current status\n\n**Early stage**\n\n- [x] Automatically generated, from `Declarations.yaml`, the full ATen API\n- [x] Cuda support ( add -d:cuda when compiling with nim )\n- [x] WASM support ( add -d:wasm when compiling with nim )\n- [x] Automatically generated, from `derivatives.yaml`, gradient procs\n- [x] Autograd\n- [ ] Add missing derivatives\n- [ ] More high level pytorch API (Module, Models etc)\n- [ ] ...\n\nThe final aim is to be as compatible as possible with the pytorch API.\n\n## Why\n\nEase of use of the python language while keeping fully bare metal native C++ performance\n\n### Python code\n\n```python\n# GRUCell\ngi = x.matmul(w_input.t()) + b_input\ngh = hidden.matmul(w_recur.t()) + b_recur\ni_r, i_i, i_n = gi.chunk(3, 1)\nh_r, h_i, h_n = gh.chunk(3, 1)\nresetgate = (i_r + h_r).sigmoid()\ninputgate = torch.sigmoid(i_i + h_i)\nnewgate = (i_n + resetgate * h_n).tanh()\nhy = newgate + inputgate * (hidden - newgate)\n```\n\n### Nim code\n\n```nimrod\n# GRUCell\nlet\n  gi = x.matmul(w_input.t()) + b_input\n  gh = hidden.matmul(w_recur.t()) + b_recur\n  (i_r, i_i, i_nn) = gi.chunk(3, 1)\n  (h_r, h_i, h_n)  = gh.chunk(3, 1)\n  resetgate = (i_r + h_r).sigmoid()\n  inputgate = torch.sigmoid(i_i + h_i)\n  newgate = (i_nn + resetgate * h_n).tanh()\n  hy = newgate + inputgate * (hidden - newgate)\n```\n\n## Getting started\n\n### Requirements\n\n**Linux**: A recent distribution on par with ubuntu 18.04 in terms of libc and basic libraries, gcc compiler\n\n**macOS**: We compile with 10.13 min version flags but might work even on lower versions, XCode for the compilers\n\n**Windows**: Windows 10, Visual Studio Runtime 2017 and Visual Studio 2017 (any edition)\n\n**WASM**: Latest Emscripten compiler and tools\n\n### Super easy, using conda\n\n*Linux, macOS and Windows*\n\n`conda create -n nimtorch -c fragcolor nimtorch` (add `cuda10.0` for cuda 10 linux only or add `wasm` for wasm version)\n\n`source activate nimtorch` or on windows: `conda activate nimtorch`\n\nThis will install: nim and ATen binaries, fragments and nimtorch all in one command, nothing else needed.\n\nMake sure you use a recent version of conda and have a compiler installed in your system, on windows you have to add `--cc:vcc` and be on a developer prompt.\n\nMake sure your system is recent (ubuntu 18.04 reference / macOS High Sierra / Windows 10) and you have cuda 9.2 installed (if you need cuda, linux only, more cuda versions coming, please open a issue if you need a specific version).\n\nTest with with something like:\n\n`nim cpp -o:test -r $ATEN/dist/pkgs/nimtorch-\\#head/tests/test_xor.nim`\n\nor on windows... (because dlls need to be side by side)\n\n`nim cpp -o:%ATEN%/lib/test.exe -r %ATEN%/dist/pkgs/nimtorch-#head/tests/test_xor.nim`\n\n### Semi manual way\n\n*Linux, macOS and Windows*\n\nCheck what version of ATen/PyTorch we need in `conda/nimtorch/meta.yaml` - should be something like `aten ==2018.10.10.1089`\n\nNote the version as you will need it in the next step\n\n`conda create -n aten -c fragcolor aten={version}`\n\nor\n\n**WASM**\n\n`conda create -n aten -c fragcolor aten={version} wasm`\n\nor Cuda 10.0 (linux only)\n\n`conda create -n aten -c fragcolor aten={version} cuda10.0`\n\nactivate aten environment\n\n`source activate aten` or on windows: `conda activate aten`\n\n1. Make sure you have a recent Nim and Nimble version in your path\n  * [Easy option: install nim with choosenim](https://github.com/dom96/choosenim)\n    * `choosenim devel`\n2. clone the **release** branch `git clone -b release https://github.com/fragcolor-xyz/nimtorch.git`\n3. `cd nimtorch`\n4. `nimble develop`\n\n*finally*\n\nrun self test `nim cpp -o:test -r torch.nim` (use `-o:%ATEN%/lib/test.exe` instead on windows because of dll location)\n\nin the case of WASM:\n\nrun self test `nim cpp -d:wasm -o:test.js torch.nim \u0026\u0026 node test.js` (needs node.js)\n\n### Manual way without requiring conda\n**Build ATEN**\n```sh\npip2 install pyyaml typing\ngit clone -b fragcolor-devel https://github.com/fragcolor-xyz/pytorch.git\ncd pytorch\ngit reset --hard \u003ccommit hash\u003e # from torch/commit.txt\ngit submodule update --init\nmkdir build \u0026\u0026 cd build\ncmake -DCMAKE_BUILD_TYPE=Release -DUSE_CUDA=OFF -DBUILD_ATEN_ONLY=ON -DCMAKE_INSTALL_PREFIX=`pwd`/output ../\nmake -j4\nmake install\n\n# also copy derivatives if we want to run generator.nim or nimble test\n# notice generator.nim might need python3 and pyyaml\ncp ../tools/autograd/derivatives.yaml `pwd`/output/share/\n```\n\n**Test the build**\n```\ncd \u003cnimtorch repo\u003e\nATEN=\u003cinstallation path of ATEN\u003e nim cpp -r -f -o:/tmp/z01 torch.nim # for eg: ATEN=pathto/pytorch/build/output/\n```\n\n## Notes\n\n* We suggest setting `OMP_WAIT_POLICY` environment variable to `PASSIVE` when running on CPU.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinkingsugar%2Fnimtorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinkingsugar%2Fnimtorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinkingsugar%2Fnimtorch/lists"}