@@ -45,19 +45,14 @@ class LoweredBackendModule(torch.nn.Module):
45
45
"""
46
46
A subclass of nn.Module that is generated for modules containing
47
47
delegated functions. This is can be created by calling `to_backend`.
48
-
49
- Private Attributes:
50
- * **backend_id**: The backend's name
51
- * **processed_bytes**: The delegate blobs created from backend.preprocess
52
- * **compile_specs**: A list of backend-specific objects with static
53
- metadata to configure the "compilation" process.
54
- * **original_module**: The original EXIR module
55
48
"""
56
49
57
- _backend_id : str
58
- _processed_bytes : bytes
59
- _compile_specs : List [CompileSpec ]
60
- _original_module : ExportedProgram
50
+ _backend_id : str # The backend's name
51
+ _processed_bytes : bytes # The delegate blobs created from backend.preprocess
52
+ _compile_specs : List [
53
+ CompileSpec
54
+ ] # A list of backend-specific objects with static metadata to configure the "compilation" process.
55
+ _original_module : ExportedProgram # The original EXIR module
61
56
62
57
def __init__ (
63
58
self ,
@@ -74,18 +69,30 @@ def __init__(
74
69
75
70
@property
76
71
def backend_id (self ) -> str :
72
+ """
73
+ Returns the backends name.
74
+ """
77
75
return self ._backend_id
78
76
79
77
@property
80
78
def processed_bytes (self ) -> bytes :
79
+ """
80
+ Returns the delegate blob created from backend.preprocess
81
+ """
81
82
return self ._processed_bytes
82
83
83
84
@property
84
85
def compile_specs (self ) -> List [CompileSpec ]:
86
+ """
87
+ Returns a list of backend-specific objects with static metadata to configure the "compilation" process.
88
+ """
85
89
return self ._compile_specs
86
90
87
91
@property
88
92
def original_module (self ) -> ExportedProgram :
93
+ """
94
+ Returns the original EXIR module
95
+ """
89
96
return self ._original_module
90
97
91
98
# TODO(chenlai): consolidate the seriailization config with serialize_to_flatbuffer api
@@ -96,6 +103,9 @@ def buffer(
96
103
constant_tensor_alignment : Optional [int ] = None ,
97
104
delegate_alignment : Optional [int ] = None ,
98
105
) -> bytes :
106
+ """
107
+ Returns a buffer containing the serialized ExecuTorch binary.
108
+ """
99
109
out = _serialize_pte_binary (
100
110
program = self .program (),
101
111
extract_segments = extract_segments ,
@@ -109,33 +119,35 @@ def buffer(
109
119
# the meta data construction is done manually.
110
120
def program (self , emit_stacktrace : bool = False ) -> Program :
111
121
"""
112
- The idea in this function is to create a module based on the original module. The original module will
113
- look something like following:
114
-
115
- opcode name target args kwargs
116
- ------------- ------------------- ---------------- ------------------------------------------ --------
117
- placeholder arg0_1 arg0_1 () {}
118
- placeholder arg1_1 arg1_1 () {}
119
- call_function aten_repeat_default * (arg1_1, [4, 1]) {}
120
- call_function aten_mul_tensor * (aten_repeat_default, aten_repeat_default) {}
121
- call_function aten_add_tensor * (arg1_1, arg1_1) {}
122
- output output output ([aten_mul_tensor, aten_add_tensor],) {}
123
-
124
- if the whole module is lowered, the resulting lowered module look like
125
-
126
- opcode name target args kwargs
127
- ------------- ------------------------ --------------------------- ---------------------------------- --------
128
- placeholder arg0_1 arg0_1 () {}
129
- placeholder arg1_1 arg1_1 () {}
130
- get_attr lowered_module_0 lowered_module_0 () {}
131
- call_function executorch_call_delegate executorch_call_delegate (lowered_module_0, arg0_1, arg1_1) {}
132
- call_function getitem <built-in function getitem> (executorch_call_delegate, 0) {}
133
- call_function getitem_1 <built-in function getitem> (executorch_call_delegate, 1) {}
134
- output output_1 output ([getitem, getitem_1],) {}
135
-
136
- We'll remove all call_function nodes, insert an call_delegate node, inserting getitems nodes to get the result for call_delegate node
137
- and return the list of getitems as the output
122
+ Returns the object that represents the ExecuTorch binary before serialization.
138
123
"""
124
+ # Creates a new module based on the original module. The original module will
125
+ # look something like following:
126
+ #
127
+ # opcode name target args kwargs
128
+ # ------------- ------------------- ---------------- ------------------------------------------ --------
129
+ # placeholder arg0_1 arg0_1 () {}
130
+ # placeholder arg1_1 arg1_1 () {}
131
+ # call_function aten_repeat_default * (arg1_1, [4, 1]) {}
132
+ # call_function aten_mul_tensor * (aten_repeat_default, aten_repeat_default) {}
133
+ # call_function aten_add_tensor * (arg1_1, arg1_1) {}
134
+ # output output output ([aten_mul_tensor, aten_add_tensor],) {}
135
+ #
136
+ # if the whole module is lowered, the resulting lowered module look like
137
+ #
138
+ # opcode name target args kwargs
139
+ # ------------- ------------------------ --------------------------- ---------------------------------- --------
140
+ # placeholder arg0_1 arg0_1 () {}
141
+ # placeholder arg1_1 arg1_1 () {}
142
+ # get_attr lowered_module_0 lowered_module_0 () {}
143
+ # call_function executorch_call_delegate executorch_call_delegate (lowered_module_0, arg0_1, arg1_1) {}
144
+ # call_function getitem <built-in function getitem> (executorch_call_delegate, 0) {}
145
+ # call_function getitem_1 <built-in function getitem> (executorch_call_delegate, 1) {}
146
+ # output output_1 output ([getitem, getitem_1],) {}
147
+ #
148
+ # We'll remove all call_function nodes, insert an call_delegate node, inserting getitems nodes to get the result for call_delegate node
149
+ # and return the list of getitems as the output
150
+
139
151
lowered_exported_program = copy .deepcopy (self .original_module )
140
152
141
153
# The real input nodes are the ones not buffer or parameter
@@ -405,7 +417,7 @@ def create_exported_program_from_submodule(
405
417
Args:
406
418
submodule: submodule to create and exported program from
407
419
owning_program: exported program containing the parameters and buffers used within
408
- the submodule
420
+ the submodule
409
421
410
422
Returns:
411
423
The ExportedProgram created from submodule
0 commit comments