Skip to content

Commit f60fb25

Browse files
authored
Require torch 0.14.0 (#22)
* Require torch 0.14.0 * update actions * Bump version * Include fstream * Bump cuda * Use macos 13 for intel MAcOS * Bump vision version + ignore rtools 44 * jimver version * make cuda toolkit required * use recent cmake * check nvtx found * Try this out * Try downloading nvtx * Download the correct branch * try cloning into a different directory * Try another directory * Dowgrade to cuda 11.8 * Try another workaraound * Try patching torchvision CmakeLists * Make sure with cuda is specified. * try downloading the the project source dir * Maybe apply only this patch * Go back to CUDA 11.8 * Apply patch to fix at::kuint16 not found. * use CMAKE_SOURCE_DIR * try again * use torck kU6 * try importing types * Use a different patch * try c10 version * Remove usage of kuint16 on linux/cuda * Improve patch * Add some more packages to install list * Use cpu macOS * Drop R 3.6 * ++ * set a cmake version * Set ro 3.31 - last that passed
1 parent 9ca7190 commit f60fb25

File tree

7 files changed

+89
-21
lines changed

7 files changed

+89
-21
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
config:
25-
- {runner: macOS-latest, r_version: release, os: macOS}
25+
- {runner: macOS-13, r_version: release, os: macOS}
2626
- {runner: [self-hosted, m1], r_version: '', os: macOS}
2727
- {runner: windows-2019, r_version: release, os: windows}
2828
- {runner: ubuntu-latest, r_version: release, os: ubuntu}
29-
- {runner: [self-hosted, linux], r_version: release, os: ubuntu, cuda: 11.7, cuda_patch: 0}
30-
- {runner: windows-2019, r_version: release, os: windows, cuda: 11.7, cuda_patch: 0}
29+
- {runner: [self-hosted, linux], r_version: release, os: ubuntu, cuda: 11.8, cuda_patch: 0}
30+
- {runner: windows-2019, r_version: release, os: windows, cuda: 11.8, cuda_patch: 0}
3131

3232
include:
3333
- config: {os: ubuntu}
@@ -58,12 +58,12 @@ jobs:
5858
DRY_RUN=1 sh ./get-docker.sh
5959
6060
- name: Setup cmake
61-
uses: jwlawson/actions-setup-cmake@v1
61+
uses: jwlawson/actions-setup-cmake@v2
6262
with:
63-
cmake-version: '3.25.2'
63+
cmake-version: '3.31'
6464

6565
- if: ${{matrix.config.cuda != ''}}
66-
uses: Jimver/cuda-toolkit@v0.2.8
66+
uses: Jimver/cuda-toolkit@v0.2.21
6767
id: cuda-toolkit
6868
with:
6969
cuda: '${{matrix.config.cuda}}.${{matrix.config.cuda_patch}}'
@@ -76,8 +76,8 @@ jobs:
7676

7777
- name: Install dependencies
7878
run: |
79-
Rscript -e "install.packages(c('remotes', 'desc', 'rcmdcheck'))"
80-
Rscript -e "remotes::install_github('mlverse/torchexport')"
79+
Rscript -e "install.packages(c('remotes', 'desc', 'rcmdcheck', 'hms'))"
80+
Rscript -e "remotes::install_github('mlverse/torchexport', force = TRUE)"
8181
8282
- run: |
8383
cd csrc
@@ -102,7 +102,7 @@ jobs:
102102
file_glob: true
103103
tag: v${{ steps.version.outputs.version }}
104104

105-
- uses: actions/upload-artifact@v3
105+
- uses: actions/upload-artifact@v4
106106
with:
107107
name: ${{ steps.version.outputs.fname }}
108108
path: csrc/build/*.zip
@@ -117,10 +117,9 @@ jobs:
117117
fail-fast: false
118118
matrix:
119119
config:
120-
- {os: mac, runner: macOS-latest, r: 'release', artifact: '+cpu+x86_64-Darwin.zip'}
120+
- {os: mac, runner: macOS-13, r: 'release', artifact: '+cpu+x86_64-Darwin.zip'}
121121
- {os: m1mac, runner: ['self-hosted', 'm1'], artifact: '+cpu+arm64-Darwin.zip'}
122122
- {os: windows, runner: windows-latest, r: 'release', rtools: '42', artifact: '+cpu-win64.zip'}
123-
- {os: windows, runner: windows-latest, r: '3.6', artifact: '+cpu-win64.zip'}
124123
- {os: ubuntu, runner: ubuntu-20.04, r: 'release', artifact: '+cpu-Linux.zip'}
125124

126125
env:
@@ -157,7 +156,7 @@ jobs:
157156
version=$(Rscript -e "cat(as.character(desc::desc_get_version()))")
158157
echo "::set-output name=version::$version"
159158
160-
- uses: actions/download-artifact@v3
159+
- uses: actions/download-artifact@v4
161160
with:
162161
name: 'torchvisionlib-${{ steps.version.outputs.version }}${{ matrix.config.artifact }}'
163162
path: build/

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: torchvisionlib
22
Title: Additional Operators for Image Models
3-
Version: 0.5.0.9000
3+
Version: 0.6.0
44
Authors@R: c(
55
person("Daniel", "Falbel", , "daniel@rstudio.com", role = c("aut", "cre")),
66
person(family = "RStudio", role = c("cph"))
@@ -19,7 +19,7 @@ LinkingTo:
1919
torch
2020
Imports:
2121
Rcpp,
22-
torch (>= 0.9.0),
22+
torch (>= 0.14.0),
2323
rlang,
2424
glue,
2525
withr

csrc/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ message(STATUS "TORCH_HOME=${TORCH_HOME}")
4141

4242
if (DEFINED ENV{CUDA} AND NOT '$ENV{CUDA}' STREQUAL '')
4343
if (WIN32)
44-
find_package(CUDAToolkit)
44+
find_package(CUDAToolkit REQUIRED)
45+
else()
46+
set(PATCH_CMD git apply ${CMAKE_SOURCE_DIR}/patch/kuint16.patch || true)
4547
endif()
4648
enable_language(CUDA)
4749
endif()
@@ -64,13 +66,13 @@ if(WIN32)
6466
GIT_TAG v1.6.37
6567
DEPENDS zlib
6668
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libpng"
67-
CMAKE_ARGS ${COMMON_CMAKE_ARGS} -DCMAKE_IGNORE_PATH=C:/rtools40/ucrt64/include -DCMAKE_IGNORE_PATH=C:/rtools43/x86_64-w64-mingw32.static.posix/include -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH};${CURRENT_BINARY_DIR}/lib
69+
CMAKE_ARGS ${COMMON_CMAKE_ARGS} -DCMAKE_IGNORE_PATH=C:/rtools44/x86_64-w64-mingw32.static.posix/include -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH};${CURRENT_BINARY_DIR}/lib
6870
)
6971
ExternalProject_Add(libjpeg
7072
GIT_REPOSITORY https://github.com/libjpeg-turbo/libjpeg-turbo
7173
GIT_TAG 2.1.2
7274
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libjpeg"
73-
CMAKE_ARGS ${COMMON_CMAKE_ARGS} -DWITH_JPEG8=0 -DWITH_JPEG7=0 -DENABLE_SHARED=0 -DWITH_TURBOJPEG=0-DCMAKE_IGNORE_PATH=C:/rtools43/x86_64-w64-mingw32.static.posix/include
75+
CMAKE_ARGS ${COMMON_CMAKE_ARGS} -DWITH_JPEG8=0 -DWITH_JPEG7=0 -DENABLE_SHARED=0 -DWITH_TURBOJPEG=0 -DCMAKE_IGNORE_PATH=C:/rtools44/x86_64-w64-mingw32.static.posix/include
7476
)
7577
endif()
7678

@@ -85,22 +87,25 @@ set(TORCHVISION_CMAKE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH})
8587
list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${TorchVision_DESTDIR})
8688

8789
if(WIN32)
88-
list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_IGNORE_PREFIX_PATH:PATH=C:/rtools43/x86_64-w64-mingw32.static.posix/)
90+
list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_IGNORE_PREFIX_PATH:PATH=C:/rtools44/x86_64-w64-mingw32.static.posix/)
91+
if (DEFINED ENV{CUDA} AND NOT '$ENV{CUDA}' STREQUAL '')
92+
list(APPEND TORCHVISION_CMAKE_ARGS -DWITH_CUDA=ON)
93+
endif()
94+
8995
elseif(APPLE)
9096
list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_FIND_FRAMEWORK:STRING=LAST)
9197
endif()
9298

9399
if (WIN32)
94100
set(TORCHVISION_DEPENDS libpng libjpeg)
95-
set(PATCH_CMD git apply ${CMAKE_SOURCE_DIR}/patch/jpeg_types.diff || true)
96101
else()
97102
set(TORCHVISION_DEPENDS)
98103
endif()
99104

100105
message(STATUS "CMAKE_ARGS: ${TORCHVISION_CMAKE_ARGS}")
101106
ExternalProject_Add(TorchVision-project
102107
GIT_REPOSITORY https://github.com/pytorch/vision
103-
GIT_TAG v0.15.2
108+
GIT_TAG v0.20.1
104109
DEPENDS ${TORCHVISION_DEPENDS}
105110
CMAKE_CACHE_ARGS ${TORCHVISION_CMAKE_ARGS}
106111
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libtorchvision"

csrc/patch/kuint16.patch

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
diff --git a/torchvision/csrc/io/image/cpu/decode_png.cpp b/torchvision/csrc/io/image/cpu/decode_png.cpp
2+
index ede14c1e94..a42bd06c35 100644
3+
--- a/torchvision/csrc/io/image/cpu/decode_png.cpp
4+
+++ b/torchvision/csrc/io/image/cpu/decode_png.cpp
5+
@@ -195,9 +195,13 @@ torch::Tensor decode_png(
6+
7+
auto num_pixels_per_row = width * channels;
8+
auto is_16_bits = bit_depth == 16;
9+
+
10+
+ if (is_16_bits) {
11+
+ throw std::runtime_error("16-bit PNG images are not supported.");
12+
+ }
13+
+
14+
auto tensor = torch::empty(
15+
- {int64_t(height), int64_t(width), channels},
16+
- is_16_bits ? at::kUInt16 : torch::kU8);
17+
+ {int64_t(height), int64_t(width), channels}, torch::kU8);
18+
if (is_little_endian()) {
19+
png_set_swap(png_ptr);
20+
}
21+
diff --git a/torchvision/csrc/ops/nms.cpp b/torchvision/csrc/ops/nms.cpp
22+
index 5ecf8812f1..2cbbe93873 100644
23+
--- a/torchvision/csrc/ops/nms.cpp
24+
+++ b/torchvision/csrc/ops/nms.cpp
25+
@@ -18,11 +18,5 @@ at::Tensor nms(
26+
return op.call(dets, scores, iou_threshold);
27+
}
28+
29+
-TORCH_LIBRARY_FRAGMENT(torchvision, m) {
30+
- m.set_python_module("torchvision._meta_registrations");
31+
- m.def(TORCH_SELECTIVE_SCHEMA(
32+
- "torchvision::nms(Tensor dets, Tensor scores, float iou_threshold) -> Tensor"));
33+
-}
34+
-
35+
} // namespace ops
36+
} // namespace vision

csrc/patch/nvtx_workaround.diff

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index f243055990..04b06e8335 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -15,6 +15,21 @@ option(WITH_WEBP "Enable features requiring LibWEBP." OFF)
6+
option(WITH_AVIF "Enable features requiring LibAVIF." OFF)
7+
8+
if(WITH_CUDA)
9+
+ if (WIN32)
10+
+ find_package(CUDAToolkit REQUIRED)
11+
+ message(STATUS "PyTorch NVTX headers workaround: Yes")
12+
+ # only do this if nvToolsExt is not defined and CUDA::nvtx3 exists
13+
+ if(NOT TARGET CUDA::nvToolsExt AND TARGET CUDA::nvtx3)
14+
+ add_library(CUDA::nvToolsExt INTERFACE IMPORTED)
15+
+ # ensure that PyTorch is told to use NVTX3 headers
16+
+ target_compile_definitions(
17+
+ CUDA::nvToolsExt INTERFACE
18+
+ TORCH_CUDA_USE_NVTX3
19+
+ )
20+
+ target_link_libraries(CUDA::nvToolsExt INTERFACE CUDA::nvtx3)
21+
+ endif()
22+
+ endif()
23+
+
24+
enable_language(CUDA)
25+
add_definitions(-D__CUDA_NO_HALF_OPERATORS__)
26+
add_definitions(-DWITH_CUDA)

csrc/src/ops.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <lantern/types.h>
22
#include <string>
33
#include <iostream>
4+
#include <fstream>
45
#include <torch/torch.h>
56
#include <torchvision/ops/ops.h>
67
#include <torchvision/io/image/cpu/decode_jpeg.h>
@@ -137,4 +138,4 @@ torch::Tensor vision_read_jpeg(std::string fpath) {
137138
torch::Tensor vision_read_jpeg_float(std::string fpath) {
138139
auto ten = vision_read_jpeg(fpath);
139140
return ten.to(torch::kFloat32).div_(255);
140-
}
141+
}

torchvisionlib.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: 50cea1d2-7be8-442b-aab8-9fd02d267af7
23

34
RestoreWorkspace: No
45
SaveWorkspace: No

0 commit comments

Comments
 (0)