Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Build PyTorch and LibTorch on Windows ARM64

Ozan Aydin edited this pageJan 30, 2025 ·2 revisions

Building for Windows on ARM64

  1. Prerequisites
  2. Cloning PyTorch
  3. Preparing Environment
  4. Setting Environment Variables
  5. Build
    1. PyTorch
    2. LibTorch

Prerequisites

  1. Build Tools for Visual Studio 2022OR any version ofVisual Studio 2022

    • UnderWorkloads, selectDesktop development with C++

    • UnderIndividual Components, selectARM64/ARM64EC build tools (latest)

  2. Python 3.12 Windows installer (ARM64)

  3. Download and installArm Performance Libraries for Windows

    • %ARMPL_DIR% environment variable should be automatically added to yourPATH by default installation settings.
  4. InstallRust

  5. Buildinglibuv (v1.39.0) from source (we'll use the folder path inBuild)

    • OpenARM64 Native Tools Command Prompt for VS2022 from start menu
    • Change path to the suitable folder
    • Run following command to buildlibuv
    git clone https://github.com/libuv/libuv.git -b v1.39.0cd libuvecho Clean folder...git clean -fxdecho Configuring libuv...mkdir libuv\buildcd libuv\buildcmake .. -DBUILD_TESTING=OFFecho Building libuv...cmake --build . --config Releaseecho Installing libuv...cmake --install . --prefix ../installpause
  6. (OPTIONAL) You may installsccache for speeding up future builds by cache support.

    • You need to addsccache to yourPATHmanually.

Cloning PyTorch

  1. Clone the PyTorch repository (or your fork)

    git clone --recursive https://github.com/pytorch/pytorchcd pytorch
  2. Init and sync submodules

    git submodule syncgit submodule update --init --recursive

Preparing Environment

NOTE: Since currentlycondadoesn't support Windows ARM64, instead we're recommending to use built-in Pythonvenv functionality for similar isolating experience. (more info)

  1. Creating a virtual environment (venv)

    python -m pip install --upgrade pippython -m venv .venvecho *> .venv\.gitignorecall .\.venv\Scripts\activate
  2. Install requirements

    pip install -r requirements.txt
  3. ActivateArm64 Native Tools Command Prompt for VS 2022 environment by calling one of the following commands based on what you've installed.

    • For Build Tools:

      "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" arm64

    • For Visual Studio 2022 Community:

      "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" arm64

    • For Visual Studio 2022 Enterprise:

      "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" arm64

    • For Visual Studio 2022 Preview:

      "C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\Build\vcvarsarm64.bat" arm64

Setting Environment Variables

  1. Set the following environment variables:

    setBLAS=APLsetUSE_LAPACK=1setMSSdk=1setDISTUTILS_USE_SDK=1:: please change {YOUR_LIBUV_FOLDER} to the your libuv foldersetlibuv_ROOT={YOUR_LIBUV_FOLDER}\install
  2. Copylibuv dll to thelib folder to include it for packaging (please check:Prerequisites)

    copy%libuv_ROOT%\lib\Release\uv.dll torch\lib\uv.dll
  3. (OPTIONAL) If you want to usesccache for speeding up your future build by cache also set following.

    setCMAKE_C_COMPILER_LAUNCHER=sccachesetCMAKE_CXX_COMPILER_LAUNCHER=sccache

Build

You can generate a.whl (wheel) file forPyTorch (the Python package)OR a.zip file forLibTorch (the C++ core). If you'd like to use PyTorch right away without creating a wheel file, you can build it directly in your environment. Here are your options:

PyTorch

  1. OPTION 1 - Generating and Installing Wheel File (for distribution or installation on other systems):

    Call following command to start build and generate output

    :: set PYTORCH_BUILD_VERSION=2.6.0   ## OPTIONAL: If you wish to give a specific versioning for `.whl` file :: set PYTORCH_BUILD_NUMBER=1        ## (for instance you can specify 2.6.0 as shown) python setup.py bdist_wheel

    Output file will be underdist folder with.whl extension.

    Format will look liketorch-FOO+gitBAR-cp312-cp312-win_arm64.whlOR if you specify version, format will be liketorch-2.6.0-cp312-cp312-win_arm64.whl

    Now you can copy and install this.whl file anywhere in your system by calling

    pip install torch-YOURVERSION-cp312-cp312-win_arm64.whl
  2. OPTION 2 - Directly Installing to Local Environment (for development on your system only)

    Run one of the following commands to initiate the build:

    • Install the package in development mode, ideal when making frequent changes to codebase
    python setup.py develop
    • Install the package for regular use, rather than ongoing development
    python setup.py install

LibTorch

  1. Additional preparation forlibtorch folder

    :: Options: Release, Debug or RelWithDebInfosetCMAKE_BUILD_TYPE=Release:: Prepare the environmentmkdir libtorchmkdir libtorch\binmkdir libtorch\cmakemkdir libtorch\includemkdir libtorch\libmkdir libtorch\sharemkdir libtorch\test
  2. Call following command to start build and generate output

    python ./tools/build_libtorch.py
  3. Prepare.zip file fromlibtorch output

    :: Moving the files to the correct locationmove /Y torch\bin\*.* libtorch\bin\move /Y torch\cmake\*.* libtorch\cmake\robocopy /move /e torch\include\ libtorch\include\move /Y torch\lib\*.* libtorch\lib\robocopy /move /e torch\share\ libtorch\share\move /Y torch\test\*.* libtorch\test\move /Y libtorch\bin\*.dll libtorch\lib\:: Create output under distmkdir disttar -cvaf dist/libtorch-win.zip -C libtorch *:: Cleanup raw data to save spacermdir /s /q libtorch
  4. Now you can copy and extractdist/libtorch-win.zip file anywhere in your system

I would love to contribute to PyTorch!

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp