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

Function get_control_flow_submodules

exir/graph_module.py:76–93  ·  view source on GitHub ↗

Returns a list of submodules used for control flow operations (torch.ops.higher_order.cond/map/scan) that are in the given toplevel graph (does not look into submodules). Specifically, the returned value is a list containing tuples of (name of the submodule that's stored in the grap

(
    graph_module: torch.fx.GraphModule,
)

Source from the content-addressed store, hash-verified

74
75
76def get_control_flow_submodules(
77 graph_module: torch.fx.GraphModule,
78) -> List[Tuple[str, torch.fx.GraphModule, torch.fx.Node]]:
79 """
80 Returns a list of submodules used for control flow operations
81 (torch.ops.higher_order.cond/map/scan) that are in the given toplevel graph (does not look
82 into submodules). Specifically, the returned value is a list containing
83 tuples of (name of the submodule that's stored in the graph module, the
84 submodule itself, and the fx node that uses this submodule).
85 """
86 return _get_control_flow_submodules(
87 graph_module,
88 {
89 torch.ops.higher_order.cond: [1, 2],
90 torch.ops.higher_order.map_impl: [0],
91 torch.ops.higher_order.scan: [0], # combine_fn is at arg index 0
92 },
93 )
94
95
96def get_cond_while_submodules(

Calls 1