15
15
16
16
# import the xnnpack backend implementation
17
17
from executorch .backends .qnnpack .qnnpack_preprocess import QnnpackBackend
18
- from executorch .exir import CaptureConfig
18
+ from executorch .exir import CaptureConfig , ExecutorchProgram
19
19
20
20
from executorch .exir .backend .backend_api import to_backend , validation_disabled
21
21
22
- from executorch .exir .serialize import serialize_to_flatbuffer
23
-
24
22
# pyre-ignore[21]: Could not find module `executorch.extension.pybindings.portable`.
25
23
from executorch .extension .pybindings .portable import ( # @manual
26
24
_load_for_executorch_from_buffer ,
@@ -114,20 +112,18 @@ def forward(self, x):
114
112
example_inputs = (torch .rand (self .input_dims ),)
115
113
116
114
composite_model (* example_inputs )
117
- program = (
115
+ executorch_program : ExecutorchProgram = (
118
116
exir .capture (composite_model , example_inputs , exir .CaptureConfig ())
119
117
.to_edge (EDGE_COMPILE_CONFIG )
120
118
.to_executorch (config = EXECUTORCH_BACKEND_CONFIG )
121
- .program
122
119
)
123
120
self .assertEqual (
124
- program .execution_plan [0 ].delegates [0 ].id ,
121
+ executorch_program . program .execution_plan [0 ].delegates [0 ].id ,
125
122
QnnpackBackend .__name__ ,
126
123
)
127
124
128
125
# Step 4: Run model and check outputs
129
- buffer = serialize_to_flatbuffer (program )
130
- executorch_module = _load_for_executorch_from_buffer (buffer )
126
+ executorch_module = _load_for_executorch_from_buffer (executorch_program .buffer )
131
127
inputs_flattened , _ = tree_flatten (example_inputs )
132
128
model_output = executorch_module .run_method ("forward" , tuple (inputs_flattened ))
133
129
ref_output = composite_model (* example_inputs )
@@ -199,20 +195,18 @@ def forward(self, x):
199
195
example_inputs = (torch .rand (self .input_dims ),)
200
196
201
197
composite_model (* example_inputs )
202
- program = (
198
+ executorch_program : ExecutorchProgram = (
203
199
exir .capture (composite_model , example_inputs , exir .CaptureConfig ())
204
200
.to_edge (EDGE_COMPILE_CONFIG )
205
201
.to_executorch (config = EXECUTORCH_BACKEND_CONFIG )
206
- .program
207
202
)
208
203
self .assertEqual (
209
- program .execution_plan [0 ].delegates [0 ].id ,
204
+ executorch_program . program .execution_plan [0 ].delegates [0 ].id ,
210
205
QnnpackBackend .__name__ ,
211
206
)
212
207
213
208
# Step 4: Run model and check outputs
214
- buffer = serialize_to_flatbuffer (program )
215
- executorch_module = _load_for_executorch_from_buffer (buffer )
209
+ executorch_module = _load_for_executorch_from_buffer (executorch_program .buffer )
216
210
inputs_flattened , _ = tree_flatten (example_inputs )
217
211
model_output = executorch_module .run_method ("forward" , tuple (inputs_flattened ))
218
212
ref_output = composite_model (* example_inputs )
@@ -274,20 +268,18 @@ def forward(self, x):
274
268
example_inputs = (torch .rand (self .input_dims ),)
275
269
276
270
composite_model (* example_inputs )
277
- program = (
271
+ executorch_program : ExecutorchProgram = (
278
272
exir .capture (composite_model , example_inputs , capture_config )
279
273
.to_edge (EDGE_COMPILE_CONFIG )
280
274
.to_executorch (config = EXECUTORCH_BACKEND_CONFIG )
281
- .program
282
275
)
283
276
self .assertEqual (
284
- program .execution_plan [0 ].delegates [0 ].id ,
277
+ executorch_program . program .execution_plan [0 ].delegates [0 ].id ,
285
278
QnnpackBackend .__name__ ,
286
279
)
287
280
288
281
# Step 4: Run model and check outputs
289
- buffer = serialize_to_flatbuffer (program )
290
- executorch_module = _load_for_executorch_from_buffer (buffer )
282
+ executorch_module = _load_for_executorch_from_buffer (executorch_program .buffer )
291
283
inputs_flattened , _ = tree_flatten (example_inputs )
292
284
model_output = executorch_module .run_method ("forward" , tuple (inputs_flattened ))
293
285
ref_output = composite_model (* example_inputs )
@@ -359,20 +351,18 @@ def forward(self, x):
359
351
example_inputs = (torch .rand (self .input_dims ),)
360
352
361
353
composite_model (* example_inputs )
362
- program = (
354
+ executorch_program : ExecutorchProgram = (
363
355
exir .capture (composite_model , example_inputs , capture_config )
364
356
.to_edge (EDGE_COMPILE_CONFIG )
365
357
.to_executorch (config = EXECUTORCH_BACKEND_CONFIG )
366
- .program
367
358
)
368
359
self .assertEqual (
369
- program .execution_plan [0 ].delegates [0 ].id ,
360
+ executorch_program . program .execution_plan [0 ].delegates [0 ].id ,
370
361
QnnpackBackend .__name__ ,
371
362
)
372
363
373
364
# Step 4: Run model and check outputs
374
- buffer = serialize_to_flatbuffer (program )
375
- executorch_module = _load_for_executorch_from_buffer (buffer )
365
+ executorch_module = _load_for_executorch_from_buffer (executorch_program .buffer )
376
366
inputs_flattened , _ = tree_flatten (example_inputs )
377
367
model_output = executorch_module .run_method ("forward" , tuple (inputs_flattened ))
378
368
ref_output = composite_model (* example_inputs )
@@ -433,20 +423,18 @@ def forward(self, x):
433
423
example_inputs = (torch .rand (self .input_dims ),)
434
424
435
425
composite_model (* example_inputs )
436
- program = (
426
+ executorch_program : ExecutorchProgram = (
437
427
exir .capture (composite_model , example_inputs , exir .CaptureConfig ())
438
428
.to_edge (EDGE_COMPILE_CONFIG )
439
429
.to_executorch (config = EXECUTORCH_BACKEND_CONFIG )
440
- .program
441
430
)
442
431
self .assertEqual (
443
- program .execution_plan [0 ].delegates [0 ].id ,
432
+ executorch_program . program .execution_plan [0 ].delegates [0 ].id ,
444
433
QnnpackBackend .__name__ ,
445
434
)
446
435
447
436
# Step 4: Run model and check outputs
448
- buffer = serialize_to_flatbuffer (program )
449
- executorch_module = _load_for_executorch_from_buffer (buffer )
437
+ executorch_module = _load_for_executorch_from_buffer (executorch_program .buffer )
450
438
inputs_flattened , _ = tree_flatten (example_inputs )
451
439
model_output = executorch_module .run_method ("forward" , tuple (inputs_flattened ))
452
440
ref_output = composite_model (* example_inputs )
@@ -515,7 +503,9 @@ def test_qnnpack_per_channel_dynamic_qlinear_via_partitioner(self):
515
503
lowered_module .exported_program .graph_module .code
516
504
)
517
505
518
- program = lowered_module .to_executorch (config = EXECUTORCH_BACKEND_CONFIG ).program
506
+ executorch_program : ExecutorchProgram = lowered_module .to_executorch (
507
+ config = EXECUTORCH_BACKEND_CONFIG
508
+ )
519
509
520
510
# TODO(T143084047)
521
511
# class CompositeModule(torch.nn.Module):
@@ -530,23 +520,21 @@ def test_qnnpack_per_channel_dynamic_qlinear_via_partitioner(self):
530
520
# example_inputs = (torch.rand(self.input_dims),)
531
521
532
522
# composite_model(*example_inputs)
533
- # program = (
523
+ # executorch_program: ExecutorchProgram = (
534
524
# exir.capture(
535
525
# composite_model, example_inputs, exir.CaptureConfig()
536
526
# )
537
527
# .to_edge(EDGE_COMPILE_CONFIG)
538
528
# .to_executorch()
539
- # .program
540
529
# )
541
530
542
531
self .assertEqual (
543
- program .execution_plan [0 ].delegates [0 ].id ,
532
+ executorch_program . program .execution_plan [0 ].delegates [0 ].id ,
544
533
QnnpackBackend .__name__ ,
545
534
)
546
535
547
536
# Step 4: Run model and check outputs
548
- buffer = serialize_to_flatbuffer (program )
549
- executorch_module = _load_for_executorch_from_buffer (buffer )
537
+ executorch_module = _load_for_executorch_from_buffer (executorch_program .buffer )
550
538
inputs_flattened , _ = tree_flatten (example_inputs )
551
539
model_output = executorch_module .run_method ("forward" , tuple (inputs_flattened ))
552
540
ref_output = captured_mod (* example_inputs )
0 commit comments