Skip to content

Commit fe438f9

Browse files
larryliu0820Gasoonjia
authored andcommitted
Add export_add.py
1 parent d97377b commit fe438f9

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

backends/aoti/aoti_partitioner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AOTISupportedOperators(OperatorSupportBase):
2828
def is_node_supported(self, submodules, node: torch.fx.Node) -> bool:
2929
supported = node.op == "call_function" and node.target in [
3030
exir_ops.edge.aten.add.Tensor,
31-
exir_ops.edge.aten._to_copy.default,
31+
exir_ops.edge.dim_order_ops._to_dim_order_copy.default,
3232
]
3333

3434
return supported

exir/backend/backend_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ def to_backend(
711711
fake_edge_program = copy.deepcopy(edge_program)
712712
partitioner_result = partitioner_instance(fake_edge_program)
713713
tagged_exported_program = partitioner_result.tagged_exported_program
714+
# Make sure tagged_exported_program has the same example_inputs as edge_program
715+
tagged_exported_program.example_inputs = edge_program.example_inputs
716+
714717
method_to_tagged_exported_program[method_name] = tagged_exported_program
715718

716719
# Check that the partitioner did not modify the original graph

exir/lowered_backend_module.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ def create_exported_program_from_submodule(
734734
),
735735
)
736736
],
737+
example_inputs=owning_program.example_inputs,
737738
constants=subgraph_constants,
738739
verifiers=[owning_program.verifier],
739740
),

export_add.py

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

install_requirements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def python_is_compatible():
5959

6060

6161
# The pip repository that hosts nightly torch packages.
62-
TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cu121"
62+
TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cu126"
6363

6464

6565
# Since ExecuTorch often uses main-branch features of pytorch, only the nightly

0 commit comments

Comments
 (0)