pytorch源码编译安装

本文详细介绍如何在conda环境下从源码编译安装PyTorch,包括环境配置、依赖安装及编译步骤。适用于希望深入了解PyTorch内部结构或定制特定功能的开发者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • conda环境

安装conda环境,python 3.8以上,gcc支持9.4以上

conda install cmake ninja

conda install intel::mkl-static intel::mkl-include

#CUDA only: Add LAPACK support for the GPU if needed
conda install -c pytorch magma-cuda110  
#or the magma-cuda* that matches your CUDA version from https://anaconda.org/pytorch/repo

#(optional) If using torch.compile with inductor/triton, install the matching version of triton
#Run from the pytorch directory after cloning
make triton
  • 源码下载
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
#if you are updating an existing checkout
git submodule sync
git submodule update --init --recursive
  • 安装依赖
pip install -r requirements.txt
  • 安装命令

DEBUG=1是编译debug版本

export _GLIBCXX_USE_CXX11_ABI=1
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
DEBUG=1 USE_DISTRIBUTED=0 USE_MKLDNN=0 USE_CUDA=0 BUILD_TEST=0 USE_FBGEMM=0 USE_NNPACK=0 USE_QNNPACK=0 USE_XNNPACK=0 python setup.py develop

如果编译有问题,可以尝试执行

python setup.py clean
  • 更新代码,重新编译前执行:
git submodule sync
git submodule update --init --recursive
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值