|
| 1 | +--- |
| 2 | +### Title the install tools article with the name of the tool to be installed |
| 3 | +### Include vendor name where appropriate |
| 4 | +title: PyTorch for Windows on Arm |
| 5 | + |
| 6 | +### Optional additional search terms (one per line) to assist in finding the article |
| 7 | +additional_search_terms: |
| 8 | +- python |
| 9 | +- windows |
| 10 | +- woa |
| 11 | +- windows on arm |
| 12 | +- open source windows on arm |
| 13 | +- pytorch |
| 14 | + |
| 15 | +### Estimated completion time in minutes (please use integer multiple of 5) |
| 16 | +minutes_to_complete: 15 |
| 17 | + |
| 18 | +### Link to official documentation |
| 19 | +official_docs: https://www.python.org/doc/ |
| 20 | + |
| 21 | +author: Pareena Verma |
| 22 | + |
| 23 | +### PAGE SETUP |
| 24 | +weight: 1 # Defines page ordering. Must be 1 for first (or only) page. |
| 25 | +tool_install: true # Set to true to be listed in main selection page, else false |
| 26 | +multi_install: false # Set to true if first page of multi-page article, else false |
| 27 | +multitool_install_part: false # Set to true if a sub-page of a multi-page article, else false |
| 28 | +layout: installtoolsall # DO NOT MODIFY. Always true for tool install articles |
| 29 | +--- |
| 30 | + |
| 31 | +PyTorch has native support for [Windows on Arm](https://learn.microsoft.com/en-us/windows/arm/overview). Starting with PyTorch 2.7 release, you can access Arm native builds of PyTorch for Windows available for Python 3.12. |
| 32 | + |
| 33 | +A number of developer-ready Windows on Arm [devices](/learning-paths/laptops-and-desktops/intro/find-hardware/) are available. |
| 34 | + |
| 35 | +Windows on Arm instances are available with Microsoft Azure. For further information, see [Deploy a Windows on Arm virtual machine on Microsoft Azure](/learning-paths/cross-platform/woa_azure/). |
| 36 | + |
| 37 | +## How do I install PyTorch for Windows on Arm? |
| 38 | + |
| 39 | +Before you install PyTorch on your Windows on Arm machine, you will need to install [Python for Windows on Arm](/install-guides/py-woa) |
| 40 | + |
| 41 | +Verify your Python installation at a Windows Command prompt or a PowerShell prompt: |
| 42 | + |
| 43 | +```command |
| 44 | +python --version |
| 45 | +``` |
| 46 | +The output should look like: |
| 47 | + |
| 48 | +```output |
| 49 | +Python 3.12.9 |
| 50 | +``` |
| 51 | +Once you have downloaded Python, you can install the PyTorch Stable release (2.7.0) on your Windows on Arm machine. |
| 52 | + |
| 53 | +```command |
| 54 | +pip3 install torch==2.7.0 --index-url https://download.pytorch.org/whl/cpu |
| 55 | +``` |
| 56 | + |
| 57 | +You will see that the `arm64` wheel for PyTorch is installed on your machine: |
| 58 | +```output |
| 59 | +Downloading https://download.pytorch.org/whl/cpu/torch-2.7.0%2Bcpu-cp312-cp312-win_arm64.whl (107.9 MB) |
| 60 | + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 107.9/107.9 MB 29.7 MB/s eta 0:00:00 |
| 61 | +Downloading https://download.pytorch.org/whl/sympy-1.13.3-py3-none-any.whl (6.2 MB) |
| 62 | + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.2/6.2 MB 47.4 MB/s eta 0:00:00 |
| 63 | +Downloading https://download.pytorch.org/whl/typing_extensions-4.12.2-py3-none-any.whl (37 kB) |
| 64 | +Downloading https://download.pytorch.org/whl/filelock-3.13.1-py3-none-any.whl (11 kB) |
| 65 | +Downloading https://download.pytorch.org/whl/fsspec-2024.6.1-py3-none-any.whl (177 kB) |
| 66 | +Downloading https://download.pytorch.org/whl/Jinja2-3.1.4-py3-none-any.whl (133 kB) |
| 67 | +Downloading https://download.pytorch.org/whl/networkx-3.3-py3-none-any.whl (1.7 MB) |
| 68 | + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 30.6 MB/s eta 0:00:00 |
| 69 | +``` |
| 70 | + |
| 71 | +You can also install the nightly preview versions of PyTorch on your Windows Arm machine: |
| 72 | + |
| 73 | +```command |
| 74 | +pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu |
| 75 | +``` |
| 76 | + |
| 77 | +## How can I run a PyTorch example? |
| 78 | + |
| 79 | +To run a PyTorch example, and confirm that PyTorch is working, use a text editor to save the code below to a file named `pytorch_woa.py`. |
| 80 | + |
| 81 | +```python |
| 82 | +import torch |
| 83 | +import platform |
| 84 | + |
| 85 | +# Print PyTorch version |
| 86 | +print("PyTorch version:", torch.__version__) |
| 87 | + |
| 88 | +# Check if CUDA is available |
| 89 | +if torch.cuda.is_available(): |
| 90 | + print("CUDA is available. PyTorch can use the GPU.") |
| 91 | +else: |
| 92 | + print("CUDA is not available. PyTorch will use the CPU.") |
| 93 | + |
| 94 | +# Detect system architecture |
| 95 | +architecture = platform.machine() |
| 96 | +if "ARM" in architecture.upper() or "AARCH" in architecture.upper(): |
| 97 | + print("PyTorch is running on Arm:", architecture) |
| 98 | +else: |
| 99 | + print("PyTorch is not running on Arm. Detected architecture:", architecture) |
| 100 | + |
| 101 | +# Perform a basic PyTorch operation to confirm it's working |
| 102 | +try: |
| 103 | + tensor = torch.tensor([1.0, 2.0, 3.0]) |
| 104 | + print("PyTorch is operational. Tensor created:", tensor) |
| 105 | +except Exception as e: |
| 106 | + print("An error occurred while testing PyTorch:", e) |
| 107 | +``` |
| 108 | +Run the code: |
| 109 | + |
| 110 | +```console |
| 111 | +python pytorch_woa.py |
| 112 | +``` |
| 113 | +Running on a Windows on Arm machine produces an output similar to: |
| 114 | + |
| 115 | +```output |
| 116 | +PyTorch version: 2.7.0+cpu |
| 117 | +CUDA is not available. PyTorch will use the CPU. |
| 118 | +PyTorch is running on Arm: ARM64 |
| 119 | +PyTorch is operational. Tensor created: tensor([1., 2., 3.]) |
| 120 | +``` |
| 121 | +You are now ready to use Python on your Windows on Arm device. |
0 commit comments