Skip to content
New issue

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

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

Already on GitHub? # to your account

Require torch 0.14.0 #22

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ba1d01b
Require torch 0.14.0
dfalbel Jan 31, 2025
9911ebf
update actions
dfalbel Jan 31, 2025
bf26801
Bump version
dfalbel Jan 31, 2025
8f633fd
Include fstream
dfalbel Jan 31, 2025
9a0c9e8
Bump cuda
dfalbel Jan 31, 2025
3b3514e
Use macos 13 for intel MAcOS
dfalbel Jan 31, 2025
63ffaaa
Bump vision version + ignore rtools 44
dfalbel Jan 31, 2025
fef13a7
jimver version
dfalbel Jan 31, 2025
6e64e84
make cuda toolkit required
dfalbel Jan 31, 2025
fcf93b6
use recent cmake
dfalbel Jan 31, 2025
d731ca4
check nvtx found
dfalbel Jan 31, 2025
c1dfe3d
Try this out
dfalbel Jan 31, 2025
d0326cd
Try downloading nvtx
dfalbel Jan 31, 2025
73a3d7d
Download the correct branch
dfalbel Jan 31, 2025
c041e34
try cloning into a different directory
dfalbel Jan 31, 2025
fecc8f9
Try another directory
dfalbel Jan 31, 2025
6e380ed
Dowgrade to cuda 11.8
dfalbel Jan 31, 2025
74cb673
Try another workaraound
dfalbel Jan 31, 2025
546abc3
Try patching torchvision CmakeLists
dfalbel Jan 31, 2025
cf94b67
Make sure with cuda is specified.
dfalbel Jan 31, 2025
6a1ed98
try downloading the the project source dir
dfalbel Jan 31, 2025
395b406
Maybe apply only this patch
dfalbel Feb 1, 2025
c48498a
Go back to CUDA 11.8
dfalbel Feb 4, 2025
e75c69c
Apply patch to fix at::kuint16 not found.
dfalbel Feb 5, 2025
f69cce7
use CMAKE_SOURCE_DIR
dfalbel Feb 5, 2025
0efb739
try again
dfalbel Feb 5, 2025
bdb85e8
use torck kU6
dfalbel Feb 5, 2025
b7cdfa4
try importing types
dfalbel Feb 5, 2025
9c4eb18
Use a different patch
dfalbel Feb 5, 2025
e6e1cce
try c10 version
dfalbel Feb 5, 2025
71571be
Remove usage of kuint16 on linux/cuda
dfalbel Feb 5, 2025
b0ca02d
Improve patch
dfalbel Feb 5, 2025
f632209
Add some more packages to install list
dfalbel Feb 5, 2025
53c04bb
Use cpu macOS
dfalbel Feb 5, 2025
4a75d9d
Drop R 3.6
dfalbel Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
fail-fast: false
matrix:
config:
- {runner: macOS-latest, r_version: release, os: macOS}
- {runner: macOS-13, r_version: release, os: macOS}
- {runner: [self-hosted, m1], r_version: '', os: macOS}
- {runner: windows-2019, r_version: release, os: windows}
- {runner: ubuntu-latest, r_version: release, os: ubuntu}
- {runner: [self-hosted, linux], r_version: release, os: ubuntu, cuda: 11.7, cuda_patch: 0}
- {runner: windows-2019, r_version: release, os: windows, cuda: 11.7, cuda_patch: 0}
- {runner: [self-hosted, linux], r_version: release, os: ubuntu, cuda: 11.8, cuda_patch: 0}
- {runner: windows-2019, r_version: release, os: windows, cuda: 11.8, cuda_patch: 0}

include:
- config: {os: ubuntu}
Expand Down Expand Up @@ -58,12 +58,12 @@ jobs:
DRY_RUN=1 sh ./get-docker.sh

- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.25.2'
cmake-version: 'latest'

- if: ${{matrix.config.cuda != ''}}
uses: Jimver/cuda-toolkit@v0.2.8
uses: Jimver/cuda-toolkit@v0.2.21
id: cuda-toolkit
with:
cuda: '${{matrix.config.cuda}}.${{matrix.config.cuda_patch}}'
Expand All @@ -76,8 +76,8 @@ jobs:

- name: Install dependencies
run: |
Rscript -e "install.packages(c('remotes', 'desc', 'rcmdcheck'))"
Rscript -e "remotes::install_github('mlverse/torchexport')"
Rscript -e "install.packages(c('remotes', 'desc', 'rcmdcheck', 'hms'))"
Rscript -e "remotes::install_github('mlverse/torchexport', force = TRUE)"

- run: |
cd csrc
Expand All @@ -102,7 +102,7 @@ jobs:
file_glob: true
tag: v${{ steps.version.outputs.version }}

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

env:
Expand Down Expand Up @@ -157,7 +156,7 @@ jobs:
version=$(Rscript -e "cat(as.character(desc::desc_get_version()))")
echo "::set-output name=version::$version"

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: 'torchvisionlib-${{ steps.version.outputs.version }}${{ matrix.config.artifact }}'
path: build/
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: torchvisionlib
Title: Additional Operators for Image Models
Version: 0.5.0.9000
Version: 0.6.0
Authors@R: c(
person("Daniel", "Falbel", , "daniel@rstudio.com", role = c("aut", "cre")),
person(family = "RStudio", role = c("cph"))
Expand All @@ -19,7 +19,7 @@ LinkingTo:
torch
Imports:
Rcpp,
torch (>= 0.9.0),
torch (>= 0.14.0),
rlang,
glue,
withr
Expand Down
17 changes: 11 additions & 6 deletions csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ message(STATUS "TORCH_HOME=${TORCH_HOME}")

if (DEFINED ENV{CUDA} AND NOT '$ENV{CUDA}' STREQUAL '')
if (WIN32)
find_package(CUDAToolkit)
find_package(CUDAToolkit REQUIRED)
else()
set(PATCH_CMD git apply ${CMAKE_SOURCE_DIR}/patch/kuint16.patch || true)
endif()
enable_language(CUDA)
endif()
Expand All @@ -64,13 +66,13 @@ if(WIN32)
GIT_TAG v1.6.37
DEPENDS zlib
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libpng"
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
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
)
ExternalProject_Add(libjpeg
GIT_REPOSITORY https://github.com/libjpeg-turbo/libjpeg-turbo
GIT_TAG 2.1.2
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libjpeg"
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
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
)
endif()

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

