Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade libtorch v2.0.0 #108

Merged
merged 3 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(DOWNLOAD_DATASETS "Automatically download required datasets at build-time." ON)
option(CREATE_SCRIPTMODULES "Automatically create all required scriptmodule files at build-time (requires python3)." OFF)

set(PYTORCH_VERSION "1.13.1")
set(PYTORCH_VERSION "2.0.0")
set(PYTORCH_MIN_VERSION "1.12.0")

find_package(Torch QUIET PATHS "${CMAKE_SOURCE_DIR}/libtorch")
Expand All @@ -20,6 +20,11 @@ if((NOT Torch_FOUND) OR (("${Torch_VERSION}" VERSION_LESS "${PYTORCH_MIN_VERSION
endif()

message(STATUS "Torch version ${Torch_VERSION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()

if(CREATE_SCRIPTMODULES)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ RUN curl --silent --show-error --location --output ~/miniconda.sh https://repo.a

FROM conda AS conda-installs
# Install pytorch for CPU and torchvision.
ARG PYTORCH_VERSION=1.13.1
ARG TORCHVISION_VERSION=0.14.1
ARG PYTORCH_VERSION=2.0.0
ARG TORCHVISION_VERSION=0.15.1
ENV NO_CUDA=1
RUN conda install pytorch==${PYTORCH_VERSION} torchvision==${TORCHVISION_VERSION} cpuonly -y -c pytorch && conda clean -ya

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
C++ Implementation of PyTorch Tutorials for Everyone
<br />
<img src="https://img.shields.io/github/license/prabhuomkar/pytorch-cpp">
<img src="https://img.shields.io/badge/libtorch-1.13.1-ee4c2c">
<img src="https://img.shields.io/badge/libtorch-2.0.0-ee4c2c">
<img src="https://img.shields.io/badge/cmake-3.14-064f8d">
</p>


| OS (Compiler)\\LibTorch | 1.13.1 |
| OS (Compiler)\\LibTorch | 2.0.0 |
| :--------------------- | :--------------------------------------------------------------------------------------------------- |
| macOS (clang 11, 12, 13) | [![Status](https://github.com/prabhuomkar/pytorch-cpp/actions/workflows/build_macos.yml/badge.svg?branch=master)](https://github.com/prabhuomkar/pytorch-cpp/actions?query=workflow%3Aci-build-macos) |
| Linux (gcc 9, 10, 11) | [![Status](https://github.com/prabhuomkar/pytorch-cpp/actions/workflows/build_ubuntu.yml/badge.svg?branch=master)](https://github.com/prabhuomkar/pytorch-cpp/actions?query=workflow%3Aci-build-ubuntu) |
Expand Down Expand Up @@ -52,7 +52,7 @@ This repository provides tutorial code in C++ for deep learning researchers to l

1. [C++-17](http://www.cplusplus.com/doc/tutorial/introduction/) compatible compiler
2. [CMake](https://cmake.org/download/) (minimum version 3.14)
3. [LibTorch version >= 1.12.0 and <= 1.13.1](https://pytorch.org/cppdocs/installing.html)
3. [LibTorch version >= 1.12.0 and <= 2.0.0](https://pytorch.org/cppdocs/installing.html)
prabhuomkar marked this conversation as resolved.
Show resolved Hide resolved
4. [Conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html)


Expand Down Expand Up @@ -89,7 +89,7 @@ Some useful options:

| Option | Default | Description |
| :------------- |:------------|-----:|
| `-D CUDA_V=(11.6\|11.7\|none)` | `none` | Download LibTorch for a CUDA version (`none` = download CPU version). |
| `-D CUDA_V=(11.7\|11.8\|none)` | `none` | Download LibTorch for a CUDA version (`none` = download CPU version). |
| `-D LIBTORCH_DOWNLOAD_BUILD_TYPE=(Release\|Debug)` | `Release` | Determines which libtorch build type version to download (only relevant on **Windows**).|
| `-D DOWNLOAD_DATASETS=(OFF\|ON)` | `ON` | Download required datasets during build (only if they do not already exist in `pytorch-cpp/data`). |
|`-D CREATE_SCRIPTMODULES=(OFF\|ON)` | `OFF` | Create all required scriptmodule files for prelearned models / weights during build. Requires installed python3 with pytorch and torchvision. |
Expand All @@ -116,14 +116,14 @@ cmake -B build \
<summary><b>Example Windows</b></summary>

##### Aim
* Automatically download LibTorch for CUDA 11.7 (Release version) and all necessary datasets.
* Automatically download LibTorch for CUDA 11.8 (Release version) and all necessary datasets.
* Do not create scriptmodule files.

##### Command
```bash
cmake -B build \
-A x64 \
-D CUDA_V=11.7
-D CUDA_V=11.8
```
</details>

Expand Down
8 changes: 4 additions & 4 deletions cmake/fetch_libtorch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

include(FetchContent)

set(CUDA_V "none" CACHE STRING "Determines libtorch CUDA version to download (11.6, 11.7 or none).")
set(CUDA_V "none" CACHE STRING "Determines libtorch CUDA version to download (11.7, 11.8 or none).")

if(${CUDA_V} STREQUAL "none")
set(LIBTORCH_DEVICE "cpu")
elseif(${CUDA_V} STREQUAL "11.6")
set(LIBTORCH_DEVICE "cu116")
elseif(${CUDA_V} STREQUAL "11.7")
set(LIBTORCH_DEVICE "cu117")
elseif(${CUDA_V} STREQUAL "11.8")
set(LIBTORCH_DEVICE "cu118")
else()
message(FATAL_ERROR "Invalid CUDA version specified, must be 11.6, 11.7 or none!")
message(FATAL_ERROR "Invalid CUDA version specified, must be 11.7, 11.8 or none!")
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
Expand Down