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

Added support for setGraphExecutorOptimize with torchscript models. #904

Merged
merged 4 commits into from
Apr 27, 2021
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 @@ -1367,6 +1367,10 @@ public static void deleteModule(long pointer) {
PyTorchLibrary.LIB.torchDeleteModule(pointer);
}

public static void setGraphExecutorOptimize(boolean enabled) {
PyTorchLibrary.LIB.setGraphExecutorOptimize(enabled);
}

public static PtSymbolBlock loadModule(
PtNDManager manager,
Path path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ native long moduleLoad(

native long moduleForward(long moduleHandle, long[] iValueHandles, boolean isTrain);

native void setGraphExecutorOptimize(boolean enabled);

native void moduleWrite(long moduleHandle, OutputStream os, byte[] buffer, boolean writeSize);

native long[] moduleGetParams(long moduleHandle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
#include <torch/csrc/jit/python/update_graph_executor_opt.h>
#include <torch/script.h>

#include "ai_djl_pytorch_jni_PyTorchLibrary.h"
Expand Down Expand Up @@ -117,7 +118,7 @@ JNIEXPORT void JNICALL Java_ai_djl_pytorch_jni_PyTorchLibrary_moduleWrite(
for (int i = 0; i < 8; i++) {
bytes[i] = static_cast<int>(length >> (56 - 8 * i) & 0XFF);
}
env->SetByteArrayRegion(jbytes, 0, 8, (jbyte*)bytes);
env->SetByteArrayRegion(jbytes, 0, 8, (jbyte*) bytes);
env->CallVoidMethod(jos, method_id, jbytes, 0, 8);
}
int len = env->GetArrayLength(arr);
Expand All @@ -136,6 +137,13 @@ JNIEXPORT void JNICALL Java_ai_djl_pytorch_jni_PyTorchLibrary_moduleWrite(
API_END()
}

JNIEXPORT void JNICALL Java_ai_djl_pytorch_jni_PyTorchLibrary_setGraphExecutorOptimize(
JNIEnv* env, jobject jthis, jboolean jenabled) {
API_BEGIN()
torch::jit::setGraphExecutorOptimize(jenabled);
API_END()
}

JNIEXPORT void JNICALL Java_ai_djl_pytorch_jni_PyTorchLibrary_moduleEval(
JNIEnv* env, jobject jthis, jlong module_handle) {
API_BEGIN()
Expand Down