if(WIN32)
list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_IGNORE_PREFIX_PATH:PATH=C:/rtools43/x86_64-w64-mingw32.static.posix/)
list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_IGNORE_PREFIX_PATH:PATH=C:/rtools44/x86_64-w64-mingw32.static.posix/)
if (DEFINED ENV{CUDA} AND NOT '$ENV{CUDA}' STREQUAL '')
list(APPEND TORCHVISION_CMAKE_ARGS -DWITH_CUDA=ON)
endif()

elseif(APPLE)
list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_FIND_FRAMEWORK:STRING=LAST)
endif()

if (WIN32)
set(TORCHVISION_DEPENDS libpng libjpeg)
set(PATCH_CMD git apply ${CMAKE_SOURCE_DIR}/patch/jpeg_types.diff || true)
else()
set(TORCHVISION_DEPENDS)
endif()

message(STATUS "CMAKE_ARGS: ${TORCHVISION_CMAKE_ARGS}")
ExternalProject_Add(TorchVision-project
GIT_REPOSITORY https://github.com/pytorch/vision
GIT_TAG v0.15.2
GIT_TAG v0.20.1
DEPENDS ${TORCHVISION_DEPENDS}
CMAKE_CACHE_ARGS ${TORCHVISION_CMAKE_ARGS}
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libtorchvision"
Expand Down
36 changes: 36 additions & 0 deletions csrc/patch/kuint16.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/torchvision/csrc/io/image/cpu/decode_png.cpp b/torchvision/csrc/io/image/cpu/decode_png.cpp
index ede14c1e94..a42bd06c35 100644
--- a/torchvision/csrc/io/image/cpu/decode_png.cpp
+++ b/torchvision/csrc/io/image/cpu/decode_png.cpp
@@ -195,9 +195,13 @@ torch::Tensor decode_png(

auto num_pixels_per_row = width * channels;
auto is_16_bits = bit_depth == 16;
+
+ if (is_16_bits) {
+ throw std::runtime_error("16-bit PNG images are not supported.");
+ }
+
auto tensor = torch::empty(
- {int64_t(height), int64_t(width), channels},
- is_16_bits ? at::kUInt16 : torch::kU8);
+ {int64_t(height), int64_t(width), channels}, torch::kU8);
if (is_little_endian()) {
png_set_swap(png_ptr);
}
diff --git a/torchvision/csrc/ops/nms.cpp b/torchvision/csrc/ops/nms.cpp
index 5ecf8812f1..2cbbe93873 100644
--- a/torchvision/csrc/ops/nms.cpp
+++ b/torchvision/csrc/ops/nms.cpp
@@ -18,11 +18,5 @@ at::Tensor nms(
return op.call(dets, scores, iou_threshold);
}

-TORCH_LIBRARY_FRAGMENT(torchvision, m) {
- m.set_python_module("torchvision._meta_registrations");
- m.def(TORCH_SELECTIVE_SCHEMA(
- "torchvision::nms(Tensor dets, Tensor scores, float iou_threshold) -> Tensor"));
-}
-
} // namespace ops
} // namespace vision
26 changes: 26 additions & 0 deletions csrc/patch/nvtx_workaround.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f243055990..04b06e8335 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,6 +15,21 @@ option(WITH_WEBP "Enable features requiring LibWEBP." OFF)
option(WITH_AVIF "Enable features requiring LibAVIF." OFF)

if(WITH_CUDA)
+ if (WIN32)
+ find_package(CUDAToolkit REQUIRED)
+ message(STATUS "PyTorch NVTX headers workaround: Yes")
+ # only do this if nvToolsExt is not defined and CUDA::nvtx3 exists
+ if(NOT TARGET CUDA::nvToolsExt AND TARGET CUDA::nvtx3)
+ add_library(CUDA::nvToolsExt INTERFACE IMPORTED)
+ # ensure that PyTorch is told to use NVTX3 headers
+ target_compile_definitions(
+ CUDA::nvToolsExt INTERFACE
+ TORCH_CUDA_USE_NVTX3
+ )
+ target_link_libraries(CUDA::nvToolsExt INTERFACE CUDA::nvtx3)
+ endif()
+ endif()
+
enable_language(CUDA)
add_definitions(-D__CUDA_NO_HALF_OPERATORS__)
add_definitions(-DWITH_CUDA)
3 changes: 2 additions & 1 deletion csrc/src/ops.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <lantern/types.h>
#include <string>
#include <iostream>
#include <fstream>
#include <torch/torch.h>
#include <torchvision/ops/ops.h>
#include <torchvision/io/image/cpu/decode_jpeg.h>
Expand Down Expand Up @@ -137,4 +138,4 @@ torch::Tensor vision_read_jpeg(std::string fpath) {
torch::Tensor vision_read_jpeg_float(std::string fpath) {
auto ten = vision_read_jpeg(fpath);
return ten.to(torch::kFloat32).div_(255);
}
}
Loading