File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change @@ -56,4 +56,6 @@ source ".ci/scripts/test_llama.sh" stories110M cmake fp16 portable ${BUILD_AAR_D
56
56
popd
57
57
mkdir -p " $BASEDIR " /src/libs
58
58
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
59
61
unzip -o " $BUILD_AAR_DIR " /model.zip -d " $BASEDIR " /src/androidTest/resources
You can’t perform that action at this time.
0 commit comments