|
| 1 | +# torch-runtime |
| 2 | +[](https://discord.com/invite/u9yhsFmEkB) |
| 3 | + |
| 4 | +**torch-runtime** is a lightweight package for automatically installing the appropriate variant of PyTorch on a user's computer, based on their OS, and GPU manufacturer and GPU model. |
| 5 | + |
| 6 | +This package is used by [Easy Diffusion](https://github.com/easydiffusion/easydiffusion), but you're welcome to use it as well. It's useful for developers who make PyTorch-based apps that target users with NVIDIA, AMD and Intel graphics cards (as well as CPU-only usage), on Windows, Mac and Linux. |
| 7 | + |
| 8 | +### Why? |
| 9 | +It lets you treat PyTorch as a single dependency (like it should be), and lets you assume that each user will get the most-performant variant of PyTorch suitable for their computer's OS and hardware. |
| 10 | + |
| 11 | +It deals with the complexity of the variety of torch builds and configurations required for CUDA, AMD (ROCm, DirectML), Intel (xpu/DirectML/ipex), and CPU-only. |
| 12 | + |
| 13 | +**Compatibility table**: [Click here](#compatibility-table) to see the supported graphics cards and operating systems. |
| 14 | + |
| 15 | +# Installation |
| 16 | +Supports Windows, Linux, and Mac. |
| 17 | + |
| 18 | +`pip install torch-runtime` |
| 19 | + |
| 20 | +## Usage |
| 21 | +### Step 1. Install the appropriate variant of PyTorch |
| 22 | +*This command should be run on the user's computer, or while creating platform-specific builds:* |
| 23 | + |
| 24 | +`python -m torch_runtime install` (*note the underscore in `torch_runtime`*) |
| 25 | + |
| 26 | +This will install `torch`, `torchvision`, and `torchaudio`, and will decide the variant based on the user's OS, GPU manufacturer and GPU model number. See [customizing packages](#customizing-packages) for more options. |
| 27 | + |
| 28 | +### Step 2. Initialize torch |
| 29 | +This should be run inside your program, to initialize the required environment variables (if any) for the variant of torch being used. |
| 30 | + |
| 31 | +```py |
| 32 | +import torch_runtime |
| 33 | + |
| 34 | +torch_runtime.init_torch() |
| 35 | +``` |
| 36 | + |
| 37 | +## Customizing packages |
| 38 | +By default, `python -m torch_runtime install` will install the latest available `torch`, `torchvision` and `torchaudio` suitable on the user's platform. |
| 39 | + |
| 40 | +You can customize the packages to install by including their names: |
| 41 | +* For e.g. to install only `torch` and `torchvision`, you can run `python -m torch_runtime install torch torchvision` |
| 42 | +* To install specific versions (in pip format), you can run `python -m torch_runtime install "torch>2.0" "torchvision==0.20"` |
| 43 | + |
| 44 | +**Note:** If you specify package versions, please keep in mind that the version may not be available to *all* the users on *all* the torch platforms. For e.g. a user with Python 3.8 would not be able to install torch 2.5 (or higher), because torch 2.5 dropped support for Python 3.8. |
| 45 | + |
| 46 | +So in general, it's better to avoid specifying a version unless it really matters to you (or you know what you're doing). Instead, please allow `torch-runtime` to pick the latest-possible version for the user. |
| 47 | + |
| 48 | +# Compatibility table |
| 49 | +The list of platforms on which `torch-runtime` can install a working variant of PyTorch. |
| 50 | + |
| 51 | +**Note:** *This list is based on user feedback (since I don't have all the cards). Please let me know if your card is supported (or not) by opening a pull request or issue or messaging on [Discord](https://discord.com/invite/u9yhsFmEkB) (with supporting logs).* |
| 52 | + |
| 53 | +**CPU-only:** |
| 54 | + |
| 55 | +| OS | Supported?| Notes | |
| 56 | +|---|---|---| |
| 57 | +| Windows | ✅ Yes | x86_64 | |
| 58 | +| Linux | ✅ Yes | x86_64 and aarch64 | |
| 59 | +| Mac (M1/M2/M3/M4) | ✅ Yes | arm64. `mps` backend | |
| 60 | +| Mac (Intel) | ✅ Yes | x86_64. Stopped after `torch 2.2.2` | |
| 61 | + |
| 62 | +**NVIDIA:** |
| 63 | + |
| 64 | +| Series | Supported? | OS | Notes | |
| 65 | +|---|---|---|---| |
| 66 | +| 40xx | ✅ Yes | Win/Linux | Uses CUDA 124 | |
| 67 | +| 30xx | ✅ Yes | Win/Linux | Uses CUDA 124 | |
| 68 | +| 20xx | ✅ Yes | Win/Linux | Uses CUDA 124 | |
| 69 | +| 10xx/16xx | ✅ Yes | Win/Linux | Uses CUDA 124. Full-precision required on 16xx series | |
| 70 | + |
| 71 | +**AMD:** |
| 72 | + |
| 73 | +| Series | Supported? | OS | Notes | |
| 74 | +|---|---|---|---| |
| 75 | +| 7xxx | ✅ Yes | Win/Linux | Navi3/RDNA3 (gfx110x). ROCm 6.2 on Linux. DirectML on Windows | |
| 76 | +| 6xxx | ✅ Yes | Win/Linux | Navi2/RDNA2 (gfx103x). ROCm 6.2 on Linux. DirectML on Windows | |
| 77 | +| 5xxx | ✅ Yes | Win/Linux | Navi1/RDNA1 (gfx101x). Full-precision required. DirectML on Windows. Linux only supports upto ROCm 5.2. Waiting for [this](https://github.com/pytorch/pytorch/issues/132570#issuecomment-2313071756) for ROCm 6.2 support. | |
| 78 | +| 5xxx on Intel Mac | ❓ Untested (WIP) | Intel Mac | gfx101x. Implemented but need testers, please message on [Discord](https://discord.com/invite/u9yhsFmEkB) | |
| 79 | +| 4xxx/Radeon VII | ❓ Untested (WIP) | N/A | gfx90x. Implemented but need testers, please message on [Discord](https://discord.com/invite/u9yhsFmEkB) | |
| 80 | +| 5xx/Polaris | ❓ Untested (WIP) | N/A | gfx80x. Implemented but need testers, please message on [Discord](https://discord.com/invite/u9yhsFmEkB) | |
| 81 | + |
| 82 | +**Apple:** |
| 83 | + |
| 84 | +| Series | Supported? |Notes | |
| 85 | +|---|---|---| |
| 86 | +| M1/M2/M3/M4 | ✅ Yes | 'mps' backend | |
| 87 | +| AMD on Intel Mac | ❓ Untested (WIP) | Implemented but need testers, please message on [Discord](https://discord.com/invite/u9yhsFmEkB) | |
| 88 | + |
| 89 | +**Intel:** |
| 90 | + |
| 91 | +| Series | Supported? | OS | Notes | |
| 92 | +|---|---|---|---| |
| 93 | +| Arc | ❓ Untested (WIP) | Win/Linux | Implemented but need testers, please message on [Discord](https://discord.com/invite/u9yhsFmEkB). Backends: 'xpu' or DirectML or [ipex](https://github.com/intel/intel-extension-for-pytorch) | |
| 94 | + |
| 95 | + |
| 96 | +# FAQ |
| 97 | +## Why can't I just run 'pip install torch'? |
| 98 | +`pip install torch` installs the CPU-only version of torch, so it won't utilize your GPU's capabilities. |
| 99 | + |
| 100 | +## Why can't I just install torch-for-ROCm directly to support AMD? |
| 101 | +Different models of AMD cards require different LLVM targets, and sometimes different ROCm versions. And ROCm currently doesn't work on Windows, so AMD on Windows is best served (currently) with DirectML. |
| 102 | + |
| 103 | +And plenty of AMD cards work with ROCm (even when they aren't in the official list of supported cards). Information about these cards (for e.g. the LLVM target to use) is pretty scattered. |
| 104 | + |
| 105 | +`torch-runtime` deals with this complexity for your convenience. |
| 106 | + |
| 107 | +# Contributing |
| 108 | +📢 I'm looking for contributions in these specific areas: |
| 109 | +- More testing on consumer AMD GPUs. |
| 110 | +- More support for older AMD GPUs. Explore: Compile and host PyTorch wheels and rocm (on GitHub) for older AMD gpus (e.g. 580/590/Polaris) with the required patches. |
| 111 | +- Intel GPUs. |
| 112 | +- Testing on professional AMD GPUs (e.g. the Instinct series). |
| 113 | +- An easy-to-run benchmark script (that people can run to check the level of compatibility on their platform). |
| 114 | + |
| 115 | +Please message on the [Discord community](https://discord.com/invite/u9yhsFmEkB) if you have AMD or Intel GPUs, and would like to help with testing or adding support for them! Thanks! |
| 116 | + |
| 117 | +# Credits |
| 118 | +* Code contributors on [Easy Diffusion](https://github.com/easydiffusion/easydiffusion). |
| 119 | +* Users on [Easy Diffusion's Discord](https://discord.com/invite/u9yhsFmEkB) who've helped with testing on various GPUs. |
| 120 | + |
| 121 | +# More resources |
| 122 | +* [AMD GPU LLVM Architectures](https://web.archive.org/web/20241228163540/https://llvm.org/docs/AMDGPUUsage.html#processors) |
| 123 | +* [Status of ROCm support for AMD Navi 1](https://github.com/ROCm/ROCm/issues/2527) |
| 124 | +* [Torch support for ROCm 6.2 on AMD Navi 1](https://github.com/pytorch/pytorch/issues/132570#issuecomment-2313071756) |
| 125 | +* [ROCmLibs-for-gfx1103-AMD780M-APU](https://github.com/likelovewant/ROCmLibs-for-gfx1103-AMD780M-APU) |
0 commit comments