{"id":38065996,"url":"https://github.com/sugarme/gotch","last_synced_at":"2026-01-16T20:34:52.042Z","repository":{"id":40896178,"uuid":"266115238","full_name":"sugarme/gotch","owner":"sugarme","description":"Go binding for Pytorch C++ API (libtorch)","archived":false,"fork":false,"pushed_at":"2024-01-25T04:10:09.000Z","size":116771,"stargazers_count":524,"open_issues_count":12,"forks_count":43,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-06-18T15:20:58.918Z","etag":null,"topics":["deep-learning","framework","go","go-binding","golang","pytorch","pytorch-go-binding"],"latest_commit_sha":null,"homepage":"","language":"Go","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/sugarme.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-05-22T13:18:41.000Z","updated_at":"2024-06-10T15:59:45.000Z","dependencies_parsed_at":"2024-01-25T05:35:52.052Z","dependency_job_id":null,"html_url":"https://github.com/sugarme/gotch","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"purl":"pkg:github/sugarme/gotch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugarme%2Fgotch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugarme%2Fgotch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugarme%2Fgotch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugarme%2Fgotch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sugarme","download_url":"https://codeload.github.com/sugarme/gotch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sugarme%2Fgotch/sbom","scorecard":{"id":857503,"data":{"date":"2025-08-11","repo":{"name":"github.com/sugarme/gotch","commit":"db661550e5a88582a40830e54bb1777e6afd32e7"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":2,"reason":"Found 3/15 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v0.9.0 not signed: https://api.github.com/repos/sugarme/gotch/releases/124541801","Warn: release artifact v0.8.0 not signed: https://api.github.com/repos/sugarme/gotch/releases/124529439","Warn: release artifact v0.7.0 not signed: https://api.github.com/repos/sugarme/gotch/releases/62637473","Warn: release artifact v0.9.0 does not have provenance: https://api.github.com/repos/sugarme/gotch/releases/124541801","Warn: release artifact v0.8.0 does not have provenance: https://api.github.com/repos/sugarme/gotch/releases/124529439","Warn: release artifact v0.7.0 does not have provenance: https://api.github.com/repos/sugarme/gotch/releases/62637473"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 22 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":7,"reason":"3 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2023-1990 / GHSA-j3p8-6mrq-6g7h","Warn: Project is vulnerable to: GO-2023-1989 / GHSA-x92r-3vfx-4cv3","Warn: Project is vulnerable to: GO-2024-2937 / GHSA-9phm-fm57-rhg8"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Pinned-Dependencies","score":10,"reason":"all dependencies are pinned","details":["Info:   1 out of   1 goCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}}]},"last_synced_at":"2025-08-24T00:16:43.524Z","repository_id":40896178,"created_at":"2025-08-24T00:16:43.524Z","updated_at":"2025-08-24T00:16:43.524Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28482267,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: 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":["deep-learning","framework","go","go-binding","golang","pytorch","pytorch-go-binding"],"created_at":"2026-01-16T20:34:51.461Z","updated_at":"2026-01-16T20:34:52.028Z","avatar_url":"https://github.com/sugarme.png","language":"Go","readme":"# Gotch [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0)[![Go.Dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/sugarme/gotch?tab=doc) \n\n\n## Overview\n\n`gotch` creates a thin wrapper to Pytorch C++ APIs (Libtorch) to make use of its already optimized C++ tensor APIs (3039) and dynamic graph computation with CUDA support and provides idiomatic Go APIs for developing and implementing Deep Learning in Go.\n\n**Some features are**\n- [x] Comprehensive Pytorch tensor APIs (2525)\n- [x] Fully featured Pytorch dynamic graph computation\n- [x] JIT interface to run model trained/saved using PyTorch Python API\n- [x] Load pretrained Pytorch models and run inference\n- [x] Pure Go APIs to build and train neural network models with both CPU and GPU support\n- [x] Most recent image models\n- [ ] NLP Language models - [Transformer](https://github.com/sugarme/transformer) in separate package built with **gotch** and [pure Go Tokenizer](https://github.com/sugarme/tokenizer).\n\n`gotch` is in active development mode and may have API breaking changes. Feel free to pull request, report issues or discuss any concerns. All contributions are welcome. \n\n`gotch` current version is **v0.9.1**\n\n## Dependencies\n\n- **Libtorch** C++ v2.1.0 library of [Pytorch](https://pytorch.org/)\n- Clang-17/Clang++-17 compilers\n\n## Installation\n\n- Default CUDA version is `11.8` if CUDA is available otherwise using CPU version.\n- Default Pytorch C++ API version is `2.1.0`\n\n**NOTE**: `libtorch` will be installed at **`/usr/local/lib`**\n\n### CPU\n\n#### Step 1: Setup libtorch (skip this step if a valid libtorch already installed in your machine!)\n\n```bash\n    wget https://github.com/sugarme/gotch/releases/download/v0.9.0/setup-libtorch.sh\n    chmod +x setup-libtorch.sh\n    export CUDA_VER=cpu \u0026\u0026 bash setup-libtorch.sh\n```\n\n**Update Environment**: in Debian/Ubuntu, add/update the following lines to `.bashrc` file\n\n```bash\n    export GOTCH_LIBTORCH=\"/usr/local/lib/libtorch\"\n    export LIBRARY_PATH=\"$LIBRARY_PATH:$GOTCH_LIBTORCH/lib\"\n    export CPATH=\"$CPATH:$GOTCH_LIBTORCH/lib:$GOTCH_LIBTORCH/include:$GOTCH_LIBTORCH/include/torch/csrc/api/include\"\n    export LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH:$GOTCH_LIBTORCH/lib\"\n```\n\n#### Step 2: Setup gotch\n\n```bash\n    wget https://github.com/sugarme/gotch/releases/download/v0.9.0/setup-gotch.sh\n    chmod +x setup-gotch.sh\n    export CUDA_VER=cpu \u0026\u0026 export GOTCH_VER=v0.9.1 \u0026\u0026 bash setup-gotch.sh\n```\n\n### GPU\n\n**NOTE**: make sure your machine has working CUDA. \n- Check version: `nvidia-smi`\n- [Install nvidia driver here](https://www.nvidia.com/Download/Find.aspx?lang=en)\n- [Install CUDA here](https://developer.nvidia.com/cuda-downloads)\n- [Install CuDNN here](https://developer.nvidia.com/rdp/cudnn-download#)\n\n#### Step 1: Setup libtorch (skip this step if a valid libtorch already installed in your machine!)\n\n```bash\n    wget https://github.com/sugarme/gotch/releases/download/v0.9.0/setup-libtorch.sh\n    chmod +x setup-libtorch.sh\n\n    export CUDA_VER=11.8 \u0026\u0026 bash setup-libtorch.sh\n```\n\n**Update Environment**: in Debian/Ubuntu, add/update the following lines to `.bashrc` file\n\n```bash\n    export GOTCH_LIBTORCH=\"/usr/local/lib/libtorch\"\n    export LIBRARY_PATH=\"$LIBRARY_PATH:$GOTCH_LIBTORCH/lib\"\n    export CPATH=\"$CPATH:$GOTCH_LIBTORCH/lib:$GOTCH_LIBTORCH/include:$GOTCH_LIBTORCH/include/torch/csrc/api/include\"\n    LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH:$GOTCH_LIBTORCH/lib:/usr/lib64-nvidia:/usr/local/cuda-${CUDA_VERSION}/lib64\"\n```\n\n#### Step 2: Setup gotch\n\n```bash\n    wget https://github.com/sugarme/gotch/releases/download/v0.9.0/setup-gotch.sh\n    chmod +x setup-gotch.sh\n    export CUDA_VER=11.8 \u0026\u0026 export GOTCH_VER=v0.9.1 \u0026\u0026 bash setup-gotch.sh\n```\n\n## Examples\n\n### Basic tensor operations\n\n```go\nimport (\n\t\"fmt\"\n\n\t\"github.com/sugarme/gotch\"\n\t\"github.com/sugarme/gotch/ts\"\n)\n\nfunc basicOps() {\n\nxs := ts.MustRand([]int64{3, 5, 6}, gotch.Float, gotch.CPU)\nfmt.Printf(\"%8.3f\\n\", xs)\nfmt.Printf(\"%i\", xs)\n\n/*\n(1,.,.) =\n   0.391     0.055     0.638     0.514     0.757     0.446  \n   0.817     0.075     0.437     0.452     0.077     0.492  \n   0.504     0.945     0.863     0.243     0.254     0.640  \n   0.850     0.132     0.763     0.572     0.216     0.116  \n   0.410     0.660     0.156     0.336     0.885     0.391  \n\n(2,.,.) =\n   0.952     0.731     0.380     0.390     0.374     0.001  \n   0.455     0.142     0.088     0.039     0.862     0.939  \n   0.621     0.198     0.728     0.914     0.168     0.057  \n   0.655     0.231     0.680     0.069     0.803     0.243  \n   0.853     0.729     0.983     0.534     0.749     0.624  \n\n(3,.,.) =\n   0.734     0.447     0.914     0.956     0.269     0.000  \n   0.427     0.034     0.477     0.535     0.440     0.972  \n   0.407     0.945     0.099     0.184     0.778     0.058  \n   0.482     0.996     0.085     0.605     0.282     0.671  \n   0.887     0.029     0.005     0.216     0.354     0.262  \n\n\n\nTENSOR INFO:\n        Shape:          [3 5 6]\n        DType:          float32\n        Device:         {CPU 1}\n        Defined:        true\n*/\n\n// Basic tensor operations\nts1 := ts.MustArange(ts.IntScalar(6), gotch.Int64, gotch.CPU).MustView([]int64{2, 3}, true)\ndefer ts1.MustDrop()\nts2 := ts.MustOnes([]int64{3, 4}, gotch.Int64, gotch.CPU)\ndefer ts2.MustDrop()\n\nmul := ts1.MustMatmul(ts2, false)\ndefer mul.MustDrop()\n\nfmt.Printf(\"ts1:\\n%2d\", ts1)\nfmt.Printf(\"ts2:\\n%2d\", ts2)\nfmt.Printf(\"mul tensor (ts1 x ts2):\\n%2d\", mul)\n\n/*\nts1:\n 0   1   2  \n 3   4   5  \n\nts2:\n 1   1   1   1  \n 1   1   1   1  \n 1   1   1   1  \n\nmul tensor (ts1 x ts2):\n 3   3   3   3  \n12  12  12  12  \n*/\n\n\n// In-place operation\nts3 := ts.MustOnes([]int64{2, 3}, gotch.Float, gotch.CPU)\nfmt.Printf(\"Before:\\n%v\", ts3)\nts3.MustAddScalar_(ts.FloatScalar(2.0))\nfmt.Printf(\"After (ts3 + 2.0):\\n%v\", ts3)\n\n/*\nBefore:\n1  1  1  \n1  1  1  \n\nAfter (ts3 + 2.0):\n3  3  3  \n3  3  3  \n*/\n}\n```\n\n### Simplified Convolutional neural network\n\n```go\nimport (\n    \"fmt\"\n\n    \"github.com/sugarme/gotch\"\n    \"github.com/sugarme/gotch/nn\"\n    \"github.com/sugarme/gotch/ts\"\n)\n\ntype Net struct {\n    conv1 *nn.Conv2D\n    conv2 *nn.Conv2D\n    fc    *nn.Linear\n}\n\nfunc newNet(vs *nn.Path) *Net {\n    conv1 := nn.NewConv2D(vs, 1, 16, 2, nn.DefaultConv2DConfig())\n    conv2 := nn.NewConv2D(vs, 16, 10, 2, nn.DefaultConv2DConfig())\n    fc := nn.NewLinear(vs, 10, 10, nn.DefaultLinearConfig())\n\n    return \u0026Net{\n        conv1,\n        conv2,\n        fc,\n    }\n}\n\nfunc (n Net) ForwardT(xs *ts.Tensor, train bool) *ts.Tensor {\n    xs = xs.MustView([]int64{-1, 1, 8, 8}, false)\n\n    outC1 := xs.Apply(n.conv1)\n    outMP1 := outC1.MaxPool2DDefault(2, true)\n    defer outMP1.MustDrop()\n\n    outC2 := outMP1.Apply(n.conv2)\n    outMP2 := outC2.MaxPool2DDefault(2, true)\n    outView2 := outMP2.MustView([]int64{-1, 10}, true)\n    defer outView2.MustDrop()\n\n    outFC := outView2.Apply(n.fc)\n    return outFC.MustRelu(true)\n}\n\nfunc main() {\n\n    vs := nn.NewVarStore(gotch.CPU)\n    net := newNet(vs.Root())\n\n    xs := ts.MustOnes([]int64{8, 8}, gotch.Float, gotch.CPU)\n\n    logits := net.ForwardT(xs, false)\n    fmt.Printf(\"Logits: %0.3f\", logits)\n}\n\n//Logits: 0.000  0.000  0.000  0.225  0.321  0.147  0.000  0.207  0.000  0.000\n```\n\n## Play with `gotch` on Google Colab or locally\n\n- [Tensor Initiation](example/basic) \u003ca href=\"https://colab.research.google.com/github/sugarme/nb/blob/master/tensor/tensor-initiation.ipynb\" target=\"_parent\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/\u003e\u003c/a\u003e\n- [Tensor Indexing](example/basic) \u003ca href=\"https://colab.research.google.com/github/sugarme/nb/blob/master/tensor/tensor-indexing.ipynb\" target=\"_parent\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/\u003e\u003c/a\u003e\n- [MNIST](example/mnist) \u003ca href=\"https://colab.research.google.com/github/sugarme/nb/blob/master/mnist/mnist.ipynb\" target=\"_parent\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/\u003e\u003c/a\u003e\n- [YOLO v3 model infering](example/yolo) \u003ca href=\"https://colab.research.google.com/github/sugarme/nb/blob/master/yolo/yolo.ipynb\" target=\"_parent\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/\u003e\u003c/a\u003e\n- [RNN model training](example/char-rnn)\n- [CIFAR model training](example/cifar)\n- [JIT ResNet18 Torch Script model load and inference](example/jit)\n- [Neural style transfer](example/neural-style-transfer)\n- [Image pretrained models - inference](example/pretrained-model)\n- [Translation](example/translation)\n- [Convert Pytorch Python model to Go](example/convert-model)\n- [Load Python Pytorch JIT model then train/finetune in Go](example/jit-train)\n- [Image augmentation](example/augmentation)\n\n## Getting Started\n\n- See [pkg.go.dev](https://pkg.go.dev/github.com/sugarme/gotch?tab=doc) for APIs detail.\n\n## License\n\n`gotch` is Apache 2.0 licensed.\n\n## Acknowledgement\n\n- This project has been inspired and used many concepts from [tch-rs](https://github.com/LaurentMazare/tch-rs)\n    Libtorch Rust binding. \n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsugarme%2Fgotch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsugarme%2Fgotch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsugarme%2Fgotch/lists"}