Skip to content

Commit 2e67e3a

Browse files
lucylqfacebook-github-bot
authored andcommitted
Remove pad_max_tiles from preprocess (#6295)
Summary: Following changes in torchtune: - pytorch/torchtune#1836 - pytorch/torchtune#1853 Update ET downstream and remove pad-max-tiles from preprocess. Pull Request resolved: #6295 Test Plan: With AOTI tests commented out (not working atm): ``` python -m unittest examples/models/llama3_2_vision/preprocess/test_preprocess.py ... ---------------------------------------------------------------------- Ran 4 tests in 21.129s OK ``` Reviewed By: larryliu0820 Differential Revision: D64481012 Pulled By: lucylq fbshipit-source-id: e822c235c5555e0682d181c4c482dec7c170c96e
1 parent 295b2aa commit 2e67e3a

File tree

3 files changed

+12
-49
lines changed

3 files changed

+12
-49
lines changed

examples/models/llama3_2_vision/preprocess/export_preprocess.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414

1515
def main():
16-
# Export
17-
ep = export_preprocess()
1816

1917
# ExecuTorch
20-
et = lower_to_executorch_preprocess(ep)
18+
ep_et = export_preprocess()
19+
et = lower_to_executorch_preprocess(ep_et)
2120
with open("preprocess_et.pte", "wb") as file:
2221
et.write_to_file(file)
2322

2423
# AOTInductor
24+
ep_aoti = export_preprocess()
2525
torch._inductor.aot_compile(
26-
ep.module(),
26+
ep_aoti.module(),
2727
get_example_inputs(),
2828
options={"aot_inductor.output_path": "preprocess_aoti.so"},
2929
)

examples/models/llama3_2_vision/preprocess/export_preprocess_lib.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def export_preprocess(
4343
max_num_tiles: int = 4,
4444
tile_size: int = 224,
4545
antialias: bool = False,
46-
pad_max_tiles: bool = True,
4746
) -> ExportedProgram:
4847

4948
# Instantiate eager model.
@@ -54,7 +53,6 @@ def export_preprocess(
5453
max_num_tiles=max_num_tiles,
5554
tile_size=tile_size,
5655
antialias=antialias,
57-
pad_max_tiles=pad_max_tiles,
5856
)
5957

6058
# Replace non-exportable ops with custom ops.

examples/models/llama3_2_vision/preprocess/test_preprocess.py

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
from executorch.extension.pybindings import portable_lib # noqa # usort: skip
1717
from executorch.extension.llm.custom_ops import sdpa_with_kv_cache # noqa # usort: skip
18+
from executorch.examples.models.llama3_2_vision.preprocess.export_preprocess_lib import (
19+
export_preprocess,
20+
get_example_inputs,
21+
lower_to_executorch_preprocess,
22+
)
1823
from executorch.extension.pybindings.portable_lib import (
1924
_load_for_executorch_from_buffer,
2025
)
@@ -37,12 +42,6 @@
3742
)
3843
from torchvision.transforms.v2 import functional as F
3944

40-
from .export_preprocess_lib import (
41-
export_preprocess,
42-
get_example_inputs,
43-
lower_to_executorch_preprocess,
44-
)
45-
4645

4746
@dataclass
4847
class PreprocessConfig:
@@ -54,7 +53,6 @@ class PreprocessConfig:
5453
tile_size: int = 224
5554
max_num_tiles: int = 4
5655
possible_resolutions = None
57-
pad_max_tiles: bool = True
5856

5957

