cd ./executorch-workspace/
conda create -yp ./.conda-env python=3.10.0
conda activate executorch
git clone --branch v0.3.0 https://github.com/pytorch/executorch.git
cd ./executorch/
git submodule sync
git submodule update --init
./install_requirements.sh
Generate a Sample ExecuTorch program
Create simple program
export_add.py
import torch
from torch.export import export
from executorch.exir import to_edge
# Start with a PyTorch model that adds two input tensors (matrices)
class Add(torch.nn.Module):
def __init__(self):
super(Add, self).__init__()
def forward(self, x: torch.Tensor, y: torch.Tensor):
return x + y
# 1. torch.export: Defines the program with the ATen operator set.
aten_dialect = export(Add(), (torch.ones(1), torch.ones(1)))
# 2. to_edge: Make optimizations for Edge devices
edge_program = to_edge(aten_dialect)
# 3. to_executorch: Convert the graph to an ExecuTorch program
executorch_program = edge_program.to_executorch()
# 4. Save the compiled .pte program
with open("add.pte", "wb") as file:
file.write(executorch_program.buffer)