Forked from mhubii/A guide to install and use the PyTorch C++ API with Anaconda.md
Created
October 31, 2023 14:52
-
-
Save ludwig/e814b9c72183b313a4bbe5c13ffd43f5 to your computer and use it in GitHub Desktop.
Revisions
-
mhubii revised this gist
Mar 7, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) project(example) find_package(Torch REQUIRED) add_executable(main main.cpp) target_link_libraries(main ${TORCH_LIBRARIES}) set_property(TARGET main PROPERTY CXX_STANDARD 14) -
mhubii revised this gist
Mar 7, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) project(example) set(CMAKE_CXX_STANDARD 14) find_package(Torch REQUIRED) add_executable(main main.cpp) target_link_libraries(main ${TORCH_LIBRARIES}) -
mhubii revised this gist
Mar 7, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,7 +64,7 @@ Great you came this far, now lets see if everything worked well. Here is a minim ```shell mkdir build cd build cmake -DCMAKE_PREFIX_PATH="${HOME}/anaconda3/envs/py39_torch/lib/python3.9/site-packages/torch" .. make ``` * Run the example -
mhubii revised this gist
Mar 7, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,7 +64,7 @@ Great you came this far, now lets see if everything worked well. Here is a minim ```shell mkdir build cd build cmake -DCMAKE_PREFIX_PATH="${HOME}/anaconda3/envs/py39_torch/lib/python3.7/site-packages/torch" .. make ``` * Run the example -
mhubii revised this gist
Mar 7, 2022 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,24 +3,24 @@ The best way to get a clean installation of [PyTorch](https://pytorch.org/), is to install the pre-compiled binaries from the [Anaconda](https://www.anaconda.com/) distribution. Therefore, we need to setup Anaconda first. ## Step 1: Install Anaconda * Go to the [download section](https://www.anaconda.com/products/individual#Downloads) and download your desired Anaconda version for Linux <p align="center"><img src="https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png" width="70%" height="70%"></p> * Run the downloaded shell script and follow the install instruction, do ```shell cd ~/Downloads sh Anaconda3-2021.11-Linux-x86_64.sh # actual name depends on your download ``` ## Step 2: Setup an Environment * To keep things clean, now setup an environment for Anaconda, do ```shell conda create --name py39_torch python=3.9 # you can choose the name of the environment and the python version ``` * Activate the environment ```shell conda activate py39_torch ``` ## Step 3: Install PyTorch -
mhubii revised this gist
Jan 8, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -64,7 +64,7 @@ Great you came this far, now lets see if everything worked well. Here is a minim ```shell mkdir build cd build cmake -DCMAKE_PREFIX_PATH="${HOME}/anaconda3/envs/py37_torch/lib/python3.7/site-packages/torch" .. make ``` * Run the example -
mhubii revised this gist
Jun 13, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,12 +41,12 @@ conda install pytorch-cpu torchvision-cpu -c pytorch Sometimes you want to compile from source, due to specific dependencies for example. You can look up what to do [here](https://github.com/pytorch/pytorch). The main steps are * Get dependencies ```shell conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing ``` * In case you want to use CUDA on a GPU, **otherwise you can skip** ```shell # Add LAPACK support for the GPU if needed conda install -c pytorch magma-cuda90 # or [magma-cuda92 | magma-cuda100 ] depending on your cuda version ``` * Clone PyTorch from GitHub ```shell -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,14 +31,14 @@ There are **two different** ways on how to proceed. <p align="center"><img src="https://user-images.githubusercontent.com/26366414/54728267-22e5ee00-4b7d-11e9-8671-1e16ac8ac4d1.png" width="70%" height="70%"></p> * Run the proposed command, and **make sure your environment is activated** ```shell conda install pytorch-cpu torchvision-cpu -c pytorch ``` ### Install from Source Sometimes you want to compile from source, due to specific dependencies for example. You can look up what to do [here](https://github.com/pytorch/pytorch). The main steps are * Get dependencies ```shell conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -60,7 +60,7 @@ python setup.py install ``` ## Step 4: Link against libtorch.so Great you came this far, now lets see if everything worked well. Here is a minimal example, on how to link against the C++ API of Pytorch. * Build the example, the path depends on your installation. If you followed the previous steps, it should be ```shell mkdir build cd build -
mhubii renamed this gist
Mar 21, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mhubii revised this gist
Mar 21, 2019 . No changes.There are no files selected for viewing
-
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,11 +15,11 @@ sh Anaconda3-2018.12-Linux-x86_64.sh # actual name depends on your download ## Step 2: Setup an Environment * To keep things clean, now setup an environment for Anaconda, do ```shell conda create --name py37_torch python=3.7 # you can choose the name of the environment and the python version ``` * Activate the environment ```shell conda activate py37_torch ``` @@ -33,42 +33,42 @@ There are **two different** ways on how to proceed. * Run the proposed command, here ```shell conda install pytorch-cpu torchvision-cpu -c pytorch ``` ### Install from Source Sometime you want to compile from source, due to specific dependencies for example. You can look up what to do [here](https://github.com/pytorch/pytorch). The main steps are * Get dependencies ```shell conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing ``` * In case you want to use CUDA on a GPU, **otherwise you can skip** ```shell # Add LAPACK support for the GPU if needed conda install -c pytorch magma-cuda92 # or [magma-cuda80 | magma-cuda91] depending on your cuda version ``` * Clone PyTorch from GitHub ```shell git clone --recursive https://github.com/pytorch/pytorch cd pytorch ``` * Install PyTorch, **make sure your environment is activated** ```shell export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"} python setup.py install ``` ## Step 4: Link against libtorch.so Great you came this far, now lets see if everything worked well. Here is a minimal example, on how to link against the C++ API of Pytorch. * Build the example, the path depends on your installation. If you followed the previous step, it should be ```shell mkdir build cd build cmake -DCMAKE_PREFIX_PATH=${HOME}/anaconda3/envs/py37_torch/lib/python3.7/site-packages/torch" .. make ``` * Run the example ```shell ./main ``` Thats it! Hope it helped you. -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ conda activate py37_torch ## Step 3: Install PyTorch There are **two different** ways on how to proceed. ### Install pre-compiled Binaries * Go to [pytorch.org](https://pytorch.org/) and choose your desired settings like so <p align="center"><img src="https://user-images.githubusercontent.com/26366414/54728267-22e5ee00-4b7d-11e9-8671-1e16ac8ac4d1.png" width="70%" height="70%"></p> -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -59,4 +59,16 @@ export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"} python setup.py install ``` ## Step 4: Link against libtorch.so Great you came this far, now lets see if everything worked well. Here is a minimal example, on how to link against the C++ API of Pytorch. * Build the example, the path depends on your installation. If you followed the previous step, it should be ``` mkdir build cd build cmake -DCMAKE_PREFIX_PATH=${HOME}/anaconda3/envs/py37_torch/lib/python3.7/site-packages/torch" .. make ``` * Run the example ``` ./main ``` Thats it! Hope it helped you. -
mhubii revised this gist
Mar 21, 2019 . 3 changed files with 9 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ #include <torch/torch.h> int main() { torch::Tensor tensor = torch::zeros({2, 2}); std::cout << tensor << std::endl; return 0; } -
mhubii renamed this gist
Mar 21, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mhubii revised this gist
Mar 21, 2019 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) project(example) set(CMAKE_CXX_STANDARD 11) find_package(Torch REQUIRED) add_executable(main main.cpp) target_link_libraries(main ${TORCH_LIBRARIES}) -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ conda activate py37_torch ``` ## Step 3: Install PyTorch There are **two different** ways on how to proceed. ### Install Pre-Compiled Binaries * Go to [pytorch.org](https://pytorch.org/) and choose your desired settings like so @@ -59,4 +59,4 @@ export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"} python setup.py install ``` ## Step 4: Link against libtorch.so Great you came this far, now lets see if everything worked well. Here is a minimal example, on how to link against the C++ API of Pytorch. -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 14 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,8 +43,20 @@ Sometime you want to compile from source, due to specific dependencies for examp ``` conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing ``` * In case you want to use CUDA on a GPU, **otherwise you can skip** ``` # Add LAPACK support for the GPU if needed conda install -c pytorch magma-cuda92 # or [magma-cuda80 | magma-cuda91] depending on your cuda version ``` * Clone PyTorch from GitHub ``` git clone --recursive https://github.com/pytorch/pytorch cd pytorch ``` * Install PyTorch, **make sure your environment is activated** ``` export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"} python setup.py install ``` ## Step 4: Link against libtorch.so Great you came this far, now lets see if everything worked well. Here is a minimal example, on how to link against the C++ API of Pytorch -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 11 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,5 +37,14 @@ There are two different ways on how to proceed. conda install pytorch-cpu torchvision-cpu -c pytorch ``` ### Install from Source Sometime you want to compile from source, due to specific dependencies for example. You can look up what to do [here](https://github.com/pytorch/pytorch). The main steps are * Get dependencies ``` conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing ``` * In case you want to use CUDA on a GPU, *otherwise you can skip* ``` # Add LAPACK support for the GPU if needed conda install -c pytorch magma-cuda92 # or [magma-cuda80 | magma-cuda91] depending on your cuda version ``` -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 15 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,15 +14,28 @@ sh Anaconda3-2018.12-Linux-x86_64.sh # actual name depends on your download ``` ## Step 2: Setup an Environment * To keep things clean, now setup an environment for Anaconda, do ``` conda create --name py37_torch python=3.7 # you can choose the name of the environment and the python version ``` * Activate the environment ``` conda activate py37_torch ``` ## Step 3: Install PyTorch There are two different ways on how to proceed. ### Install Pre-Compiled Binaries * Go to [pytorch.org](https://pytorch.org/) and choose your desired settings like so <p align="center"><img src="https://user-images.githubusercontent.com/26366414/54728267-22e5ee00-4b7d-11e9-8671-1e16ac8ac4d1.png" width="70%" height="70%"></p> * Run the proposed command, here ``` conda install pytorch-cpu torchvision-cpu -c pytorch ``` ### Install from Source -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,3 +12,17 @@ The best way to get a clean installation of [PyTorch](https://pytorch.org/), is cd ~/Downloads sh Anaconda3-2018.12-Linux-x86_64.sh # actual name depends on your download ``` ## Step 2: Setup an Environment To keep things clean, now setup an environment for Anaconda, do ``` conda create --name py37_torch python=3.7 # you can choose the name of the environment and the python version ``` ## Step 3: Install PyTorch There are two different ways on how to proceed. ### Install Pre-Compiled Binaries Go to [pytorch.org](https://pytorch.org/) and choose your desired settings like so ### Install from Source -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,8 @@ The best way to get a clean installation of [PyTorch](https://pytorch.org/), is <p align="center"><img src="https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png" width="70%" height="70%"></p> * Run the downloaded shell script and follow the install instruction, do ```shell cd ~/Downloads sh Anaconda3-2018.12-Linux-x86_64.sh # actual name depends on your download ``` -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,4 +12,4 @@ The best way to get a clean installation of [PyTorch](https://pytorch.org/), is cd ~/Downloads sh Anaconda3-2018.12-Linux-x86_64.sh ``` Follow the install instructions there -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ The best way to get a clean installation of [PyTorch](https://pytorch.org/), is ## Step 1: Install Anaconda * Go to the [download section](https://www.anaconda.com/distribution/) and download your desired Anaconda version for Linux <p align="center"><img src="https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png" width="70%" height="70%"></p> * Run the downloaded shell script (the name of the script depends on your previous download), do ```shell -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ The best way to get a clean installation of [PyTorch](https://pytorch.org/), is ## Step 1: Install Anaconda * Go to the [download section](https://www.anaconda.com/distribution/) and download your desired Anaconda version for Linux <img src="https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png" width="70%" height="70%"> * Run the downloaded shell script (the name of the script depends on your previous download), do ```shell -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ The best way to get a clean installation of [PyTorch](https://pytorch.org/), is ## Step 1: Install Anaconda * Go to the [download section](https://www.anaconda.com/distribution/) and download your desired Anaconda version for Linux  * Run the downloaded shell script (the name of the script depends on your previous download), do ```shell -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,10 +4,12 @@ The best way to get a clean installation of [PyTorch](https://pytorch.org/), is ## Step 1: Install Anaconda * Go to the [download section](https://www.anaconda.com/distribution/) and download your desired Anaconda version for Linux  * Run the downloaded shell script (the name of the script depends on your previous download), do ```shell cd ~/Downloads sh Anaconda3-2018.12-Linux-x86_64.sh ``` -
mhubii revised this gist
Mar 21, 2019 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,4 +9,5 @@ The best way to get a clean installation of [PyTorch](https://pytorch.org/), is cd ~/Downloads sh Anaconda3-2018.12-Linux-x86_64.sh ``` 
NewerOlder