Skip to content

Commit 2db96fe

Browse files
larryliu0820mergennachin
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 6a2e582 commit 2db96fe

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
@@ -45,19 +45,14 @@ class LoweredBackendModule(torch.nn.Module):
4545
"""
4646
A subclass of nn.Module that is generated for modules containing
4747
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
5548
"""
5649

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
6156

6257
def __init__(
6358
self,
@@ -74,18 +69,30 @@ def __init__(
7469

7570
@property
7671
def backend_id(self) -> str:
72+
"""
73+
Returns the backends name.
74+
"""
7775
return self._backend_id
7876

7977
@property
8078
def processed_bytes(self) -> bytes:
79+
"""
80+
Returns the delegate blob created from backend.preprocess
81+
"""
8182
return self._processed_bytes
8283

8384
@property
8485
def compile_specs(self) -> List[CompileSpec]:
86+
"""
87+
Returns a list of backend-specific objects with static metadata to configure the "compilation" process.
88+
"""
8589
return self._compile_specs
8690

8791
@property
8892
def original_module(self) -> ExportedProgram:
93+
"""
94+
Returns the original EXIR module
95+
"""
8996
return self._original_module
9097

9198
# TODO(chenlai): consolidate the seriailization config with serialize_to_flatbuffer api
@@ -96,6 +103,9 @@ def buffer(
96103
constant_tensor_alignment: Optional[int] = None,
97104
delegate_alignment: Optional[int] = None,
98105
) -> bytes:
106+
"""
107+
Returns a buffer containing the serialized ExecuTorch binary.
108+
"""
99109
out = _serialize_pte_binary(
100110
program=self.program(),
101111
extract_segments=extract_segments,
@@ -109,33 +119,35 @@ def buffer(
109119
# the meta data construction is done manually.
110120
def program(self, emit_stacktrace: bool = False) -> Program:
111121
"""
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.
138123
"""
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+
139151
lowered_exported_program = copy.deepcopy(self.original_module)
140152

141153
# The real input nodes are the ones not buffer or parameter
@@ -405,7 +417,7 @@ def create_exported_program_from_submodule(
405417
Args:
406418
submodule: submodule to create and exported program from
407419
owning_program: exported program containing the parameters and buffers used within
408-
the submodule
420+
the submodule
409421
410422
Returns:
411423
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)