Skip to content

Commit a2bc6bd

Browse files
pytorchbotEashan Garg
andauthored
Change memory planning API to accept full algorithm as argument as opposed to string name (#6130)
Change memory planning API to accept full algorithm as argument as opposed to string name (#4727) Summary: Pull Request resolved: #4727 Executorch memory planning currently accepts a string identifier to represent the desired algorithm. However, this makes it difficult to pass custom arguments to write more customized memory planning algorithms. This change allows users to pass the full memory planning function as an argument as opposed to just the string identifier. Core changes in: - fbcode/executorch/exir/passes/memory_planning_pass.py - fbcode/executorch/exir/tests/test_memory_planning.py Remaining changes are just to enforce compliance with new API at all call sites in codebase NOTE: A less intrusive change could be to allow argument to be either string or entire custom functions. I opted for just passing only functions to simplify and avoid confusion Reviewed By: zonglinpeng, hsharma35, mcremon-meta Differential Revision: D60433641 fbshipit-source-id: 0fe3677b7c3f4c3763cb1b4fe6d28ef814f2ecf9 (cherry picked from commit 618466e) Co-authored-by: Eashan Garg <[email protected]>
1 parent 67c959a commit a2bc6bd

File tree

22 files changed

+38
-91
lines changed

22 files changed

+38
-91
lines changed

backends/qualcomm/tests/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ def lower_module_and_test_output(
350350
# Therefore, won't want to pre-allocate
351351
# by memory manager in runtime.
352352
memory_planning_pass=MemoryPlanningPass(
353-
memory_planning_algo="greedy",
354353
alloc_graph_input=not self.shared_buffer,
355354
alloc_graph_output=not self.shared_buffer,
356355
),

backends/vulkan/vulkan_preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def preprocess( # noqa: C901
5757
MeanToSumDiv(),
5858
SpecPropPass(),
5959
ConstraintBasedSymShapeEvalPass(),
60-
MemoryPlanningPass("greedy"),
60+
MemoryPlanningPass(),
6161
]
6262

6363
new_gm = program.graph_module

docs/source/compiler-memory-planning.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ The `MemoryPlanningPass` exposes the option to not memory plan program inputs an
3232
program = edge_program.to_executorch(
3333
exir.ExecutorchBackendConfig(
3434
memory_planning_pass=MemoryPlanningPass(
35-
memory_planning_algo="greedy",
3635
alloc_graph_input=False, # Inputs will not be memory planned, the data_ptr for input tensors after model load will be nullptr
3736
alloc_graph_output=True, # Outputs will be memory planned, the data_ptr for output tensors after model load will be in the `planned_memory`.
3837
)
@@ -77,7 +76,7 @@ Then later when lowering to ExecuTorch you can use your custom plan in the follo
7776
program = edge_program.to_executorch(
7877
exir.ExecutorchBackendConfig(
7978
memory_planning_pass=CustomPoolMemoryPlanningPass(
80-
memory_planning_algo="greedy",
79+
memory_planning_algo=greedy,
8180
)
8281
)
8382
)

docs/source/tutorials_source/export-to-executorch-tutorial.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,7 @@ def forward(self, a, x, b):
523523
executorch_program: ExecutorchProgramManager = edge_program.to_executorch(
524524
ExecutorchBackendConfig(
525525
passes=[], # User-defined passes
526-
memory_planning_pass=MemoryPlanningPass(
527-
"greedy"
528-
), # Default memory planning pass
526+
memory_planning_pass=MemoryPlanningPass(), # Default memory planning pass
529527
)
530528
)
531529

examples/mediatek/model_export_scripts/llama.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ def export_to_et_ir(
365365
executorch_program = delegated_program.to_executorch(
366366
config=exir.ExecutorchBackendConfig(
367367
memory_planning_pass=exir.passes.MemoryPlanningPass(
368-
memory_planning_algo="greedy",
369368
alloc_graph_input=False,
370369
alloc_graph_output=False,
371370
),

examples/models/llava/export_llava.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def export_all(llava_model: LlavaModel):
233233
passes=[
234234
QuantFusionPass(),
235235
],
236-
memory_planning_pass=MemoryPlanningPass("greedy", alloc_graph_input=False),
236+
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False),
237237
sym_shape_eval_pass={
238238
"image_encoder": ConstraintBasedSymShapeEvalPass(),
239239
"text_model": ConstraintBasedSymShapeEvalPass(),

examples/qualcomm/oss_scripts/llama2/llama.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ def lowering_modules(
311311
# Therefore, won't want to pre-allocate
312312
# by memory manager in runtime.
313313
memory_planning_pass=MemoryPlanningPass(
314-
memory_planning_algo="greedy",
315314
alloc_graph_input=False,
316315
alloc_graph_output=False,
317316
),

examples/qualcomm/qaihub_scripts/utils/export.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def compile(args):
220220
)
221221
# setup memory planning
222222
memory_planning_pass = MemoryPlanningPass(
223-
memory_planning_algo="greedy",
224223
alloc_graph_input=args.allocate_graph_io,
225224
alloc_graph_output=args.allocate_graph_io,
226225
)

examples/qualcomm/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ def build_executorch_binary(
285285
# Therefore, won't want to pre-allocate
286286
# by memory manager in runtime.
287287
memory_planning_pass=MemoryPlanningPass(
288-
memory_planning_algo="greedy",
289288
alloc_graph_input=not shared_buffer,
290289
alloc_graph_output=not shared_buffer,
291290
),

exir/capture/_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ class ExecutorchBackendConfig:
5656

5757
# A single memory planning pass can be defined for all the programs in the
5858
# EdgeProgramManager or can be defined per program.
59-
memory_planning_pass: Union[PassType, Dict[str, PassType]] = MemoryPlanningPass(
60-
"greedy"
61-
)
59+
memory_planning_pass: Union[PassType, Dict[str, PassType]] = MemoryPlanningPass()
6260
to_out_var_pass: PassType = ToOutVarPass(ignore_to_out_var_failure=False)
6361
dynamic_memory_planning_mode: DynamicMemoryPlanningMode = (
6462
DynamicMemoryPlanningMode.UPPER_BOUND

0 commit comments

Comments
 (0)