{"id":15418930,"url":"https://github.com/vvmnnnkv/libtorchjs","last_synced_at":"2026-02-24T12:03:45.004Z","repository":{"id":105806121,"uuid":"164315631","full_name":"vvmnnnkv/libtorchjs","owner":"vvmnnnkv","description":"Node.js N-API wrapper for libtorch","archived":false,"fork":false,"pushed_at":"2020-03-22T22:04:58.000Z","size":35,"stargazers_count":18,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-17T03:33:36.732Z","etag":null,"topics":["libtorch","n-api","nodejs","pytorch"],"latest_commit_sha":null,"homepage":null,"language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vvmnnnkv.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":"2019-01-06T14:37:20.000Z","updated_at":"2023-11-21T13:09:42.000Z","dependencies_parsed_at":"2023-06-18T12:19:01.863Z","dependency_job_id":null,"html_url":"https://github.com/vvmnnnkv/libtorchjs","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/vvmnnnkv/libtorchjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvmnnnkv%2Flibtorchjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvmnnnkv%2Flibtorchjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvmnnnkv%2Flibtorchjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvmnnnkv%2Flibtorchjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vvmnnnkv","download_url":"https://codeload.github.com/vvmnnnkv/libtorchjs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvmnnnkv%2Flibtorchjs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29781237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T10:45:18.109Z","status":"ssl_error","status_checked_at":"2026-02-24T10:45:09.911Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["libtorch","n-api","nodejs","pytorch"],"created_at":"2024-10-01T17:23:21.825Z","updated_at":"2026-02-24T12:03:44.969Z","avatar_url":"https://github.com/vvmnnnkv.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LibtorchJS\n\nSimple [Node.js N-API module](https://nodejs.org/api/n-api.html) that wraps few pieces of pytorch C++ library ([libtorch](https://pytorch.org/cppdocs/)) to allow loading and running pytorch-trained models in Node.js.\n\nNode.js [non-blocking model](https://nodejs.org/en/docs/guides/dont-block-the-event-loop/) is great for scheduling heavy computational tasks such as NN inference.\nThis wrapper provides async methods that do not block event loop, so it's possible to use it in a web-service.\n\nThis module was made just for fun, to check if it's easily possible to create [image style transfer app with Node.js](https://github.com/vvmnnnkv/nodejs-style-transfer).\n\n## Installation\n\nWith npm: `npm i --save libtorchjs`\n\nModule binary is pre-built and published using `node-pre-gyp` so it's not required to download libtorch/pytorch \nor install build tools.\n\nCurrently, Linux \u0026 Windows builds are available.\n\n## Usage Example\n\n```javascript\nconst torch = require('libtorchjs');\n\nconst input = torch.randn([1, 3, 224, 224]);\ntorch.load('model.pt', function(err, model) {\n    model.forward(input, function(err, result) {\n        const output = result.toUint8Array();\n        console.log(output);\n    });\n});\n```\n\n## API\nThe overall goal is to mirror pytorch API where possible. Currently just a few methods are exposed.\n\n#### Tensor\n##### ones(Array shape)\nCreate tensor of specified shape filled with 1's (autograd is disabled) and return Tensor object.\n\n##### randn(Array shape)\nCreate tensor of specified shape (autograd is disabled) filled with random values in (0..1) range.\n\n#### ScriptModule\n##### load(String filename, callback)\nLoad traced model async from file and return resulting ScripModule. \n\n##### forward(Tensor tensor, callback)\nForward tensor async and return resulting Tensor.\n\n## Acknowledgments\nFollowing resources were extremely useful for creating this module:\n * Inspiration: https://www.udacity.com/facebook-pytorch-scholarship\n * Libtorch tutorial: https://pytorch.org/tutorials/advanced/cpp_export.html\n * Blog post about similar thing: http://blog.christianperone.com/2018/10/pytorch-1-0-tracing-jit-and-libtorch-c-api-to-integrate-pytorch-into-nodejs\n * N-API examples: https://github.com/nodejs/node-addon-examples\n * Pre-built module distribution: https://github.com/mapbox/node-pre-gyp\n\n## Possible Future\n * Expose more of libtorch\n * Promisify libtorchjs API\n * GPU support\n * ~~Windows~~ :heavy_check_mark:, Mac support\n * Use travis/appveyor for automatic builds\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvvmnnnkv%2Flibtorchjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvvmnnnkv%2Flibtorchjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvvmnnnkv%2Flibtorchjs/lists"}