Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ludwig/e814b9c72183b313a4bbe5c13ffd43f5 to your computer and use it in GitHub Desktop.
Save ludwig/e814b9c72183b313a4bbe5c13ffd43f5 to your computer and use it in GitHub Desktop.

Revisions

  1. @mhubii mhubii revised this gist Mar 7, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CMakeLists.txt
    Original 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})
    set_property(TARGET main PROPERTY CXX_STANDARD 14)
  2. @mhubii mhubii revised this gist Mar 7, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions CMakeLists.txt
    Original 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 11)
    set(CMAKE_CXX_STANDARD 14)

    find_package(Torch REQUIRED)

    add_executable(main main.cpp)
    target_link_libraries(main ${TORCH_LIBRARIES})
    target_link_libraries(main ${TORCH_LIBRARIES})
  3. @mhubii mhubii revised this gist Mar 7, 2022. 1 changed file with 1 addition and 1 deletion.
    Original 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" ..
    cmake -DCMAKE_PREFIX_PATH="${HOME}/anaconda3/envs/py39_torch/lib/python3.9/site-packages/torch" ..
    make
    ```
    * Run the example
  4. @mhubii mhubii revised this gist Mar 7, 2022. 1 changed file with 1 addition and 1 deletion.
    Original 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" ..
    cmake -DCMAKE_PREFIX_PATH="${HOME}/anaconda3/envs/py39_torch/lib/python3.7/site-packages/torch" ..
    make
    ```
    * Run the example
  5. @mhubii mhubii revised this gist Mar 7, 2022. 1 changed file with 4 additions and 4 deletions.
    Original 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/distribution/) and download your desired Anaconda version for Linux
    * 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-2018.12-Linux-x86_64.sh # actual name depends on your download
    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 py37_torch python=3.7 # you can choose the name of the environment and the python version
    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 py37_torch
    conda activate py39_torch
    ```

    ## Step 3: Install PyTorch
  6. @mhubii mhubii revised this gist Jan 8, 2020. 1 changed file with 1 addition and 1 deletion.
    Original 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" ..
    cmake -DCMAKE_PREFIX_PATH="${HOME}/anaconda3/envs/py37_torch/lib/python3.7/site-packages/torch" ..
    make
    ```
    * Run the example
  7. @mhubii mhubii revised this gist Jun 13, 2019. 1 changed file with 2 additions and 2 deletions.
    Original 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 pyyaml mkl mkl-include setuptools cmake cffi typing
    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-cuda92 # or [magma-cuda80 | magma-cuda91] depending on your cuda version
    conda install -c pytorch magma-cuda90 # or [magma-cuda92 | magma-cuda100 ] depending on your cuda version
    ```
    * Clone PyTorch from GitHub
    ```shell
  8. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 2 additions and 2 deletions.
    Original 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, here
    * Run the proposed command, and **make sure your environment is activated**

    ```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
    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
  9. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 1 addition and 1 deletion.
    Original 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 step, it should be
    * Build the example, the path depends on your installation. If you followed the previous steps, it should be
    ```shell
    mkdir build
    cd build
  10. @mhubii mhubii renamed this gist Mar 21, 2019. 1 changed file with 0 additions and 0 deletions.
  11. @mhubii mhubii revised this gist Mar 21, 2019. No changes.
  12. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions a_guide.md
    Original 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.
  13. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion a_guide.md
    Original 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
    ### 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>
  14. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion a_guide.md
    Original 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.
    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.
  15. @mhubii mhubii revised this gist Mar 21, 2019. 3 changed files with 9 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    9 changes: 9 additions & 0 deletions main.cpp
    Original 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;
    }
  16. @mhubii mhubii renamed this gist Mar 21, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  17. @mhubii mhubii revised this gist Mar 21, 2019. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  18. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions CMakeLists.txt
    Original 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})
  19. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions guide.md
    Original 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.
    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
    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.
  20. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions guide.md
    Original 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*
    * 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
  21. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions guide.md
    Original 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
    ### 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
    ```
  22. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 15 additions and 2 deletions.
    17 changes: 15 additions & 2 deletions guide.md
    Original 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
    * 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
    * 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
  23. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions guide.md
    Original 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
  24. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions guide.md
    Original 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 (the name of the script depends on your previous download), do
    * Run the downloaded shell script and follow the install instruction, do
    ```shell
    cd ~/Downloads
    sh Anaconda3-2018.12-Linux-x86_64.sh
    sh Anaconda3-2018.12-Linux-x86_64.sh # actual name depends on your download
    ```
    Follow the install instructions there
  25. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion guide.md
    Original 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
  26. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion guide.md
    Original 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%">
    <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
  27. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion guide.md
    Original 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

    ![download_anaconda](https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png | width=100)
    <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
  28. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion guide.md
    Original 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

    ![download_anaconda](https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png)
    ![download_anaconda](https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png | width=100)

    * Run the downloaded shell script (the name of the script depends on your previous download), do
    ```shell
  29. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion guide.md
    Original 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

    ![download_anaconda](https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png)

    * 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
    ```
    ![download_anaconda](https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png)

  30. @mhubii mhubii revised this gist Mar 21, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion guide.md
    Original 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
    ```
    ![]
    ![download_anaconda](https://user-images.githubusercontent.com/26366414/54727908-ceda0a00-4b7a-11e9-858e-6bb07a1a64e4.png)