Skip to content

Commit c7e2e95

Browse files
JacobSzwejbkafacebook-github-bot
authored andcommitted
delete exir.capture from some more places (#2852)
Summary: a bunch of misc places using exir.capture that shouldnt be anymore. Reviewed By: mergennachin Differential Revision: D55766467
1 parent 1adf268 commit c7e2e95

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

exir/tests/test_quantization.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
import torch
1212
import torchvision
13-
from executorch import exir
14-
from executorch.exir import EdgeCompileConfig
13+
from executorch.exir import EdgeCompileConfig, to_edge
1514
from executorch.exir.passes.quant_fusion_pass import QuantFusionPass
1615
from executorch.exir.passes.spec_prop_pass import SpecPropPass
1716
from torch.ao.ns.fx.utils import compute_sqnr
@@ -29,6 +28,7 @@
2928
get_symmetric_quantization_config,
3029
XNNPACKQuantizer,
3130
)
31+
from torch.export import export
3232
from torch.testing import FileCheck
3333
from torch.testing._internal.common_quantized import override_quantized_engine
3434

@@ -70,19 +70,17 @@ def test_resnet(self) -> None:
7070
compile_config = EdgeCompileConfig(
7171
_check_ir_validity=False,
7272
)
73-
m = (
74-
exir.capture(m, example_inputs)
75-
.to_edge(config=compile_config)
76-
.transform(QuantFusionPass(), SpecPropPass())
77-
)
73+
m = to_edge(
74+
export(m, example_inputs), compile_config=compile_config
75+
).transform([QuantFusionPass(), SpecPropPass()])
7876

79-
after_quant_result = m(*example_inputs)[0]
77+
after_quant_result = m.exported_program().module()(*example_inputs)[0]
8078
FileCheck().check(
8179
"executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_tensor"
8280
).check(
8381
"executorch_exir_dialects_edge__ops_quantized_decomposed_dequantize_per_tensor"
8482
).run(
85-
m.exported_program.graph_module.code
83+
m.exported_program().graph_module.code
8684
)
8785
# after_quant_fusion_result = m(*example_inputs)[0]
8886

test/models/generate_linear_out_bundled_program.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
import subprocess
1717
from typing import List
1818

19-
import executorch.exir as exir
20-
2119
import torch
22-
from executorch.exir import ExecutorchBackendConfig
20+
from executorch.exir import ExecutorchBackendConfig, to_edge
2321

2422
from executorch.exir.passes import MemoryPlanningPass, ToOutVarPass
2523
from executorch.exir.print_program import pretty_print
@@ -30,6 +28,7 @@
3028
)
3129

3230
from executorch.test.models.linear_model import LinearModel
31+
from torch.export import export
3332

3433

3534
def main() -> None:
@@ -38,21 +37,17 @@ def main() -> None:
3837
trace_inputs = (torch.ones(2, 2, dtype=torch.float),)
3938

4039
# Trace to FX Graph.
41-
exec_prog = (
42-
exir.capture(model, trace_inputs)
43-
.to_edge()
44-
.to_executorch(
45-
config=ExecutorchBackendConfig(
46-
memory_planning_pass=MemoryPlanningPass(),
47-
to_out_var_pass=ToOutVarPass(),
48-
)
40+
exec_prog = to_edge(export(model, trace_inputs)).to_executorch(
41+
config=ExecutorchBackendConfig(
42+
memory_planning_pass=MemoryPlanningPass(),
43+
to_out_var_pass=ToOutVarPass(),
4944
)
5045
)
5146
# Emit in-memory representation.
52-
pretty_print(exec_prog.program)
47+
pretty_print(exec_prog.executorch_program)
5348

5449
# Serialize to flatbuffer.
55-
exec_prog.program.version = 0
50+
exec_prog.executorch_program.version = 0
5651

5752
# Create test sets
5853
method_test_cases: List[MethodTestCase] = []
@@ -66,7 +61,6 @@ def main() -> None:
6661
]
6762

6863
bundled_program = BundledProgram(exec_prog, method_test_suites)
69-
pretty_print(bundled_program)
7064

7165
bundled_program_flatbuffer = serialize_from_bundled_program_to_flatbuffer(
7266
bundled_program
@@ -76,7 +70,7 @@ def main() -> None:
7670
subprocess.run(["hg", "root"], stdout=subprocess.PIPE).stdout.decode().strip()
7771
)
7872
with open(
79-
f"{fbsource_base_path}/fbcode/executorch/test/models/linear_out_bundled_program.pte",
73+
f"{fbsource_base_path}/fbcode/executorch/test/models/linear_out_bundled_program.bpte",
8074
"wb",
8175
) as file:
8276
file.write(bundled_program_flatbuffer)

0 commit comments

Comments
 (0)