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

Function create_replacement_for_pattern

backends/vulkan/patterns/__init__.py:98–117  ·  view source on GitHub ↗
(
    ep: ExportedProgram,
    graph_module: torch.fx.GraphModule,
    patterns: List[torch.fx.GraphModule],
    create_replacement_func: CreateReplacementFn,
)

Source from the content-addressed store, hash-verified

96
97
98def create_replacement_for_pattern(
99 ep: ExportedProgram,
100 graph_module: torch.fx.GraphModule,
101 patterns: List[torch.fx.GraphModule],
102 create_replacement_func: CreateReplacementFn,
103) -> int:
104 total_replaced = 0
105
106 for pattern in patterns:
107 sm = SubgraphMatcher(pattern.graph, ignore_literals=True)
108 matches = list(sm.match(graph_module.graph))
109
110 for partition_to_replace in matches:
111 pattern = create_pattern_match_from_internal_match(partition_to_replace)
112 create_replacement_func(ep, graph_module, pattern)
113 total_replaced += 1
114 # Remove dead code so they won't be matched again
115 graph_module.graph.eliminate_dead_code()
116
117 return total_replaced
118
119
120def replace_all_fusable_subgraphs(

Callers 1

Calls 2

matchMethod · 0.45

Tested by

no test coverage detected