Skip to content

Commit 3a8e1f5

Browse files
committed
enable aoti for preprocess ci
ghstack-source-id: 1bedf38 Pull Request resolved: #6553
1 parent 6fd92ab commit 3a8e1f5

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

examples/models/llama3_2_vision/preprocess/export_preprocess.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,22 @@ def main():
2424
strict=False,
2525
)
2626

27-
# Executorch
27+
# AOTInductor. Note: export AOTI before ExecuTorch, as
28+
# ExecuTorch will modify the ExportedProgram.
29+
torch._inductor.aot_compile(
30+
ep.module(),
31+
model.get_example_inputs(),
32+
options={"aot_inductor.output_path": "preprocess_aoti.so"},
33+
)
34+
35+
# Executorch.
2836
edge_program = to_edge(
2937
ep, compile_config=EdgeCompileConfig(_check_ir_validity=False)
3038
)
3139
et_program = edge_program.to_executorch()
3240
with open("preprocess_et.pte", "wb") as file:
3341
et_program.write_to_file(file)
3442

35-
# Export.
36-
# ep = torch.export.export(
37-
# model.get_eager_model(),
38-
# model.get_example_inputs(),
39-
# dynamic_shapes=model.get_dynamic_shapes(),
40-
# strict=False,
41-
# )
42-
#
43-
# # AOTInductor
44-
# torch._inductor.aot_compile(
45-
# ep.module(),
46-
# model.get_example_inputs(),
47-
# options={"aot_inductor.output_path": "preprocess_aoti.so"},
48-
# )
49-
5043

5144
if __name__ == "__main__":
5245
main()

examples/models/llama3_2_vision/preprocess/test_preprocess.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,30 @@ def initialize_models(resize_to_max_canvas: bool) -> Dict[str, Any]:
7676
strict=False,
7777
)
7878

79-
# aoti_path = torch._inductor.aot_compile(
80-
# exported_model.module(),
81-
# model.get_example_inputs(),
82-
# )
79+
aoti_path = torch._inductor.aot_compile(
80+
exported_model.module(),
81+
model.get_example_inputs(),
82+
)
8383

8484
edge_program = to_edge(
8585
exported_model, compile_config=EdgeCompileConfig(_check_ir_validity=False)
8686
)
8787
executorch_model = edge_program.to_executorch()
8888

89+
# Re-export, as lowering to executorch changes the graph.
90+
exported_model = torch.export.export(
91+
model.get_eager_model(),
92+
model.get_example_inputs(),
93+
dynamic_shapes=model.get_dynamic_shapes(),
94+
strict=False,
95+
)
96+
8997
return {
9098
"config": config,
9199
"reference_model": reference_model,
92100
"model": model,
93101
"exported_model": exported_model,
94-
# "aoti_path": aoti_path,
102+
"aoti_path": aoti_path,
95103
"executorch_model": executorch_model,
96104
}
97105

@@ -237,11 +245,11 @@ def run_preprocess(
237245
self.assertEqual(reference_ar, et_ar.tolist())
238246

239247
# Run aoti model and check it matches reference model.
240-
# aoti_path = models["aoti_path"]
241-
# aoti_model = torch._export.aot_load(aoti_path, "cpu")
242-
# aoti_image, aoti_ar = aoti_model(image_tensor, inscribed_size, best_resolution)
243-
# self.assertTrue(torch.allclose(reference_image, aoti_image))
244-
# self.assertEqual(reference_ar, aoti_ar.tolist())
248+
aoti_path = models["aoti_path"]
249+
aoti_model = torch._export.aot_load(aoti_path, "cpu")
250+
aoti_image, aoti_ar = aoti_model(image_tensor, inscribed_size, best_resolution)
251+
self.assertTrue(torch.allclose(reference_image, aoti_image))
252+
self.assertEqual(reference_ar, aoti_ar.tolist())
245253

246254
# This test setup mirrors the one in torchtune:
247255
# https://github.com/pytorch/torchtune/blob/main/tests/torchtune/models/clip/test_clip_image_transform.py

0 commit comments

Comments
 (0)