Skip to content

Commit 48fcae1

Browse files
committed
Update
[ghstack-poisoned]
1 parent e36ca0a commit 48fcae1

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

extension/android_test/add_model.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import torch
2+
from executorch.exir import to_edge
3+
from torch.export import export
4+
5+
6+
# Start with a PyTorch model that adds two input tensors (matrices)
7+
class Add(torch.nn.Module):
8+
def __init__(self):
9+
super(Add, self).__init__()
10+
11+
def forward(self, x: torch.Tensor, y: torch.Tensor):
12+
return x + y
13+
14+
15+
# 1. torch.export: Defines the program with the ATen operator set.
16+
aten_dialect = export(Add(), (torch.ones(1), torch.ones(1)))
17+
18+
# 2. to_edge: Make optimizations for Edge devices
19+
edge_program = to_edge(aten_dialect)
20+
21+
# 3. to_executorch: Convert the graph to an ExecuTorch program
22+
executorch_program = edge_program.to_executorch()
23+
24+
# 4. Save the compiled .pte program
25+
with open("add.pte", "wb") as file:
26+
file.write(executorch_program.buffer)

extension/android_test/setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ source ".ci/scripts/test_llama.sh" stories110M cmake fp16 portable ${BUILD_AAR_D
5656
popd
5757
mkdir -p "$BASEDIR"/src/libs
5858
cp "$BUILD_AAR_DIR/executorch.aar" "$BASEDIR"/src/libs/executorch.aar
59+
python add_model.py
60+
mv "add.pte" "$BASEDIR"/src/androidTest/resources/add.pte
5961
unzip -o "$BUILD_AAR_DIR"/model.zip -d "$BASEDIR"/src/androidTest/resources

0 commit comments

Comments
 (0)