From 28ff41e19bcc13d5be82d3ce7ab5f3e2e3863cad Mon Sep 17 00:00:00 2001 From: Kimish Patel Date: Wed, 9 Apr 2025 20:31:55 -0700 Subject: [PATCH] [pytorch/executorch][diff_train] using-executorch-android.md: Use an easier example (#10008) And it's working without additional requirements! Internal: << DO NOT EDIT BELOW THIS LINE >> **GitHub Author**: Hansong <107070759+kirklandsign@users.noreply.github.com> (Meta Employee) **GitHub Repo**: [pytorch/executorch](https://github.com/pytorch/executorch) **GitHub Pull Request**: [#10008](https://github.com/pytorch/executorch/pull/10008) Initially generated by: https://www.internalfb.com/intern/sandcastle/job/13510800659039904/ This was imported as part of a Diff Train. Please review this as soon as possible. Since it is a direct copy of a commit on GitHub, there shouldn't be much to do. diff-train-source-id: a1af1ffbb126f631f14db5ade48bfc435f7a6046 Differential Revision: [D72746022](https://our.internmc.facebook.com/intern/diff/D72746022/) [ghstack-poisoned] --- docs/source/using-executorch-android.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/source/using-executorch-android.md b/docs/source/using-executorch-android.md index f1a18ba4ae4..4528de55219 100644 --- a/docs/source/using-executorch-android.md +++ b/docs/source/using-executorch-android.md @@ -172,18 +172,22 @@ public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the ExecuTorch module - module = Module.load("/path/to/module.pte"); - } - public void runInference(View view) { - // Prepare input data - Tensor input = Tensor.fromBlob(getInputData()); - // Run inference - Tensor output = module.forward(EValue.from(input))[0].toTensor(); - // Process output data - processOutput(output); + Module module = Module.load("/data/local/tmp/add.pte"); + Tensor tensor1 = Tensor.fromBlob(new float[] {1.0f}, new long[] {1}); + Tensor tensor2 = Tensor.fromBlob(new float[] {20.0f}, new long[] {1}); + + EValue eValue1 = EValue.from(tensor1); + EValue eValue2 = EValue.from(tensor2); + float result = module.forward(eValue1, eValue2)[0].toTensor().getDataAsFloatArray()[0]; } } ``` + +Push the corresponding pte file to the phone: +```sh +adb push extension/module/test/resources/add.pte /data/local/tmp/ +``` + This example loads an ExecuTorch module, prepares input data, runs inference, and processes the output data. Please use [DeepLabV3AndroidDemo](https://github.com/pytorch-labs/executorch-examples/tree/main/dl3/android/DeepLabV3Demo)