{"id":26891126,"url":"https://github.com/slicer/light-the-torch","last_synced_at":"2026-05-10T06:11:32.960Z","repository":{"id":37905514,"uuid":"278435637","full_name":"Slicer/light-the-torch","owner":"Slicer","description":"Install PyTorch distributions with computation backend auto-detection","archived":false,"fork":false,"pushed_at":"2024-12-17T22:09:08.000Z","size":189,"stargazers_count":251,"open_issues_count":12,"forks_count":8,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-07T23:13:36.799Z","etag":null,"topics":["cuda","install","pip","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Slicer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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-07-09T18:01:38.000Z","updated_at":"2025-03-31T12:40:27.000Z","dependencies_parsed_at":"2025-01-04T17:05:13.791Z","dependency_job_id":null,"html_url":"https://github.com/Slicer/light-the-torch","commit_stats":{"total_commits":90,"total_committers":5,"mean_commits":18.0,"dds":0.0444444444444444,"last_synced_commit":"19e77b794c1b4f64a8591a764348e259ddd4055d"},"previous_names":["slicer/light-the-torch","pmeier/light-the-torch"],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slicer%2Flight-the-torch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slicer%2Flight-the-torch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slicer%2Flight-the-torch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slicer%2Flight-the-torch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Slicer","download_url":"https://codeload.github.com/Slicer/light-the-torch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744333,"owners_count":20988783,"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":["cuda","install","pip","pytorch"],"created_at":"2025-03-31T22:14:16.928Z","updated_at":"2026-05-10T06:11:32.954Z","avatar_url":"https://github.com/Slicer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `light-the-torch`\n\n[![BSD-3-Clause License](https://img.shields.io/github/license/Slicer/light-the-torch)](https://opensource.org/licenses/BSD-3-Clause)\n[![Project Status: WIP](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)\n[![Code coverage via codecov.io](https://codecov.io/gh/Slicer/light-the-torch/branch/main/graph/badge.svg)](https://codecov.io/gh/Slicer/light-the-torch)\n\n`light-the-torch` is a small utility that wraps `pip` to ease the installation process\nfor PyTorch distributions like `torch`, `torchvision`, `torchaudio`, and so on as well\nas third-party packages that depend on them. It auto-detects compatible CUDA versions\nfrom the local setup and installs the correct PyTorch binaries without user\ninterference.\n\n- [Why do I need it?](#why-do-i-need-it)\n- [How do I install it?](#how-do-i-install-it)\n- [How do I use it?](#how-do-i-use-it)\n- [How does it work?](#how-does-it-work)\n- [Is it safe?](#is-it-safe)\n- [How do I contribute?](#how-do-i-contribute)\n\n## Why do I need it?\n\nPyTorch distributions like `torch`, `torchvision`, `torchaudio`, and so on are fully\n`pip install`'able, but PyPI, the default `pip` search index, has some limitations:\n\n1. PyPI regularly only allows binaries up to a size of\n   [approximately 60 MB](https://github.com/pypa/packaging-problems/issues/86). One can\n   [request a file size limit increase](https://pypi.org/help/#file-size-limit) (and the\n   PyTorch team probably does that for every release), but it is still not enough:\n   although PyTorch has pre-built binaries for Windows with CUDA, they cannot be\n   installed through PyPI due to their size.\n2. PyTorch uses local version specifiers to indicate for which computation backend the\n   binary was compiled, for example `torch==1.11.0+cpu`. Unfortunately, local specifiers\n   are not allowed on PyPI. Thus, only the binaries compiled with one CUDA version are\n   uploaded without an indication of the CUDA version. If you do not have a CUDA capable\n   GPU, downloading this is only a waste of bandwidth and disk capacity. If on the other\n   hand your NVIDIA driver version simply doesn't support the CUDA version the binary\n   was compiled with, you can't use any of the GPU features.\n\nTo overcome this, PyTorch also hosts _most_[^1] binaries\n[on their own package indices](https://download.pytorch.org/whl). To access PyTorch's\npackage indices, you can still use `pip install`, but some\n[additional options](https://pytorch.org/get-started/locally/) are needed:\n\n```shell\npip install torch --index-url https://download.pytorch.org/whl/cu118\n```\n\n[^1]:\n    Some distributions are not compiled against a specific computation backend and thus\n    hosting them on PyPI is sufficient since they work in every environment.\n\nWhile this is certainly an improvement, it still has a few downsides:\n\n1. You need to know what computation backend, e.g. CUDA 11.8 (`cu118`), is supported on\n   your local machine. This can be quite challenging for new users and at least tedious\n   for more experienced ones.\n2. Besides the stable binaries, PyTorch also offers nightly and test ones. To install\n   them, you need a different `--index-url` for each.\n\nIf any of these points don't sound appealing to you, and you just want to have the same\nuser experience as `pip install` for PyTorch distributions, `light-the-torch` was made\nfor you.\n\n## How do I install it?\n\nInstalling `light-the-torch` is as easy as\n\n```shell\npip install light-the-torch\n```\n\nSince it depends on `pip` and it might be upgraded during installation,\n[Windows users](https://pip.pypa.io/en/stable/installation/#upgrading-pip) should\ninstall it with\n\n```shell\npy -m pip install light-the-torch\n```\n\n## How do I use it?\n\nAfter `light-the-torch` is installed you can use its CLI interface `ltt` as drop-in\nreplacement for `pip`:\n\n```shell\nltt install torch\n```\n\nIn fact, `ltt` is `pip` with a few added options:\n\n- By default, `ltt` uses the local NVIDIA driver version to select the correct binary\n  for you. You can pass the `--pytorch-computation-backend` option to manually specify\n  the computation backend you want to use:\n\n  ```shell\n  ltt install --pytorch-computation-backend=cu121 torch torchvision torchaudio\n  ```\n\n  Borrowing from the mutex packages that PyTorch provides for `conda` installations,\n  `--cpuonly` is available as shorthand for `--pytorch-computation-backend=cpu`.\n\n  In addition, the computation backend to be installed can also be set through the\n  `LTT_PYTORCH_COMPUTATION_BACKEND` environment variable. It will only be honored in\n  case no CLI option for the computation backend is specified.\n\n- By default, `ltt` installs stable PyTorch binaries. To install binaries from the\n  nightly or test channels pass the `--pytorch-channel` option:\n\n  ```shell\n  ltt install --pytorch-channel=nightly torch torchvision torchaudio\n  ```\n\n  If `--pytorch-channel` is not passed, using `pip`'s builtin `--pre` option implies\n  `--pytorch-channel=test`.\n\nOf course, you are not limited to install only PyTorch distributions. Everything shown\nabove also works if you install packages that depend on PyTorch:\n\n```shell\nltt install --pytorch-computation-backend=cpu --pytorch-channel=nightly pystiche\n```\n\n## How does it work?\n\nThe authors of `pip` **do not condone** the use of `pip` internals as they might break\nwithout warning. As a results of this, `pip` has no capability for plugins to hook into\nspecific tasks.\n\n`light-the-torch` works by monkey-patching `pip` internals at runtime:\n\n- While searching for a download link for a PyTorch distribution, `light-the-torch`\n  replaces the default search index with an official PyTorch download link. This is\n  equivalent to calling `pip install` with the `--index-url` option only for PyTorch\n  distributions.\n- While evaluating possible PyTorch installation candidates, `light-the-torch` culls\n  binaries incompatible with the hardware.\n\n## Is it safe?\n\nA project as large as PyTorch is attractive for malicious actors given the large user\nbase. For example in December 2022, PyTorch was hit by a\n[supply chain attack](https://pytorch.org/blog/compromised-nightly-dependency/) that\npotentially extracted user information. The PyTorch team mitigated the attack as soon as\nit was detected by temporarily hosting all third party dependencies on their own\nindices. With that,\n`pip install torch --extra-index-url https://download.pytorch.org/whl/cpu` wouldn't pull\nanything from PyPI and thus avoiding malicious packages placed there. Ultimately, this\nbecame the permanent solution and the official installation instructions now use\n`--index-url` and thus preventing installing anything not hosted on their indices.\n\nHowever, due to `light-the-torch`'s index patching, this mitigation was initially\ncompletely circumvented since only PyTorch distributions would have been installed from\nthe PyTorch indices. Since version `0.7.0`, `light-the-torch` will only pull third-party\ndependencies from PyPI in case they are specifically requested and pinned. For example\n`ltt install --pytorch-channel=nightly torch` and\n`ltt install --pytorch-channel=nightly torch sympy` will install everything from the\nPyTorch indices. However, if you pin a third party dependency, e.g.\n`ltt install --pytorch-channel=nightly torch sympy==1.11.1`, it will be pulled from PyPI\nregardless of whether the version matches the one on the PyTorch index.\n\nIn summary, `light-the-torch` is usually as safe as the regular PyTorch installation\ninstructions. However, attacks on the supply chain can lead to situations where\n`light-the-torch` circumvents mitigations done by the PyTorch team. Unfortunately,\n`light-the-torch` is not officially supported by PyTorch and thus also not tested by\nthem.\n\n## How do I contribute?\n\nThanks a lot for your interest to contribute to `light-the-torch`! All contributions are\nappreciated, be it code or not. Especially in a project like this, we rely on user\nreports for edge cases we didn't anticipate. Please feel free to\n[open an issue](https://github.com/Slicer/light-the-torch/issues) if you encounter\nanything that you think should be working but doesn't.\n\nIf you want to contribute code, check out our [contributing guidelines](CONTRIBUTING.md)\nto learn more about the workflow.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslicer%2Flight-the-torch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslicer%2Flight-the-torch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslicer%2Flight-the-torch/lists"}