Skip to content

Switch over backend tests to export_for_training #5220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backends/example/test_example_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_example_inputs():
)

m = model.eval()
m = torch._export.capture_pre_autograd_graph(m, copy.deepcopy(example_inputs))
m = torch.export.export_for_training(m, copy.deepcopy(example_inputs)).module()
# print("original model:", m)
quantizer = ExampleQuantizer()
# quantizer = XNNPACKQuantizer()
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_delegate_mobilenet_v2(self):
)

m = model.eval()
m = torch._export.capture_pre_autograd_graph(m, copy.deepcopy(example_inputs))
m = torch.export.export_for_training(m, copy.deepcopy(example_inputs)).module()
quantizer = ExampleQuantizer()

m = prepare_pt2e(m, quantizer)
Expand Down
17 changes: 8 additions & 9 deletions exir/backend/test/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ python_library(
"//executorch/test/...",
],
deps = [
":backend_with_compiler_demo",
"//caffe2:torch",
"//executorch/exir:graph_module",
"//executorch/exir/backend:compile_spec_schema",
"//executorch/exir/backend:partitioner",
"//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib",
"//executorch/exir/backend/test/demos/rpc:executor_backend_partitioner",
"//executorch/exir/backend/test/demos/rpc:executor_backend_preprocess",
"//executorch/exir/dialects:lib",
"fbcode//caffe2:torch",
"fbcode//executorch/exir:graph_module",
"fbcode//executorch/exir/backend:compile_spec_schema",
"fbcode//executorch/exir/backend:partitioner",
"fbcode//executorch/exir/backend/canonical_partitioners:canonical_partitioner_lib",
"fbcode//executorch/exir/backend/test:backend_with_compiler_demo",
"fbcode//executorch/exir/backend/test/demos/rpc:executor_backend_preprocess",
"fbcode//executorch/exir/dialects:lib",
],
)

Expand Down
19 changes: 9 additions & 10 deletions exir/backend/test/test_partitioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
_load_for_executorch_from_buffer,
)
from executorch.extension.pytree import tree_flatten
from torch._export import capture_pre_autograd_graph
from torch._export.utils import is_buffer, is_lifted_tensor_constant, is_param
from torch.export import export
from torch.export import export, export_for_training
from torch.fx.passes.operator_support import any_chain


Expand Down Expand Up @@ -77,7 +76,7 @@ def partition(

mlp = MLP()
example_inputs = mlp.get_random_inputs()
model = capture_pre_autograd_graph(mlp, example_inputs)
model = export_for_training(mlp, example_inputs).module()
aten = export(model, example_inputs)
spec_key = "path"
spec_value = "/a/b/c/d"
Expand Down Expand Up @@ -138,7 +137,7 @@ def partition(

mlp = MLP()
example_inputs = mlp.get_random_inputs()
model = capture_pre_autograd_graph(mlp, example_inputs)
model = export_for_training(mlp, example_inputs).module()
aten = export(model, example_inputs)
edge = exir.to_edge(aten)

Expand Down Expand Up @@ -178,7 +177,7 @@ def partition(

mlp = MLP()
example_inputs = mlp.get_random_inputs()
model = capture_pre_autograd_graph(mlp, example_inputs)
model = export_for_training(mlp, example_inputs).module()
edge = exir.to_edge(export(model, example_inputs))

with self.assertRaisesRegex(
Expand Down Expand Up @@ -230,7 +229,7 @@ def partition(
partition_tags=partition_tags,
)

model = capture_pre_autograd_graph(self.AddConst(), (torch.ones(2, 2),))
model = export_for_training(self.AddConst(), (torch.ones(2, 2),)).module()
edge = exir.to_edge(export(model, (torch.ones(2, 2),)))
delegated = edge.to_backend(PartitionerNoTagData())

Expand Down Expand Up @@ -309,7 +308,7 @@ def partition(
partition_tags=partition_tags,
)

model = capture_pre_autograd_graph(self.AddConst(), (torch.ones(2, 2),))
model = export_for_training(self.AddConst(), (torch.ones(2, 2),)).module()
edge = exir.to_edge(export(model, (torch.ones(2, 2),)))
delegated = edge.to_backend(PartitionerTagData())

Expand Down Expand Up @@ -384,7 +383,7 @@ def partition(
partition_tags=partition_tags,
)

model = capture_pre_autograd_graph(self.AddConst(), (torch.ones(2, 2),))
model = export_for_training(self.AddConst(), (torch.ones(2, 2),)).module()
edge = exir.to_edge(export(model, (torch.ones(2, 2),)))
delegated = edge.to_backend(PartitionerTagData())

Expand Down Expand Up @@ -472,7 +471,7 @@ def partition(
)

inputs = (torch.ones(2, 2),)
model = capture_pre_autograd_graph(ReuseConstData(), (torch.ones(2, 2),))
model = export_for_training(ReuseConstData(), (torch.ones(2, 2),)).module()
edge = exir.to_edge(export(model, (torch.ones(2, 2),)))
exec_prog = edge.to_backend(PartitionerTagData()).to_executorch()
executorch_module = _load_for_executorch_from_buffer(exec_prog.buffer)
Expand Down Expand Up @@ -532,7 +531,7 @@ def partition(
partition_tags=partition_tags,
)

model = capture_pre_autograd_graph(ReuseConstData(), (torch.ones(2, 2),))
model = export_for_training(ReuseConstData(), (torch.ones(2, 2),)).module()
edge = exir.to_edge(export(model, (torch.ones(2, 2),)))
with self.assertRaises(RuntimeError) as error:
_ = edge.to_backend(PartitionerTagData())
Expand Down
4 changes: 2 additions & 2 deletions exir/backend/test/test_passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from executorch.exir.backend.canonical_partitioners.duplicate_constant_node_pass import (
duplicate_constant_node,
)
from torch._export import capture_pre_autograd_graph
from torch._export.utils import is_buffer
from torch.export import export_for_training
from torch.testing import FileCheck


Expand All @@ -29,7 +29,7 @@ def forward(self, x):
z = x - self.const
return y, z

model = capture_pre_autograd_graph(ReuseConstData(), (torch.ones(2, 2),))
model = export_for_training(ReuseConstData(), (torch.ones(2, 2),)).module()
edge = exir.to_edge(torch.export.export(model, (torch.ones(2, 2),)))

const_nodes = [
Expand Down
Loading