@@ -67,15 +67,13 @@ Here is a flow highlighting how to generate a `BundledProgram` given a PyTorch m
67
67
``` python
68
68
69
69
import torch
70
- from executorch import exir
70
+ from torch.export import export
71
+
71
72
from executorch.bundled_program.config import BundledConfig
72
73
from executorch.bundled_program.core import create_bundled_program
73
74
from executorch.bundled_program.serialize import serialize_from_bundled_program_to_flatbuffer
74
- from executorch.bundled_program.serialize import deserialize_from_flatbuffer_to_bundled_program
75
75
76
-
77
- from executorch.exir import ExecutorchBackendConfig
78
- from executorch.exir.passes import MemoryPlanningPass, ToOutVarPass
76
+ from executorch.exir import to_edge
79
77
80
78
81
79
# Step 1: ExecuTorch Program Export
@@ -119,12 +117,12 @@ capture_inputs = {
119
117
}
120
118
121
119
# Trace to FX Graph and emit the program
122
- program = (
123
- exir.capture_multiple( model, capture_inputs)
124
- .to_edge()
125
- .to_executorch()
126
- .program
127
- )
120
+ method_graphs = {
121
+ m_name: export( getattr ( model, m_name), capture_inputs[m_name] )
122
+ for m_name in method_names
123
+ }
124
+
125
+ program = to_edge(method_graphs).to_executorch().executorch_program
128
126
129
127
# Step 2: Construct BundledConfig
130
128
@@ -291,12 +289,13 @@ Here's the example of the dtype of test input not meet model's requirement:
291
289
292
290
```python
293
291
import torch
294
- from executorch import exir
295
- from executorch.exir import ExecutorchBackendConfig
296
- from executorch.exir.passes import MemoryPlanningPass, ToOutVarPass
292
+ from torch.export import export
293
+
297
294
from executorch.bundled_program.config import BundledConfig
298
295
from executorch.bundled_program.core import create_bundled_program
299
296
297
+ from executorch.exir import to_edge
298
+
300
299
301
300
class Module(torch.nn.Module):
302
301
def __init__(self):
@@ -318,16 +317,13 @@ method_names = ['forward']
318
317
inputs = torch.ones(2, 2, dtype=torch.float)
319
318
print(model(inputs))
320
319
321
- # Trace to FX Graph.
322
- program = (
323
- exir.capture(model, (inputs,))
324
- .to_edge()
325
- .to_executorch(
326
- config=ExecutorchBackendConfig(
327
- memory_planning_pass=MemoryPlanningPass(), to_out_var_pass=ToOutVarPass()
328
- )
329
- ).program
330
- )
320
+ # Trace to FX Graph and emit the program
321
+ method_graphs = {
322
+ m_name: export(getattr(model, m_name), (inputs, ))
323
+ for m_name in method_names
324
+ }
325
+
326
+ program = to_edge(method_graphs).to_executorch().executorch_program
331
327
332
328
333
329
# number of input sets to be verified
@@ -416,12 +412,13 @@ Another common error would be the method name in `BundledConfig` does not exist
416
412
417
413
``` python
418
414
import torch
419
- from executorch import exir
420
- from executorch.exir import ExecutorchBackendConfig
421
- from executorch.exir.passes import MemoryPlanningPass, ToOutVarPass
415
+ from torch.export import export
416
+
422
417
from executorch.bundled_program.config import BundledConfig
423
418
from executorch.bundled_program.core import create_bundled_program
424
419
420
+ from executorch.exir import to_edge
421
+
425
422
426
423
427
424
class Module (torch .nn .Module ):
@@ -440,23 +437,17 @@ class Module(torch.nn.Module):
440
437
441
438
model = Module()
442
439
443
- # NOTE : wrong_forward is not an inference method in the above model.
444
- method_names = [' wrong_forward' ]
440
+ method_names = [' forward' ]
445
441
446
442
inputs = torch.ones(2 , 2 , dtype = torch.float)
447
- print (model(inputs))
448
443
449
- # Trace to FX Graph.
450
- program = (
451
- exir.capture(model, (inputs,))
452
- .to_edge()
453
- .to_executorch(
454
- config = ExecutorchBackendConfig(
455
- memory_planning_pass = MemoryPlanningPass(), to_out_var_pass = ToOutVarPass()
456
- )
457
- ).program
458
- )
444
+ # Trace to FX Graph and emit the program
445
+ method_graphs = {
446
+ m_name: export(getattr (model, m_name), (inputs, ))
447
+ for m_name in method_names
448
+ }
459
449
450
+ program = to_edge(method_graphs).to_executorch().executorch_program
460
451
461
452
# Number of input sets to be verified
462
453
n_input = 10
@@ -476,7 +467,11 @@ expected_outpus = [
476
467
[[model(* x)] for x in inputs[0 ]]
477
468
]
478
469
479
- bundled_config = BundledConfig(method_names, inputs, expected_outpus)
470
+
471
+ # NOTE : WRONG_FORWARD is not an inference method in the above model.
472
+ wrong_method_names = [' WRONG_FORWARD' ]
473
+
474
+ bundled_config = BundledConfig(wrong_method_names, inputs, expected_outpus)
480
475
481
476
bundled_program = create_bundled_program(program, bundled_config)
482
477
0 commit comments