6058
class TestImageTransform(unittest.TestCase):
@@ -137,17 +135,6 @@ def prepare_inputs(
137135
[1.0, 1.0], # expected_tile_max
138136
[0.0, 0.0], # expected_tile_min
139137
[1, 2], # expected_aspect_ratio
140-
False, # pad_max_tiles
141-
),
142-
(
143-
(100, 400, 3), # image_size
144-
torch.Size([4, 3, 224, 224]), # expected shape
145-
False, # resize_to_max_canvas
146-
[0.2230, 0.1763, 0.0, 0.0], # expected_tile_means
147-
[1.0, 1.0, 0.0, 0.0], # expected_tile_max
148-
[0.0, 0.0, 0.0, 0.0], # expected_tile_min
149-
[1, 2], # expected_aspect_ratio
150-
True, # pad_max_tiles
151138
),
152139
(
153140
(1000, 300, 3), # image_size
@@ -157,7 +144,6 @@ def prepare_inputs(
157144
[0.9976, 0.9940, 0.9936, 0.9906], # expected_tile_max
158145
[0.0037, 0.0047, 0.0039, 0.0], # expected_tile_min
159146
[4, 1], # expected_aspect_ratio
160-
False, # pad_max_tiles
161147
),
162148
(
163149
(200, 200, 3), # image_size
@@ -167,7 +153,6 @@ def prepare_inputs(
167153
[0.9921, 0.9925, 0.9969, 0.9908], # expected_tile_max
168154
[0.0056, 0.0069, 0.0059, 0.0032], # expected_tile_min
169155
[2, 2], # expected_aspect_ratio
170-
False, # pad_max_tiles
171156
),
172157
(
173158
(600, 200, 3), # image_size
@@ -177,17 +162,6 @@ def prepare_inputs(
177162
[1.0, 1.0, 1.0], # expected_tile_max
178163
[0.0, 0.0, 0.0], # expected_tile_min
179164
[3, 1], # expected_aspect_ratio
180-
False, # pad_max_tiles
181-
),
182-
(
183-
(600, 200, 3), # image_size
184-
torch.Size([4, 3, 224, 224]), # expected shape
185-
False, # resize_to_max_canvas
186-
[0.4472, 0.4468, 0.3031, 0.0], # expected_tile_means
187-
[1.0, 1.0, 1.0, 0.0], # expected_tile_max
188-
[0.0, 0.0, 0.0, 0.0], # expected_tile_min
189-
[3, 1], # expected_aspect_ratio
190-
True, # pad_max_tiles
191165
),
192166
]
193167
)
@@ -200,11 +174,8 @@ def test_preprocess(
200174
expected_tile_max: List[float],
201175
expected_tile_min: List[float],
202176
expected_ar: List[int],
203-
pad_max_tiles: bool,
204177
) -> None:
205-
config = PreprocessConfig(
206-
resize_to_max_canvas=resize_to_max_canvas, pad_max_tiles=pad_max_tiles
207-
)
178+
config = PreprocessConfig(resize_to_max_canvas=resize_to_max_canvas)
208179

209180
reference_model = CLIPImageTransform(
210181
image_mean=config.image_mean,
@@ -215,7 +186,6 @@ def test_preprocess(
215186
tile_size=config.tile_size,
216187
max_num_tiles=config.max_num_tiles,
217188
possible_resolutions=None,
218-
pad_max_tiles=config.pad_max_tiles,
219189
)
220190

221191
eager_model = _CLIPImageTransform(
@@ -225,7 +195,6 @@ def test_preprocess(
225195
antialias=config.antialias,
226196
tile_size=config.tile_size,
227197
max_num_tiles=config.max_num_tiles,
228-
pad_max_tiles=config.pad_max_tiles,
229198
)
230199

231200
exported_model = export_preprocess(
@@ -235,7 +204,6 @@ def test_preprocess(
235204
antialias=config.antialias,
236205
tile_size=config.tile_size,
237206
max_num_tiles=config.max_num_tiles,
238-
pad_max_tiles=config.pad_max_tiles,
239207
)
240208

241209
executorch_model = lower_to_executorch_preprocess(exported_model)
@@ -275,11 +243,8 @@ def test_preprocess(
275243
self.assertAlmostEqual(tile.min().item(), expected_tile_min[i], delta=1e-4)
276244

277245
# Check num tiles matches the product of the aspect ratio.
278-
if pad_max_tiles:
279-
self.assertEqual(config.max_num_tiles, reference_image.shape[0])
280-
else:
281-
expected_num_tiles = reference_ar[0] * reference_ar[1]
282-
self.assertEqual(expected_num_tiles, reference_image.shape[0])
246+
expected_num_tiles = reference_ar[0] * reference_ar[1]
247+
self.assertEqual(expected_num_tiles, reference_image.shape[0])
283248

284249
# Pre-work for eager and exported models. The reference model performs these
285250
# calculations and passes the result to _CLIPImageTransform, the exportable model.

0 commit comments

Comments
 (0)