(
name: str,
nodes: Dict[str, Node],
input_nodes: Dict[
str, Node | OperatorGraph
], # Never OperatorGraph, annotated for Pyre
output_nodes: Dict[
str, Node | OperatorGraph
], # Never OperatorGraph, annotated for Pyre
out_variant_output_nodes: Set[str],
module_mapping: Dict[
Tuple[str, str], List[Any]
], # Any used here for Pyre, list of Nodes
)
| 334 | |
| 335 | @staticmethod |
| 336 | def _compose_op_graph( |
| 337 | name: str, |
| 338 | nodes: Dict[str, Node], |
| 339 | input_nodes: Dict[ |
| 340 | str, Node | OperatorGraph |
| 341 | ], # Never OperatorGraph, annotated for Pyre |
| 342 | output_nodes: Dict[ |
| 343 | str, Node | OperatorGraph |
| 344 | ], # Never OperatorGraph, annotated for Pyre |
| 345 | out_variant_output_nodes: Set[str], |
| 346 | module_mapping: Dict[ |
| 347 | Tuple[str, str], List[Any] |
| 348 | ], # Any used here for Pyre, list of Nodes |
| 349 | ): |
| 350 | # Generate Module Graphs |
| 351 | module_graphs: List[OperatorGraph] = [] |
| 352 | for module_key, module_nodes in module_mapping.items(): |
| 353 | module_element = OperatorGraph( |
| 354 | graph_name=module_key[0], |
| 355 | elements=module_nodes, |
| 356 | metadata={"module_type": module_key[1]}, |
| 357 | ) |
| 358 | module_graphs.append(module_element) |
| 359 | |
| 360 | # Remove module modes from main graph |
| 361 | for node in module_nodes: |
| 362 | nodes.pop(node.name) |
| 363 | |
| 364 | main_nodes = [ |
| 365 | node |
| 366 | for name, node in nodes.items() |
| 367 | if name not in input_nodes |
| 368 | and name not in output_nodes |
| 369 | and name not in out_variant_output_nodes |
| 370 | ] |
| 371 | main_graph = FXOperatorGraph( |
| 372 | graph_name="forward", elements=main_nodes + module_graphs |
| 373 | ) |
| 374 | input_graph = FXOperatorGraph( |
| 375 | graph_name="inputs", elements=list(input_nodes.values()) |
| 376 | ) |
| 377 | output_graph = FXOperatorGraph( |
| 378 | graph_name="outputs", elements=list(output_nodes.values()) |
| 379 | ) |
| 380 | |
| 381 | return FXOperatorGraph( |
| 382 | graph_name=name, |
| 383 | elements=[input_graph, main_graph, output_graph], |
| 384 | ) |
| 385 | |
| 386 | # Given a dict, extract only the utilized metadata |
| 387 | @staticmethod |
no test coverage detected