Skip to content

Commit a62c53a

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Fix Export to ExecuTorch API Reference format issues (#878)
Summary: Pull Request resolved: #878 As titled Reviewed By: JacobSzwejbka, dbort Differential Revision: D50246694 fbshipit-source-id: d06eeeb578545cf74b994179031793ec5307fdfc
1 parent b0f72a9 commit a62c53a

File tree

2 files changed

+57
-45
lines changed

2 files changed

+57
-45
lines changed

exir/lowered_backend_module.py

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,14 @@ class LoweredBackendModule(torch.nn.Module):
4949
"""
5050
A subclass of nn.Module that is generated for modules containing
5151
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
5952
"""
6053

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
6560

6661
def __init__(
6762
self,
@@ -78,18 +73,30 @@ def __init__(
7873

7974
@property
8075
def backend_id(self) -> str:
76+
"""
77+
Returns the backends name.
78+
"""
8179
return self._backend_id
8280

8381
@property
8482
def processed_bytes(self) -> bytes:
83+
"""
84+
Returns the delegate blob created from backend.preprocess
85+
"""
8586
return self._processed_bytes
8687

8788
@property
8889
def compile_specs(self) -> List[CompileSpec]:
90+
"""
91+
Returns a list of backend-specific objects with static metadata to configure the "compilation" process.
92+
"""
8993
return self._compile_specs
9094

9195
@property
9296
def original_module(self) -> ExportedProgram:
97+
"""
98+
Returns the original EXIR module
99+
"""
93100
return self._original_module
94101

95102
# TODO(chenlai): consolidate the seriailization config with serialize_to_flatbuffer api
@@ -100,6 +107,9 @@ def buffer(
100107
constant_tensor_alignment: Optional[int] = None,
101108
delegate_alignment: Optional[int] = None,
102109
) -> bytes:
110+
"""
111+
Returns a buffer containing the serialized ExecuTorch binary.
112+
"""
103113
out = _serialize_pte_binary(
104114
program=self.program(),
105115
extract_segments=extract_segments,
@@ -113,33 +123,35 @@ def buffer(
113123
# the meta data construction is done manually.
114124
def program(self, emit_stacktrace: bool = False) -> Program:
115125
"""
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.
142127
"""
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+
143155
lowered_exported_program = copy.deepcopy(self.original_module)
144156

145157
# The real input nodes are the ones not buffer or parameter
@@ -434,7 +446,7 @@ def create_exported_program_from_submodule(
434446
Args:
435447
submodule: submodule to create and exported program from
436448
owning_program: exported program containing the parameters and buffers used within
437-
the submodule
449+
the submodule
438450
439451
Returns:
440452
The ExportedProgram created from submodule

exir/program/_program.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def to_edge(
631631

632632
class EdgeProgramManager:
633633
"""
634-
Package of one or more :class:'ExportedPrograms' in Edge dialect. Designed to simplify
634+
Package of one or more `ExportedPrograms` in Edge dialect. Designed to simplify
635635
lowering to ExecuTorch.
636636
637637
Allows easy applications of transforms across a collection of exported programs
@@ -692,11 +692,11 @@ def transform(
692692
693693
Args:
694694
passes: The passes can either be a list of passes, or a
695-
dictionary mapping method names to lists of passes. If it is
696-
just a list of passes, all methods in the given EdgeProgramManager
697-
will be transformed with the provided passes. If it is a
698-
dictionary, only method names specified in the dictionary will be
699-
transformed with their corresponding passes.
695+
dictionary mapping method names to lists of passes. If it is
696+
just a list of passes, all methods in the given EdgeProgramManager
697+
will be transformed with the provided passes. If it is a
698+
dictionary, only method names specified in the dictionary will be
699+
transformed with their corresponding passes.
700700
701701
Returns:
702702
EdgeProgramManager: A copy of the calling EdgeProgramManager with the
@@ -771,7 +771,7 @@ def to_executorch(
771771
772772
Args:
773773
config: An optional argument used to provide greater control over
774-
the transformation to the ExecuTorch backend.
774+
the transformation to the ExecuTorch backend.
775775
776776
Returns:
777777
ExecutorchProgramManager: A manager representing the state of the EdgeProgramManager

0 commit comments

Comments
 (0)