@@ -139,14 +139,15 @@ def buffer(
139
139
segment_alignment : int = 4096 ,
140
140
constant_tensor_alignment : Optional [int ] = None ,
141
141
delegate_alignment : Optional [int ] = None ,
142
+ memory_planning : MemoryPlanningPass = None ,
142
143
) -> bytes :
143
144
"""
144
145
Returns a buffer containing the serialized ExecuTorch binary.
145
146
"""
146
147
# TODO(T181463742): avoid calling bytes(..) which incurs large copies.
147
148
out = bytes (
148
149
_serialize_pte_binary (
149
- program = self .program (),
150
+ program = self .program (memory_planning = memory_planning ),
150
151
extract_delegate_segments = extract_delegate_segments ,
151
152
segment_alignment = segment_alignment ,
152
153
constant_tensor_alignment = constant_tensor_alignment ,
@@ -157,7 +158,11 @@ def buffer(
157
158
158
159
# TODO(chenlai): re-consider recapture instead of manually constructing the program because
159
160
# the meta data construction is done manually.
160
- def program (self , emit_stacktrace : bool = False ) -> Program :
161
+ def program (
162
+ self ,
163
+ emit_stacktrace : bool = False ,
164
+ memory_planning : MemoryPlanningPass = None ,
165
+ ) -> Program :
161
166
# Fix autodpes introuces cyclic dependencies:
162
167
# program -> verifier -> lowered_backend_module -> program
163
168
# @manual
@@ -319,9 +324,9 @@ def program(self, emit_stacktrace: bool = False) -> Program:
319
324
example_inputs = None ,
320
325
verifier = lowered_exported_program .verifier ,
321
326
)
322
- exported_program = _transform (
323
- exported_program , SpecPropPass (), MemoryPlanningPass ("greedy" )
324
- )
327
+ if memory_planning is None :
328
+ memory_planning = MemoryPlanningPass ("greedy" )
329
+ exported_program = _transform ( exported_program , SpecPropPass (), memory_planning )
325
330
emitted_program = emit_program (
326
331
exported_program , emit_stacktrace = emit_stacktrace
327
332
).program
0 commit comments