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

[pytorch] apply no_optimizer_guard only for Android #2153

Merged
merged 1 commit into from
Nov 11, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ struct JITCallGuard {
torch::NoGradGuard no_grad;
#else
c10::InferenceMode guard;
#ifdef __ANDROID__
torch::jit::GraphOptimizerEnabledGuard no_optimizer_guard{false};
#endif
#endif
};

JNIEXPORT jlong JNICALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ JNIEXPORT jlong JNICALL Java_ai_djl_pytorch_jni_PyTorchLibrary_torchSum__J_3JZ(
API_END_RETURN()
}

JNIEXPORT jlong JNICALL Java_ai_djl_pytorch_jni_PyTorchLibrary_torchCumProd
(JNIEnv * env, jobject jthis, jlong jhandle, jlong jdim, jint jdtype) {
JNIEXPORT jlong JNICALL Java_ai_djl_pytorch_jni_PyTorchLibrary_torchCumProd(
JNIEnv* env, jobject jthis, jlong jhandle, jlong jdim, jint jdtype) {
API_BEGIN()
const auto* tensor_ptr = reinterpret_cast<torch::Tensor*>(jhandle);
if (jdtype == -1) {
const auto* result_ptr = new torch::Tensor(tensor_ptr->cumprod(jdim));
return reinterpret_cast<uintptr_t>(result_ptr);
const auto* result_ptr = new torch::Tensor(tensor_ptr->cumprod(jdim));
return reinterpret_cast<uintptr_t>(result_ptr);
} else {
const auto* result_ptr = new torch::Tensor(tensor_ptr->cumprod(jdim, utils::GetScalarTypeFromDType(jdtype)));
return reinterpret_cast<uintptr_t>(result_ptr);
const auto* result_ptr = new torch::Tensor(tensor_ptr->cumprod(jdim, utils::GetScalarTypeFromDType(jdtype)));
return reinterpret_cast<uintptr_t>(result_ptr);
}
API_END_RETURN()
}
Expand Down