Skip to content
Back to search

pytorch

Tensors and Dynamic neural networks in Python with strong GPU acceleration

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026. Its scripts were only partly scanned.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/pytorch/pytorch with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/pytorch/pytorch'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/pytorch--pytorch/badge.svg)](/listings/pytorch--pytorch)

HTML

<a href="/listings/pytorch--pytorch"><img src="/api/listings/pytorch--pytorch/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Binaries

Commands to install binaries via Conda or pip wheels are on our website: [https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/)

NVIDIA Jetson Platforms

Python wheels for NVIDIA's Jetson Nano, Jetson TX1/TX2, Jetson Xavier NX/AGX, and Jetson AGX Orin are provided [here](https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-10-now-available/72048) and the L4T container is published [here](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-pytorch)

They require JetPack 4.2 and above, and [@dusty-nv](https://github.com/dusty-nv) and [@ptrblck](https://github.com/ptrblck) are maintaining them.

From Source

Prerequisites

If you are installing from source, you will need: - Python 3.10 or later - A compiler that fully supports C++20, such as clang or gcc (gcc 11.3.0 or newer is required, on Linux) - Visual Studio or Visual Studio Build Tool (Windows only) - At least 10 GB of free disk space - 30-60 minutes for the initial build (subsequent rebuilds are much faster)

\* PyTorch CI uses Visual C++ BuildTools, which come with Visual Studio Enterprise, Professional, or Community Editions. You can also install the build tools from https://visualstudio.microsoft.com/visual-cpp-build-tools/. The build tools *do not* come with Visual Studio Code by default.

An example of environment setup is shown below:

* Linux:

$ source <CONDA_INSTALL_DIR>/bin/activate
$ conda create -y -n <CONDA_NAME>
$ conda activate <CONDA_NAME>

* Windows:

$ source <CONDA_INSTALL_DIR>\Scripts\activate.bat
$ conda create -y -n <CONDA_NAME>
$ conda activate <CONDA_NAME>
$ call "C:\Program Files\Microsoft Visual Studio\<VERSION>\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

A conda environment is not required. You can also do a PyTorch build in a standard virtual environment, e.g., created with tools like `uv`, provided your system has installed all the necessary dependencies unavailable as pip packages (e.g., CUDA, MKL.)

NVIDIA CUDA Support

If you want to compile with CUDA support, [select a supported version of CUDA from our support matrix](https://pytorch.org/get-started/locally/), then install the following: - [NVIDIA CUDA](https://developer.nvidia.com/cuda-downloads) - [NVIDIA cuDNN](https://developer.nvidia.com/cudnn) v9.0 or above - [Compiler](https://gist.github.com/ax3l/9489132) compatible with CUDA

Note: You could refer to the [cuDNN Support Matrix](https://docs.nvidia.com/deeplearning/cudnn/backend/latest/reference/support-matrix.html) for cuDNN versions with the various supported CUDA, CUDA driver, and NVIDIA hardware.

If you want to disable CUDA support, export the environment variable `USE_CUDA=0`. Other potentially useful environment variables are documented in [`cmake/EnvVarForwarding.cmake`](./cmake/EnvVarForwarding.cmake). If CUDA is installed in a non-standard location, set PATH so that the nvcc you want to use can be found (e.g., `export PATH=/usr/local/cuda-12.8/bin:$PATH`).

If you are building for NVIDIA's Jetson platforms (Jetson Nano, TX1, TX2, AGX Xavier), Instructions to install PyTorch for Jetson Nano are [available here](https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/)

AMD ROCm Support

If you want to compile with ROCm support, install - [AMD ROCm](https://rocm.docs.amd.com/en/latest/deploy/linux/quick_start.html) 4.0 and above installation - ROCm is currently supported only for Linux systems.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 486 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. <picture>
  2. <source media="(prefers-color-scheme: dark)" srcset="https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/pytorch-logo-light.png" />
  3. <source media="(prefers-color-scheme: light)" srcset="https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/pytorch-logo-dark.png" />
  4. <img src="https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/pytorch-logo-dark.png" alt="PyTorch logo" />
  5. </picture>
  6. --------------------------------------------------------------------------------
  7. PyTorch is a Python package that provides two high-level features:
  8. - Tensor computation (like NumPy) with strong GPU acceleration
  9. - Deep neural networks built on a tape-based autograd system
  10. You can reuse your favorite Python packages such as NumPy, SciPy, and Cython to extend PyTorch when needed.
  11. Our trunk health (Continuous Integration signals) can be found at [hud.pytorch.org](https://hud.pytorch.org/ci/pytorch/pytorch/main).
  12. <!-- toc -->
  13. - [More About PyTorch](#more-about-pytorch)
  14. - [A GPU-Ready Tensor Library](#a-gpu-ready-tensor-library)
  15. - [Dynamic Neural Networks: Tape-Based Autograd](#dynamic-neural-networks-tape-based-autograd)
  16. - [Python First](#python-first)
  17. - [Imperative Experiences](#imperative-experiences)
  18. - [Fast and Lean](#fast-and-lean)
  19. - [Extensions Without Pain](#extensions-without-pain)
  20. - [Installation](#installation)
  21. - [Binaries](#binaries)
  22. - [NVIDIA Jetson Platforms](#nvidia-jetson-platforms)
  23. - [From Source](#from-source)
  24. - [Prerequisites](#prerequisites)
  25. - [NVIDIA CUDA Support](#nvidia-cuda-support)
  26. - [AMD ROCm Support](#amd-rocm-support)
  27. - [Intel GPU Support](#intel-gpu-support)
  28. - [Get the PyTorch Source](#get-the-pytorch-source)
  29. - [Install Dependencies](#install-dependencies)
  30. - [Install PyTorch](#install-pytorch)
  31. - [Adjust Build Options (Optional)](#adjust-build-options-optional)
  32. - [Docker Image](#docker-image)
  33. - [Using pre-built images](#using-pre-built-images)
  34. - [Building the image yourself](#building-the-image-yourself)
  35. - [Previous Versions](#previous-versions)
  36. - [Getting Started](#getting-started)
  37. - [Resources](#resources)
  38. - [Communication](#communication)
  39. - [Releases and Contributing](#releases-and-contributing)
  40. - [The Team](#the-team)
  41. - [License](#license)
  42. <!-- tocstop -->
  43. ## More About PyTorch
  44. [Learn the basics of PyTorch](https://pytorch.org/tutorials/beginner/basics/intro.html)
  45. At a granular level, PyTorch is a library that consists of the following components:
  46. | Component | Description |
  47. | ---- | --- |
  48. | [**torch**](https://pytorch.org/docs/stable/torch.html) | A Tensor library like NumPy, with strong GPU support |
  49. | [**torch.autograd**](https://pytorch.org/docs/stable/autograd.html) | A tape-based automatic differentiation library that supports all differentiable Tensor operations in torch |
  50. | [**torch.nn**](https://pytorch.org/docs/stable/nn.html) | A neural networks library deeply integrated with autograd designed for maximum flexibility |
  51. | [**torch.multiprocessing**](https://pytorch.org/docs/stable/multiprocessing.html) | Python multiprocessing, but with magical memory sharing of torch Tensors across processes. Useful for data loading and Hogwild training |
  52. | [**torch.utils**](https://pytorch.org/docs/stable/data.html) | DataLoader and other utility functions for convenience |
  53. Usually, PyTorch is used either as:
  54. - A replacement for NumPy to use the power of GPUs.
  55. - A deep learning research platform that provides maximum flexibility and speed.
  56. Elaborating Further:
  57. ### A GPU-Ready Tensor Library
  58. If you use NumPy, then you have used Tensors (a.k.a. ndarray).
  59. ![Tensor illustration](https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/tensor_illustration.png)
  60. PyTorch provides Tensors that can live either on the CPU or the GPU and accelerates the
  61. computation by a huge amount.
  62. We provide a wide variety of tensor routines to accelerate and fit your scientific computation needs
  63. such as slicing, indexing, mathematical operations, linear algebra, reductions.
  64. And they are fast!
  65. ### Dynamic Neural Networks: Tape-Based Autograd
  66. PyTorch has a unique way of building neural networks: using and replaying a tape recorder.
  67. Most frameworks such as TensorFlow, Theano, Caffe, and CNTK have a static view of the world.
  68. One has to build a neural network and reuse the same structure again and again.
  69. Changing the way the network behaves means that one has to start from scratch.
  70. With PyTorch, we use a technique called reverse-mode auto-differentiation, which allows you to
  71. change the way your network behaves arbitrarily with zero lag or overhead. Our inspiration comes
  72. from several research papers on this topic, as well as current and past work such as
  73. [torch-autograd](https://github.com/twitter/torch-autograd),
  74. [autograd](https://github.com/HIPS/autograd),
  75. [Chainer](https://chainer.org), etc.
  76. While this technique is not unique to PyTorch, it's one of the fastest implementations of it to date.
  77. You get the best of speed and flexibility for your crazy research.
  78. ![Dynamic graph](https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/dynamic_graph.gif)
  79. ### Python First
  80. PyTorch is not a Python binding into a monolithic C++ framework.
  81. It is built to be deeply integrated into Python.
  82. You can use it naturally like you would use [NumPy](https://www.numpy.org/) / [SciPy](https://www.scipy.org/) / [scikit-learn](https://scikit-learn.org) etc.
  83. You can write your new neural network layers in Python itself, using your favorite libraries
  84. and use packages such as [Cython](https://cython.org/) and [Numba](https://numba.pydata.org/).
  85. Our goal is to not reinvent the wheel where appropriate.
  86. ### Imperative Experiences
  87. PyTorch is designed to be intuitive, linear in thought, and easy to use.
  88. When you execute a line of code, it gets executed. There isn't an asynchronous view of the world.
  89. When you drop into a debugger or receive error messages and stack traces, understanding them is straightforward.
  90. The stack trace points to exactly where your code was defined.
  91. We hope you never spend hours debugging your code because of bad stack traces or asynchronous and opaque execution engines.
  92. ### Fast and Lean
  93. PyTorch has minimal framework overhead. We integrate acceleration libraries
  94. such as [Intel MKL](https://software.intel.com/mkl) and NVIDIA ([cuDNN](https://developer.nvidia.com/cudnn), [NCCL](https://developer.nvidia.com/nccl)) to maximize speed.
  95. At the core, its CPU and GPU Tensor and neural network backends
  96. are mature and have been tested for years.
  97. Hence, PyTorch is quite fast — whether you run small or large neural networks.
  98. The memory usage in PyTorch is extremely efficient compared to Torch or some of the alternatives.
  99. We've written custom memory allocators for the GPU to make sure that
  100. your deep learning models are maximally memory efficient.
  101. This enables you to train bigger deep learning models than before.
  102. ### Extensions Without Pain
  103. Writing new neural network modules, or interfacing with PyTorch's Tensor API, was designed to be straightforward
  104. and with minimal abstractions.
  105. You can write new neural network layers in Python using the torch API
  106. [or your favorite NumPy-based libraries such as SciPy](https://pytorch.org/tutorials/advanced/numpy_extensions_tutorial.html).
  107. If you want to write your layers in C/C++, we provide a convenient extension API that is efficient and with minimal boilerplate.
  108. No wrapper code needs to be written. You can see [a tutorial here](https://pytorch.org/tutorials/advanced/cpp_extension.html) and [an example here](https://github.com/pytorch/extension-cpp).
  109. ## Installation
  110. ### Binaries
  111. Commands to install binaries via Conda or pip wheels are on our website: [https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/)
  112. #### NVIDIA Jetson Platforms
  113. Python wheels for NVIDIA's Jetson Nano, Jetson TX1/TX2, Jetson Xavier NX/AGX, and Jetson AGX Orin are provided [here](https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-10-now-available/72048) and the L4T container is published [here](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-pytorch)
  114. They require JetPack 4.2 and above, and [@dusty-nv](https://github.com/dusty-nv) and [@ptrblck](https://github.com/ptrblck) are maintaining them.
  115. ### From Source
  116. #### Prerequisites
  117. If you are installing from source, you will need:
  118. - Python 3.11 or later
  119. - A compiler that fully supports C++20, such as clang or gcc (gcc 11.3.0 or newer is required, on Linux)
  120. - Visual Studio or Visual Studio Build Tool (Windows only)
  121. - At least 10 GB of free disk space
  122. - 30-60 minutes for the initial build (subsequent rebuilds are much faster)
  123. \* PyTorch CI uses Visual C++ BuildTools, which come with Visual Studio Enterprise,
  124. Professional, or Community Editions. You can also install the build tools from
  125. https://visualstudio.microsoft.com/visual-cpp-build-tools/. The build tools *do not*
  126. come with Visual Studio Code by default.
  127. An example of environment setup is shown below:
  128. * Linux:
  129. ```bash
  130. $ source <CONDA_INSTALL_DIR>/bin/activate
  131. $ conda create -y -n <CONDA_NAME>
  132. $ conda activate <CONDA_NAME>
  133. ```
  134. * Windows:
  135. ```bash
  136. $ source <CONDA_INSTALL_DIR>\Scripts\activate.bat
  137. $ conda create -y -n <CONDA_NAME>
  138. $ conda activate <CONDA_NAME>
  139. $ call "C:\Program Files\Microsoft Visual Studio\<VERSION>\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
  140. ```
  141. A conda environment is not required. You can also do a PyTorch build in a
  142. standard virtual environment, e.g., created with tools like `uv`, provided
  143. your system has installed all the necessary dependencies unavailable as pip
  144. packages (e.g., CUDA, MKL.)
  145. ##### NVIDIA CUDA Support
  146. If you want to compile with CUDA support, [select a supported version of CUDA from our support matrix](https://pytorch.org/get-started/locally/), then install the following:
  147. - [NVIDIA CUDA](https://developer.nvidia.com/cuda-downloads)
  148. - [NVIDIA cuDNN](https://developer.nvidia.com/cudnn) v9.0 or above
  149. - [Compiler](https://gist.github.com/ax3l/9489132) compatible with CUDA
  150. Note: You could refer to the [cuDNN Support Matrix](https://docs.nvidia.com/deeplearning/cudnn/backend/latest/reference/support-matrix.html) for cuDNN versions with the various supported CUDA, CUDA driver, and NVIDIA hardware.
  151. If you want to disable CUDA support, export the environment variable `USE_CUDA=0`.
  152. Other potentially useful environment variables are documented in [`cmake/EnvVarForwarding.cmake`](./cmake/EnvVarForwarding.cmake). If
  153. CUDA is installed in a non-standard location, set PATH so that the nvcc you
  154. want to use can be found (e.g., `export PATH=/usr/local/cuda-12.8/bin:$PATH`).
  155. If you are building for NVIDIA's Jetson platforms (Jetson Nano, TX1, TX2, AGX Xavier), Instructions to install PyTorch for Jetson Nano are [available here](https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/)
  156. ##### AMD ROCm Support
  157. If you want to compile with ROCm support, install
  158. - [AMD ROCm](https://rocm.docs.amd.com/en/latest/deploy/linux/quick_start.html) 4.0 and above installation
  159. - ROCm is currently supported only for Linux systems.
  160. By default the build system expects ROCm to be installed in `/opt/rocm`. If ROCm is installed in a different directory, the `ROCM_PATH` environment variable must be set to the ROCm installation directory. The build system automatically detects the AMD GPU architecture. Optionally, the AMD GPU architecture can be explicitly set with the `PYTORCH_ROCM_ARCH` environment variable [AMD GPU architecture](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html#supported-gpus)
  161. If you want to disable ROCm support, export the environment variable `USE_ROCM=0`.
  162. Other potentially useful environment variables are documented in [`cmake/EnvVarForwarding.cmake`](./cmake/EnvVarForwarding.cmake).
  163. ##### Intel GPU Support
  164. If you want to compile with Intel GPU support, follow these
  165. - [PyTorch Prerequisites for Intel GPUs](https://www.intel.com/content/www/us/en/developer/articles/tool/pytorch-prerequisites-for-intel-gpu.html) instructions.
  166. - Intel GPU is supported for Linux and Windows.
  167. If you want to disable Intel GPU support, export the environment variable `USE_XPU=0`.
  168. Other potentially useful environment variables are documented in [`cmake/EnvVarForwarding.cmake`](./cmake/EnvVarForwarding.cmake).
  169. #### Get the PyTorch Source
  170. ```bash
  171. git clone https://github.com/pytorch/pytorch
  172. cd pytorch
  173. # if you are updating an existing checkout
  174. git submodule sync
  175. git submodule update --init --recursive
  176. ```
  177. #### Install Dependencies
  178. **Common**
  179. ```bash
  180. # Run this command from the PyTorch directory after cloning the source code using the “Get the PyTorch Source“ section above
  181. pip install --group dev
  182. ```
  183. **On Linux**
  184. ```bash
  185. pip install mkl-static mkl-include
  186. # CUDA only: Add LAPACK support for the GPU if needed
  187. # magma installation: run with active conda environment. specify CUDA version to install
  188. .ci/docker/common/install_magma_conda.sh 12.4
  189. # (optional) If using torch.compile with inductor/triton, install the matching version of triton
  190. # Run from the pytorch directory after cloning
  191. # For Intel GPU support, please explicitly `export USE_XPU=1` before running command.
  192. make triton
  193. ```
  194. **On Windows**
  195. ```bash
  196. pip install mkl-static mkl-include
  197. # Add these packages if torch.distributed is needed.
  198. # Distributed package support on Windows is a prototype feature and is subject to changes.
  199. conda install -c conda-forge libuv=1.51
  200. ```
  201. #### Install PyTorch
  202. **On Linux**
  203. If you're compiling for AMD ROCm then first run this command:
  204. ```bash
  205. # Only run this if you're compiling for ROCm
  206. python tools/amd_build/build_amd.py
  207. ```
  208. Install PyTorch
  209. ```bash
  210. # the CMake prefix for conda environment
  211. export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}"
  212. python -m pip install --no-build-isolation -v -e .
  213. # the CMake prefix for non-conda environment, e.g. Python venv
  214. # call following after activating the venv
  215. export CMAKE_PREFIX_PATH="${VIRTUAL_ENV}:${CMAKE_PREFIX_PATH}"
  216. ```
  217. **On macOS**
  218. ```bash
  219. python -m pip install --no-build-isolation -v -e .
  220. ```
  221. **On Windows**
  222. If you want to build legacy python code, please refer to [Building on legacy code and CUDA](https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#building-on-legacy-code-and-cuda)
  223. **CPU-only builds**
  224. In this mode PyTorch computations will run on your CPU, not your GPU.
  225. ```cmd
  226. python -m pip install --no-build-isolation -v -e .
  227. ```
  228. Note on OpenMP: The desired OpenMP implementation is Intel OpenMP (iomp). In order to link against iomp, you'll need to manually download the library and set up the building environment by tweaking `CMAKE_INCLUDE_PATH` and `LIB`. The instruction [here](https://docs.pytorch.org/docs/main/notes/windows.html#building-from-source) is an example for setting up both MKL and Intel OpenMP. Without these configurations for CMake, Microsoft Visual C OpenMP runtime (vcomp) will be used.
  229. **CUDA based build**
  230. In this mode PyTorch computations will leverage your GPU via CUDA for faster number crunching
  231. [NVTX](https://docs.nvidia.com/gameworks/content/gameworkslibrary/nvtx/nvidia_tools_extension_library_nvtx.htm) is needed to build PyTorch with CUDA.
  232. NVTX is a part of CUDA distributive, where it is called "Nsight Compute". To install it onto an already installed CUDA run CUDA installation once again and check the corresponding checkbox.
  233. Make sure that CUDA with Nsight Compute is installed after Visual Studio.
  234. Currently, VS 2017 / 2019, and Ninja are supported as the generator of CMake. If `ninja.exe` is detected in `PATH`, then Ninja will be used as the default generator, otherwise, it will use VS 2017 / 2019.
  235. <br/> If Ninja is selected as the generator, the latest MSVC will get selected as the underlying toolchain.
  236. Additional libraries such as
  237. [Magma](https://developer.nvidia.com/magma), [oneDNN, a.k.a. MKLDNN or DNNL](https://github.com/oneapi-src/oneDNN), and [Sccache](https://github.com/mozilla/sccache) are often needed. Please refer to the [installation-helper](https://github.com/pytorch/pytorch/tree/main/.ci/pytorch/win-test-helpers/installation-helpers) to install them.
  238. You can refer to the [build_pytorch.bat](https://github.com/pytorch/pytorch/blob/main/.ci/pytorch/win-test-helpers/build_pytorch.bat) script for some other environment variables configurations
  239. ```cmd
  240. cmd
  241. :: Set the environment variables after you have downloaded and unzipped the mkl package,
  242. :: else CMake would throw an error as `Could NOT find OpenMP`.
  243. set CMAKE_INCLUDE_PATH={Your directory}\mkl\include
  244. set LIB={Your directory}\mkl\lib;%LIB%
  245. :: Read the content in the previous section carefully before you proceed.
  246. :: [Optional] If you want to override the underlying toolset used by Ninja and Visual Studio with CUDA, please run the following script block.
  247. :: "Visual Studio 2019 Developer Command Prompt" will be run automatically.
  248. :: Make sure you have CMake >= 3.12 before you do this when you use the Visual Studio generator.
  249. set CMAKE_GENERATOR_TOOLSET_VERSION=14.27
  250. set DISTUTILS_USE_SDK=1
  251. for /f "usebackq tokens=*" %i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version [15^,17^) -products * -latest -property installationPath`) do call "%i\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%CMAKE_GENERATOR_TOOLSET_VERSION%
  252. :: [Optional] If you want to override the CUDA host compiler
  253. set CUDAHOSTCXX=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\cl.exe
  254. python -m pip install --no-build-isolation -v -e .
  255. ```
  256. **Intel GPU builds**
  257. In this mode PyTorch with Intel GPU support will be built.
  258. Please make sure [the common prerequisites](#prerequisites) as well as [the prerequisites for Intel GPU](#intel-gpu-support) are properly installed and the environment variables are configured prior to starting the build. For build tool support, `Visual Studio 2022` is required.
  259. Then PyTorch can be built with the command:
  260. ```cmd
  261. :: CMD Commands:
  262. :: Set the CMAKE_PREFIX_PATH to help find corresponding packages
  263. :: %CONDA_PREFIX% only works after `conda activate custom_env`
  264. if defined CMAKE_PREFIX_PATH (
  265. set "CMAKE_PREFIX_PATH=%CONDA_PREFIX%\Library;%CMAKE_PREFIX_PATH%"
  266. ) else (
  267. set "CMAKE_PREFIX_PATH=%CONDA_PREFIX%\Library"
  268. )
  269. python -m pip install --no-build-isolation -v -e .
  270. ```
  271. ##### Adjust Build Options (Optional)
  272. You can adjust the configuration of CMake variables through environment variables, which the
  273. build forwards to CMake (see [`cmake/EnvVarForwarding.cmake`](./cmake/EnvVarForwarding.cmake) for
  274. the full list). For example, pointing the build at a specific Conda prefix, CuDNN, or BLAS:
  275. On Linux
  276. ```bash
  277. export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}"
  278. spin develop
  279. ```
  280. On macOS
  281. ```bash
  282. export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}"
  283. MACOSX_DEPLOYMENT_TARGET=11.0 spin develop
  284. ```
  285. After a first `spin develop`, you can inspect or adjust the CMake cache interactively with
  286. `ccmake build` (or `cmake-gui build`) and rebuild with `spin develop`; your edits persist, because
  287. reconfiguration does not use `--fresh`. Environment variables win over `-C` flags, `-C` flags win
  288. over `pyproject.toml`, and all three win over what the build directory remembers from last time:
  289. a forwarded environment variable is re-applied on every build, so a cache edit only survives for
  290. variables the environment and the flags leave alone. To change one setting for a single command,
  291. put the variable in front of the command.
  292. ### Docker Image
  293. #### Using pre-built images
  294. You can also pull a pre-built docker image from Docker Hub and run with docker v23.0+
  295. ```bash
  296. docker run --gpus all --rm -ti --ipc=host pytorch/pytorch:latest
  297. ```
  298. Please note that PyTorch uses shared memory to share data between processes, so if torch multiprocessing is used (e.g.
  299. for multithreaded data loaders) the default shared memory segment size that container runs with is not enough, and you
  300. should increase shared memory size either with `--ipc=host` or `--shm-size` command line options to `nvidia-docker run`.
  301. #### Building the image yourself
  302. **NOTE:** Must be built with a Docker version >= 23.0
  303. The Dockerfile is supplied to build images with CUDA 12.6 support and cuDNN v9.
  304. You can pass `PYTHON_VERSION=x.y` make variable to specify which Python version is to be used by Miniconda, or leave it
  305. unset to use the default, as the Dockerfile uses system Python.
  306. ```bash
  307. make -f docker.Makefile
  308. # images are tagged as docker.io/${your_docker_username}/pytorch
  309. ```
  310. You can also pass the `CMAKE_VARS="..."` environment variable to specify additional CMake variables to be passed to CMake during the build.
  311. See [`cmake/EnvVarForwarding.cmake`](./cmake/EnvVarForwarding.cmake) for the list of available variables.
  312. ```bash
  313. make -f docker.Makefile
  314. ```
  315. ### Previous Versions
  316. Installation instructions and binaries for previous PyTorch versions may be found
  317. on [our website](https://pytorch.org/get-started/previous-versions).
  318. ## Getting Started
  319. Pointers to get you started:
  320. - [Tutorials: get you started with understanding and using PyTorch](https://pytorch.org/tutorials/)
  321. - [Examples: easy to understand PyTorch code across all domains](https://github.com/pytorch/examples)
  322. - [The API Reference](https://pytorch.org/docs/)
  323. - [Glossary](https://github.com/pytorch/pytorch/blob/main/GLOSSARY.md)
  324. ## Resources
  325. * [PyTorch.org](https://pytorch.org/)
  326. * [PyTorch Tutorials](https://pytorch.org/tutorials/)
  327. * [PyTorch Examples](https://github.com/pytorch/examples)
  328. * [PyTorch Models](https://pytorch.org/hub/)
  329. * [Intro to Deep Learning with PyTorch from Udacity](https://www.udacity.com/course/deep-learning-pytorch--ud188)
  330. * [Intro to Machine Learning with PyTorch from Udacity](https://www.udacity.com/course/intro-to-machine-learning-nanodegree--nd229)
  331. * [Deep Neural Networks with PyTorch from Coursera](https://www.coursera.org/learn/deep-neural-networks-with-pytorch)
  332. * [PyTorch Twitter](https://twitter.com/PyTorch)
  333. * [PyTorch Blog](https://pytorch.org/blog/)
  334. * [PyTorch YouTube](https://www.youtube.com/channel/UCWXI5YeOsh03QvJ59PMaXFw)
  335. ## Communication
  336. * Forums: Discuss implementations, research, etc. https://discuss.pytorch.org
  337. * GitHub Issues: Bug reports, feature requests, install issues, RFCs, thoughts, etc. See the [issue lifecycle](CONTRIBUTING.md#issue-lifecycle) for how they are handled.
  338. * Slack: The [PyTorch Slack](https://pytorch.slack.com/) hosts a primary audience of moderate to experienced PyTorch users and developers for general chat, online discussions, collaboration, etc.
  339. * Facebook Page: Important announcements about PyTorch. https://www.facebook.com/pytorch
  340. * For brand guidelines, please visit our website at [pytorch.org](https://pytorch.org/)
  341. ## Releases and Contributing
  342. To report issues or contribute changes to PyTorch, see [CONTRIBUTING.md](CONTRIBUTING.md).
  343. For information about PyTorch releases, see [RELEASE.md](RELEASE.md).
  344. ## The Team
  345. PyTorch is a community-driven project with several skillful [engineers and researchers](https://docs.pytorch.org/docs/stable/community/persons_of_interest.html) contributing to it.
  346. Note: This project is unrelated to [hughperkins/pytorch](https://github.com/hughperkins/pytorch) with the same name. Hugh is a valuable contributor to the Torch community and has helped with many things Torch and PyTorch.
  347. ## License
  348. PyTorch has a BSD-style license, as found in the [LICENSE](LICENSE) file.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.