diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 12ba9fc..12b2242 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -22,12 +22,12 @@ jobs: fail-fast: false matrix: config: - - {runner: macOS-13, r_version: release, os: macOS} + - {runner: macOS-14, r_version: release, os: macOS, torch_url: 'https://github.com/mlverse/libtorch-mac-m1/releases/download/LibTorch-for-R/libtorch-x86_64-v2.8.0.zip', cmake_args: '-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_IGNORE_PATH=/opt/homebrew -DCMAKE_PREFIX_PATH=/usr/local'} - {runner: [self-hosted, m1], r_version: '', os: macOS} - - {runner: windows-2019, r_version: release, os: windows} + - {runner: windows-2022, r_version: release, os: windows} - {runner: ubuntu-latest, r_version: release, os: ubuntu} - - {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} + - {runner: ubuntu-latest, r_version: release, os: ubuntu, cuda: 12.8, cuda_patch: 0} + - {runner: windows-2022, r_version: release, os: windows, cuda: 12.8, cuda_patch: 0} include: - config: {os: ubuntu} @@ -38,6 +38,7 @@ jobs: TORCH_TEST: 1 GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} CUDA: ${{matrix.config.cuda}} + TORCH_URL: ${{matrix.config.torch_url}} MAKEFLAGS: '-j8' DEBIAN_FRONTEND: 'noninteractive' TZ: 'Etc/UTC' @@ -63,7 +64,7 @@ jobs: cmake-version: '3.31' - if: ${{matrix.config.cuda != ''}} - uses: Jimver/cuda-toolkit@v0.2.21 + uses: Jimver/cuda-toolkit@v0.2.23 id: cuda-toolkit with: cuda: '${{matrix.config.cuda}}.${{matrix.config.cuda_patch}}' @@ -76,13 +77,19 @@ jobs: - name: Install dependencies run: | - Rscript -e "install.packages(c('remotes', 'desc', 'rcmdcheck', 'hms'))" + Rscript -e "install.packages(c('remotes', 'desc', 'rcmdcheck', 'hms', 'cli'))" Rscript -e "remotes::install_github('mlverse/torchexport', force = TRUE)" + - name: Install x86_64 Homebrew and libraries + if: ${{ contains(matrix.config.cmake_args, 'x86_64') }} + run: | + arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + arch -x86_64 /usr/local/bin/brew install libpng jpeg-turbo + - run: | cd csrc mkdir build && cd build - cmake .. + cmake .. ${{ matrix.config.cmake_args }} cmake --build . --target package --config Release --parallel 4 - id: version @@ -90,8 +97,8 @@ jobs: run: | version=$(Rscript -e "cat(as.character(desc::desc_get_version()))") fname=$(Rscript -e "cat(list.files('csrc/build/', '*.zip'))") - echo "::set-output name=version::$version" - echo "::set-output name=fname::$fname" + echo "version=$version" >> $GITHUB_OUTPUT + echo "fname=$fname" >> $GITHUB_OUTPUT - uses: svenstaro/upload-release-action@v2 if: github.ref_name == 'main' @@ -117,10 +124,10 @@ jobs: fail-fast: false matrix: config: - - {os: mac, runner: macOS-13, r: 'release', artifact: '+cpu+x86_64-Darwin.zip'} + - {os: mac, runner: macOS-15, r: 'release', arch: 'x86_64', 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: ubuntu, runner: ubuntu-20.04, r: 'release', artifact: '+cpu-Linux.zip'} + - {os: ubuntu, runner: ubuntu-latest, r: 'release', artifact: '+cpu-Linux.zip'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} @@ -136,7 +143,7 @@ jobs: if: ${{ !contains(matrix.config.os, 'm1') }} - uses: r-lib/actions/setup-r@v2 - if: ${{ !contains(matrix.config.os, 'm1') }} + if: ${{ !contains(matrix.config.os, 'm1') && matrix.config.arch != 'x86_64' }} with: r-version: ${{ matrix.config.r }} rtools-version: ${{ matrix.config.rtools }} @@ -144,6 +151,16 @@ jobs: use-public-rspm: true windows-path-include-mingw: false + - name: Install x86_64 R and libraries + if: ${{ matrix.config.arch == 'x86_64' }} + run: | + arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + arch -x86_64 /usr/local/bin/brew install libpng jpeg-turbo + brew tap r-lib/rig + brew install --cask rig + sudo rig add release --arch x86_64 + sudo rig default release + - name: Install dependencies run: | Rscript -e "install.packages(c('remotes', 'desc', 'rcmdcheck'))" -e "remotes::install_deps(dependencies = TRUE, INSTALL_opts='--no-multiarch')" @@ -154,7 +171,7 @@ jobs: id: version run: | version=$(Rscript -e "cat(as.character(desc::desc_get_version()))") - echo "::set-output name=version::$version" + echo "version=$version" >> $GITHUB_OUTPUT - uses: actions/download-artifact@v4 with: diff --git a/DESCRIPTION b/DESCRIPTION index 9ace0cd..e71c7cf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: torchvisionlib Title: Additional Operators for Image Models -Version: 0.6.0 +Version: 0.7.0.9000 Authors@R: c( person("Daniel", "Falbel", , "daniel@rstudio.com", role = c("aut", "cre")), person(family = "RStudio", role = c("cph")) @@ -19,7 +19,7 @@ LinkingTo: torch Imports: Rcpp, - torch (>= 0.14.0), + torch (>= 0.17.0), rlang, glue, withr diff --git a/NEWS.md b/NEWS.md index a92fc08..ab73dd2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # torchvisionlib (development version) +# torchvisionlib 0.7.0 + +- Updates to support LibTorch v2.8 + + # torchvisionlib 0.5.0 - Updates to support LibTorch v2.0.1 diff --git a/csrc/CMakeLists.txt b/csrc/CMakeLists.txt index c705c75..f950d6a 100644 --- a/csrc/CMakeLists.txt +++ b/csrc/CMakeLists.txt @@ -32,8 +32,9 @@ else() ) message(STATUS "TORCH_R_VERSION: ${TORCH_R_VERSION}") SET(TORCH_HOME "${CMAKE_CURRENT_BINARY_DIR}/torch") + file(MAKE_DIRECTORY ${TORCH_HOME}) execute_process( - COMMAND Rscript -e "Sys.setenv(TORCH_HOME='${TORCH_HOME}', TORCH_R_VERSION='${TORCH_R_VERSION}', TORCH_COMMIT_SHA='none');source('${TORCH_INSTALL_SCRIPT}'); install_torch();" + COMMAND Rscript -e "library(cli);Sys.setenv(TORCH_HOME='${TORCH_HOME}', TORCH_R_VERSION='${TORCH_R_VERSION}', TORCH_COMMIT_SHA='none');source('${TORCH_INSTALL_SCRIPT}'); install_torch();" ) endif() @@ -94,6 +95,9 @@ if(WIN32) elseif(APPLE) list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_FIND_FRAMEWORK:STRING=LAST) + if(CMAKE_OSX_ARCHITECTURES) + list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}) + endif() endif() if (WIN32) @@ -105,7 +109,7 @@ endif() message(STATUS "CMAKE_ARGS: ${TORCHVISION_CMAKE_ARGS}") ExternalProject_Add(TorchVision-project GIT_REPOSITORY https://github.com/pytorch/vision - GIT_TAG v0.20.1 + GIT_TAG v0.23.0 DEPENDS ${TORCHVISION_DEPENDS} CMAKE_CACHE_ARGS ${TORCHVISION_CMAKE_ARGS} PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libtorchvision" @@ -192,7 +196,11 @@ else() endif() if(APPLE) - set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}+${CMAKE_SYSTEM_PROCESSOR}) + if(CMAKE_OSX_ARCHITECTURES) + set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}+${CMAKE_OSX_ARCHITECTURES}) + else() + set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}+${CMAKE_SYSTEM_PROCESSOR}) + endif() endif() include(CPack) diff --git a/csrc/patch/kuint16.patch b/csrc/patch/kuint16.patch index 0e67e73..875444a 100644 --- a/csrc/patch/kuint16.patch +++ b/csrc/patch/kuint16.patch @@ -1,23 +1,3 @@ -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