MCPcopy Create free account
hub / github.com/pytorch/executorch / wrapper

Function wrapper

exir/tests/test_memory_planning.py:284–340  ·  view source on GitHub ↗
(self: "TestMemoryPlanning")

Source from the content-addressed store, hash-verified

282 # parameterized.expand is not compatible with maketest. I'll just loop thru
283 # the test setups in the wrapper.
284 def wrapper(self: "TestMemoryPlanning") -> None:
285 nonlocal criteria
286 if not criteria:
287 criteria = [
288 # naive algorithm does not reuse tensor storages
289 (naive, False),
290 # greedy algorithm should reuse tensor storages in the testing model
291 (greedy, True),
292 ]
293
294 for algo, expect_reuse in criteria:
295 print(
296 f"algo {getattr(algo, '__name__', repr(algo))}, expect_reuse {expect_reuse}"
297 )
298 eager_module = module_cls().eval()
299 # pyre-fixme[29]: `Union[nn.modules.module.Module,
300 # torch._tensor.Tensor]` is not a function.
301 inputs = eager_module.get_random_inputs()
302 graph_module = (
303 to_edge(export(eager_module, inputs, strict=True))
304 .exported_program()
305 .graph_module
306 )
307 mem_algo = MemoryPlanningAlgorithmSuite(algo_list=[algo])
308 graph_module = PassManager(
309 passes=[
310 SpecPropPass(),
311 ToOutVarPass(),
312 MemoryPlanningPass(
313 mem_algo,
314 alloc_graph_input=alloc_graph_input,
315 alloc_graph_output=alloc_graph_output,
316 ),
317 ],
318 )(graph_module).graph_module
319
320 self.verify_reuse(
321 graph_module,
322 expect_reuse,
323 alloc_graph_input,
324 alloc_graph_output,
325 alloc_mutable_buffer,
326 )
327 self.verify_graph_input_output(
328 graph_module,
329 alloc_graph_input,
330 alloc_graph_output,
331 alloc_mutable_buffer,
332 )
333
334 self.verify_overlap_placeholders(has_unused_graph_input, graph_module)
335
336 # print(f"Final code: {graph_module.code}")
337 # print(f"Final graph: {graph_module.graph}")
338
339 if extra_check:
340 extra_check(self, graph_module)
341

Callers

nothing calls this directly

Calls 12

to_edgeFunction · 0.90
exportFunction · 0.90
PassManagerClass · 0.90
SpecPropPassClass · 0.90
ToOutVarPassClass · 0.90
MemoryPlanningPassClass · 0.90
verify_reuseMethod · 0.80
get_random_inputsMethod · 0.45
exported_programMethod · 0.45

Tested by

no test coverage detected