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