Skip to content

Commit

Permalink
[ci] Fixes pytorch jni build for 1.13.1 (#3184)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu authored May 13, 2024
1 parent 2d9c84b commit 7d2036d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion engines/pytorch/pytorch-native/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if [[ ! -d "libtorch" ]]; then
curl -s https://download.pytorch.org/libtorch/${FLAVOR}/libtorch${CXX11ABI}-shared-with-deps-${VERSION}%2B${FLAVOR}.zip | jar xv >/dev/null
fi
elif [[ $PLATFORM == 'darwin' ]]; then
if [[ "$VERSION" =~ ^(2.2.)* ]]; then
if [[ "$VERSION" =~ ^(2.[2-9].*)$ ]]; then
if [[ $ARCH == 'aarch64' ]]; then
curl -s https://download.pytorch.org/libtorch/cpu/libtorch-macos-arm64-${VERSION}.zip | jar xv >/dev/null
else
Expand All @@ -53,6 +53,10 @@ if [[ ! -d "libtorch" ]]; then
fi
fi

if [[ "$VERSION" == "1.13.1" ]]; then
PT_VERSION=V1_13_X
fi

if [[ "$FLAVOR" = cu* ]]; then
USE_CUDA=1
fi
Expand Down
10 changes: 10 additions & 0 deletions engines/pytorch/pytorch-native/src/main/native/djl_pytorch_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#include <torch/script.h>

#include <iostream>
#ifdef V1_13_X
#include <c10/util/variant.h>
#else
#include <variant>
#endif

#include "djl_pytorch_jni_log.h"

Expand All @@ -30,10 +34,16 @@ namespace utils {

#if !defined(__ANDROID__)
// for image interpolation
#ifdef V1_13_X
typedef torch::variant<torch::enumtype::kNearest, torch::enumtype::kLinear, torch::enumtype::kBilinear,
torch::enumtype::kBicubic, torch::enumtype::kTrilinear, torch::enumtype::kArea, torch::enumtype::kNearestExact>
mode_t;
#else
typedef std::variant<torch::enumtype::kNearest, torch::enumtype::kLinear, torch::enumtype::kBilinear,
torch::enumtype::kBicubic, torch::enumtype::kTrilinear, torch::enumtype::kArea, torch::enumtype::kNearestExact>
mode_t;
#endif
#endif

inline jint GetDTypeFromScalarType(const torch::ScalarType& type) {
if (torch::kFloat32 == type) {
Expand Down

0 comments on commit 7d2036d

Please sign in to comment.