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

Method test_alloc_node_spec

exir/tests/test_passes.py:1004–1037  ·  view source on GitHub ↗

Make sure every memory.alloc node including those in sub graph modules have a TensorSpec.

(self)

Source from the content-addressed store, hash-verified

1002 ).check_not("operator.sub").run(converted_gm.code)
1003
1004 def test_alloc_node_spec(self) -> None:
1005 """
1006 Make sure every memory.alloc node including those in sub graph modules
1007 have a TensorSpec.
1008 """
1009 eager_model = FTMapBasic()
1010 inputs = eager_model.get_random_inputs()
1011 prog = to_edge(
1012 export(eager_model, inputs, strict=True),
1013 compile_config=exir.EdgeCompileConfig(_check_ir_validity=False),
1014 )
1015 passes = [
1016 SpecPropPass(),
1017 HintBasedSymShapeEvalPass(),
1018 ]
1019 new_prog = prog.transform(passes)
1020
1021 new_gm_res = ToOutVarPass()(new_prog.exported_program().graph_module)
1022 self.assertIsNotNone(new_gm_res)
1023 new_gm = new_gm_res.graph_module
1024
1025 new_gm_res = MemoryPlanningPass()(new_gm)
1026 self.assertIsNotNone(new_gm_res)
1027 new_gm = new_gm_res.graph_module
1028
1029 alloc_nodes = []
1030 for subgm in new_gm.modules():
1031 if isinstance(subgm, torch.fx.GraphModule):
1032 for node in subgm.graph.nodes:
1033 if node.target == memory.alloc:
1034 alloc_nodes.append(node)
1035 self.assertTrue(len(alloc_nodes) > 0)
1036 for node in alloc_nodes:
1037 self.assertTrue(isinstance(node.meta.get("spec", None), TensorSpec))
1038
1039 def test_debug_pass_file_log(self) -> None:
1040 eager_model = Mul()

Callers

nothing calls this directly

Calls 12

get_random_inputsMethod · 0.95
FTMapBasicClass · 0.90
to_edgeFunction · 0.90
exportFunction · 0.90
SpecPropPassClass · 0.90
ToOutVarPassClass · 0.90
MemoryPlanningPassClass · 0.90
transformMethod · 0.45
exported_programMethod · 0.45
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected