Patch pip to play ball with PyTorch
Project description
pytorch-pip-shim
package |
|
---|---|
code |
|
tests |
Disclaimer
Neither this project (pytorch-pip-shim) nor its author (Philip Meier) are affiliated with PyTorch in any way. PyTorch and any related marks are trademarks of Facebook, Inc.
What is it?
pytorch-pip-shim is a small background utility that eases the installation process with pip for PyTorch and third-party packages that depend on its distributions. After the shim is inserted, you can install PyTorch with pip like you do with any other package.
Why do I need it?
PyTorch is fully pip install able, but PyPI, the default pip search index, has some limitations:
PyPI regularly only allows binaries up to a size of approximately 60 MB. You can request a file size limit increase (and the PyTorch team probably did that), but it is still not enough: the Windows binaries cannot be installed through PyPI due to their size.
PyTorch uses local version specifiers to indicate for which computation backend the binary was compiled, for example torch==1.6.0+cpu. Unfortunately, local specifiers are not allowed on PyPI. Thus, only the binaries compiled with the latest CUDA version are uploaded. If you do not have a CUDA capable GPU, downloading this is only a waste of bandwidth and disk capacity. If on the other hand simply don’t have the latest CUDA driver installed, you can’t use any of the GPU features.
To overcome this, PyTorch alos hosts all binaries themselves. To access them, you still can use pip install, but have to use some additional options:
$ pip install torch==1.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
While this is certainly an improvement, it also has it downside: in addition to the computation backend, the version has to be specified exactly. Without knowing what the latest release is, it is impossible to install it as simple as pip install torch normally would.
At this point you might justifiably as: why don’t you just use conda as PyTorch recommends?
$ conda install pytorch cpuonly -c pytorch
This should cover all cases, right? Well, almost. The above command is enough if you just need PyTorch. Imagine the case of a package that depends on PyTorch, but cannot be installed with conda since it is hosted on PyPI? You can’t use the -f option since the package in question is not hosted by PyTorch. Thus, you now have to manually track down (and resolve in the case of multiple packages) the PyTorch distributions, install them in a first step and only install the actual package (and all other dependencies) afterwards.
If just want to use pip install like you always did before without worrying about any of the stuff above, pytorch-pip-shim was made for you.
How do I install it?
Installing pytorch-pip-shim is as easy as
$ pip install pytorch-pip-shim
Since it depends on pip and it might be upgraded during installation, Windows users should install it with
$ python -m pip install pytorch-pip-shim
How do I use it?
After pytorch-pip-shim is installed there is only a single step to insert the shim:
$ pytorch-pip-shim insert
After that you can use pip as you did before and pytorch-pip-shim handles the computation backend auto-detection for you in the background.
If you want to remove the shim you can do so with
$ pytorch-pip-shim remove
You can check its status with
$ pytorch-pip-shim status
How do I uninstall it?
Uninstalling is as easy as
$ pip uninstall pytorch-pip-shim
By doing so, pytorch-pip-shim automatically removes the shim if inserted.
How do I configure it?
Once inserted, you don’t need to configure anything. If you don’t want the computation backend auto-detected but rather want to set it manually pytorch-pip-shim adds two CLI options to pip install:
--computation-backend <computation_backend>
--cpu
How does it work?
The authors of pip do not condone the use of pip internals as they might break without warning. As a results of this, pip has no capability for plugins to hook into specific tasks. Thus, the only way to patch pip s functionality is to adapt its source in-place. Although this is really bad practice, it is unavoidable for the goal of this package.
pystiche-pip-shim inserts a shim into the pip main file, which decorates the main function. Everytime you call pip install, some aspects of the installation process are patched:
While searching for a download link for a PyTorch distribution, pytorch-pip-shim replaces the default search index. This is equivalent to calling pip install with the -f option only for PyTorch distributions.
While evaluating possible PyTorch installation candidates, pytorch-pip-shim culls binaries not compatible with the available hardware.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytorch_pip_shim-0.1.0.tar.gz
.
File metadata
- Download URL: pytorch_pip_shim-0.1.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d91dc1adeeab341304eec46e21699f467f430b0e9fe0ce6128ebfac91a76bce |
|
MD5 | 70ed21dce3ea8ff139a8f1856d3448d1 |
|
BLAKE2b-256 | d77a4de60129ddf503accbc6710d805a5f9b93ec4722fb45e157920a6ac83bd7 |
File details
Details for the file pytorch_pip_shim-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pytorch_pip_shim-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 424d3c6bdb53f92b8c5d78bc5181148a248bdd7b81c81498c3d31690fee8b6df |
|
MD5 | 6f82156aade003cbc1eb14a2da1f1b84 |
|
BLAKE2b-256 | d51e2ff000df14e2ef9ad5c87a47b30b56f9fc359c61b73525dde5bb35bdc5b4 |