{"id":153,"date":"2025-03-01T00:00:37","date_gmt":"2025-02-28T16:00:37","guid":{"rendered":"https:\/\/void-tech.cn\/?p=153"},"modified":"2025-03-21T00:06:23","modified_gmt":"2025-03-20T16:06:23","slug":"build-torch-from-source","status":"publish","type":"post","link":"https:\/\/void-tech.cn\/index.php\/2025\/03\/01\/build-torch-from-source\/","title":{"rendered":"\u4ece\u6e90\u6784\u5efa PyTorch"},"content":{"rendered":"<p><!--more-->build torch2.1.2 for cuda11.4, python3.8<\/p>\n<p><a href=\"https:\/\/void-tech.cn\/wp-content\/uploads\/2025\/03\/torch-2.1.2cu114-cp38-cp38-win_amd64.whl\">torch-2.1.2+cu114-cp38-cp38-win_amd64.whl<\/a><\/p>\n<p><a href=\"https:\/\/void-tech.cn\/wp-content\/uploads\/2025\/03\/torch-2.1.2cu114-cp38-cp38-linux_x86_64.whl\">torch-2.1.2+cu114-cp38-cp38-linux_x86_64.whl<\/a><\/p>\n<p><a href=\"https:\/\/void-tech.cn\/wp-content\/uploads\/2025\/03\/torch-2.1.2cu114-cp38-cp38-linux_aarch64.whl\">torch-2.1.2+cu114-cp38-cp38-linux_aarch64.whl<\/a><\/p>\n<p><a href=\"https:\/\/void-tech.cn\/wp-content\/uploads\/2025\/03\/torch-2.1.2cu114.tegra-cp38-cp38-linux_aarch64.whl\">torch-2.1.2+cu114.tegra-cp38-cp38-linux_aarch64<\/a><\/p>\n<p>&#8212;&#8212;&#8212;-<br \/>\nLinux environment:<br \/>\ndocker container from <span style=\"background-color: #f5f5f5; font-family: Consolas, Monaco, monospace;\">nvcr.io\/nvidia\/cuda:11.4.2-cudnn8-devel-ubuntu20.04<\/span><\/p>\n<pre class=\"code\"># install dependence\r\napt update &amp;&amp; apt install -y --no-install-recommends git pkg-config curl python3 python3-pip python3-dev build-essential libjpeg-dev\r\npip3 install numpy==1.22.2 scipy==1.10.1 pyyaml==6.0.1 pandas==1.5.3 onnx==1.14.0 triton==2.1.0 transformers==4.30.2 cmake ninja\r\n\r\ncurl -fkLO https:\/\/nchc.dl.sourceforge.net\/project\/libpng\/zlib\/1.2.11\/zlib-1.2.11.tar.gz &amp;&amp; tar -zxvf *.gz &amp;&amp; rm *.gz\r\ncurl -fkLO https:\/\/jaist.dl.sourceforge.net\/project\/libpng\/libpng16\/1.6.44\/libpng-1.6.44.tar.gz &amp;&amp; tar -zxvf *.gz &amp;&amp; rm *.gz\r\ncd zlib-1.2.11 &amp;&amp; make &amp;&amp; make install &amp;&amp; cd ..\/libpng-1.6.44 &amp;&amp; .\/configure &amp;&amp; make &amp;&amp; make install &amp;&amp; cd ..<\/pre>\n<pre class=\"code\"># build torch\r\nexport TORCH_CUDA_ARCH_LIST=\"3.5;3.7;5.0;5.2;6.0;6.1;7.0;7.5;8.0;8.6\"\r\nexport PYTORCH_BUILD_VERSION=2.1.2+cu114\r\nexport PYTORCH_BUILD_NUMBER=0\r\n\r\n# build for Tegra\r\n# export TORCH_CUDA_ARCH_LIST=\"7.2;8.7\"\r\n# export USE_CUDNN=0\r\n\r\ngit clone --recursive -b v2.1.2 https:\/\/github.com\/pytorch\/pytorch.git &amp;&amp; cd pytorch\r\npython3 setup.py bdist_wheel install<\/pre>\n<pre class=\"code\"># build torchvision\r\nexport PYTORCH_VERSION=2.1.2+cu114\r\nexport TORCHVISION_USE_PNG=1\r\nexport TORCHVISION_USE_JPEG=1\r\nexport TORCHVISION_USE_NVJPEG=1\r\nexport BUILD_VERSION=0.16.2+cu114\r\n\r\ngit clone --recursive -b v0.16.2 https:\/\/github.com\/pytorch\/vision.git &amp;&amp; cd vision\r\npython3 setup.py bdist_wheel<\/pre>\n<pre class=\"code\"># build torchaudio\r\nexport PYTORCH_VERSION=2.1.2+cu114\r\nexport BUILD_VERSION=2.1.2+cu114\r\n\r\ngit clone --recursive -b v2.1.2 https:\/\/github.com\/pytorch\/audio.git &amp;&amp; cd audio\r\npython3 setup.py bdist_wheel<\/pre>\n<p>&#8212;&#8212;&#8212;-<br \/>\nWindows environment:<br \/>\nWindows Server 2022; Visual Studio 2019; CUDA Toolkit 11.4.2; cuDNN 8.2.4.15; python 3.8.10; cmake<\/p>\n<pre class=\"code\"># install dependence\r\npip install wheel numpy==1.22.2 scipy==1.10.1 pyyaml==6.0.1 pandas==1.5.3 onnx==1.14.0 transformers==4.30.2 mkl ninja sympy<\/pre>\n<pre class=\"code\"># build torch\r\nset \"VS150COMNTOOLS=%PROGRAMFILES(x86)%\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\"\r\nset CMAKE_GENERATOR=Visual Studio 16 2019\r\nset DISTUTILS_USE_SDK=1\r\nset CMAKE_GENERATOR=Ninja\r\nset USE_CUDA=1\r\nset USE_CUDNN=1\r\nset CUDNN_INCLUDE_DIR=\"%PROGRAMFILES%\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.4\\include\"\r\nset TORCH_CUDA_ARCH_LIST=Kepler;Maxwell;Pascal;Volta;Turing;Ampere\r\nset PYTORCH_BUILD_VERSION=2.1.2+cu114\r\nset PYTORCH_BUILD_NUMBER=0\r\ncall \"%VS150COMNTOOLS%\\vcvarsall.bat\" x64\r\n\r\ngit clone --recursive -b v2.1.2 https:\/\/github.com\/pytorch\/pytorch.git &amp;&amp; cd pytorch\r\npython setup.py bdist_wheel<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-share"],"_links":{"self":[{"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":6,"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":185,"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/posts\/153\/revisions\/185"}],"wp:attachment":[{"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/void-tech.cn\/index.php\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}