From 8ecbe966e1d88befe5c53919beb3983d2baac33b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 8 Jan 2026 01:46:59 +0000 Subject: [PATCH 1/2] Initial plan From f26e45c14c59b59ad366a6ed239613ba7b0c0955 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 8 Jan 2026 01:52:51 +0000 Subject: [PATCH 2/2] Replace android.util.Log with java.util.logging.Logger in executorch_android Co-authored-by: kirklandsign <107070759+kirklandsign@users.noreply.github.com> --- .../src/main/java/org/pytorch/executorch/Module.java | 10 +++++----- .../src/main/java/org/pytorch/executorch/Tensor.java | 6 +++--- .../pytorch/executorch/training/TrainingModule.java | 9 +++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java index 6da76bf4b74..466180c753c 100644 --- a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java +++ b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/Module.java @@ -8,7 +8,6 @@ package org.pytorch.executorch; -import android.util.Log; import com.facebook.jni.HybridData; import com.facebook.jni.annotations.DoNotStrip; import com.facebook.soloader.nativeloader.NativeLoader; @@ -18,6 +17,7 @@ import java.util.Map; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Logger; import org.pytorch.executorch.annotations.Experimental; /** @@ -27,6 +27,7 @@ */ @Experimental public class Module { + private static final Logger LOGGER = Logger.getLogger("ExecuTorch"); static { if (!NativeLoader.isInitialized()) { @@ -139,7 +140,7 @@ public EValue[] execute(String methodName, EValue... inputs) { try { mLock.lock(); if (!mHybridData.isValid()) { - Log.e("ExecuTorch", "Attempt to use a destroyed module"); + LOGGER.severe("Attempt to use a destroyed module"); return new EValue[0]; } return executeNative(methodName, inputs); @@ -164,7 +165,7 @@ public int loadMethod(String methodName) { try { mLock.lock(); if (!mHybridData.isValid()) { - Log.e("ExecuTorch", "Attempt to use a destroyed module"); + LOGGER.severe("Attempt to use a destroyed module"); return 0x2; // InvalidState } return loadMethodNative(methodName); @@ -251,8 +252,7 @@ public void destroy() { mLock.unlock(); } } else { - Log.w( - "ExecuTorch", + LOGGER.warning( "Destroy was called while the module was in use. Resources will not be immediately" + " released."); } diff --git a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/Tensor.java b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/Tensor.java index e8c0a918b13..889a0d17d01 100644 --- a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/Tensor.java +++ b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/Tensor.java @@ -8,7 +8,6 @@ package org.pytorch.executorch; -import android.util.Log; import com.facebook.jni.HybridData; import com.facebook.jni.annotations.DoNotStrip; import java.nio.Buffer; @@ -21,6 +20,7 @@ import java.nio.ShortBuffer; import java.util.Arrays; import java.util.Locale; +import java.util.logging.Logger; import org.pytorch.executorch.annotations.Experimental; /** @@ -44,6 +44,7 @@ */ @Experimental public abstract class Tensor { + private static final Logger LOGGER = Logger.getLogger("ExecuTorch"); private static final String ERROR_MSG_DATA_BUFFER_NOT_NULL = "Data buffer must be not null"; private static final String ERROR_MSG_DATA_ARRAY_NOT_NULL = "Data array must be not null"; private static final String ERROR_MSG_SHAPE_NOT_NULL = "Shape must be not null"; @@ -846,8 +847,7 @@ private Tensor_unsupported(ByteBuffer data, long[] shape, DType dtype) { super(shape); this.data = data; this.mDtype = dtype; - Log.e( - "ExecuTorch", + LOGGER.severe( toString() + " in Java. Please consider re-export the model with proper return type"); } diff --git a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/training/TrainingModule.java b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/training/TrainingModule.java index 3735fb6f426..0784662164e 100644 --- a/extension/android/executorch_android/src/main/java/org/pytorch/executorch/training/TrainingModule.java +++ b/extension/android/executorch_android/src/main/java/org/pytorch/executorch/training/TrainingModule.java @@ -8,7 +8,6 @@ package org.pytorch.executorch.training; -import android.util.Log; import com.facebook.jni.HybridData; import com.facebook.jni.annotations.DoNotStrip; import com.facebook.soloader.nativeloader.NativeLoader; @@ -16,6 +15,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; +import java.util.logging.Logger; import org.pytorch.executorch.EValue; import org.pytorch.executorch.Tensor; import org.pytorch.executorch.annotations.Experimental; @@ -27,6 +27,7 @@ */ @Experimental public class TrainingModule { + private static final Logger LOGGER = Logger.getLogger("ExecuTorch"); static { if (!NativeLoader.isInitialized()) { @@ -88,7 +89,7 @@ public static TrainingModule load(final String modelPath) { */ public EValue[] executeForwardBackward(String methodName, EValue... inputs) { if (!mHybridData.isValid()) { - Log.e("ExecuTorch", "Attempt to use a destroyed module"); + LOGGER.severe("Attempt to use a destroyed module"); return new EValue[0]; } return executeForwardBackwardNative(methodName, inputs); @@ -99,7 +100,7 @@ public EValue[] executeForwardBackward(String methodName, EValue... inputs) { public Map namedParameters(String methodName) { if (!mHybridData.isValid()) { - Log.e("ExecuTorch", "Attempt to use a destroyed module"); + LOGGER.severe("Attempt to use a destroyed module"); return new HashMap(); } return namedParametersNative(methodName); @@ -110,7 +111,7 @@ public Map namedParameters(String methodName) { public Map namedGradients(String methodName) { if (!mHybridData.isValid()) { - Log.e("ExecuTorch", "Attempt to use a destroyed module"); + LOGGER.severe("Attempt to use a destroyed module"); return new HashMap(); } return namedGradientsNative(methodName);