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

Function _fixup_output_node

exir/lowered_backend_module.py:362–379  ·  view source on GitHub ↗
(gm: torch.fx.GraphModule)

Source from the content-addressed store, hash-verified

360
361# TODO(zhxchen17) Try ExportPass
362def _fixup_output_node(gm: torch.fx.GraphModule) -> None:
363 for node in reversed(gm.graph.nodes):
364 if node.op == "output":
365 with gm.graph.inserting_before(node):
366 assert len(node.args) == 1
367 outputs = node.args[0]
368 if isinstance(outputs, torch.fx.Node):
369 val = outputs.meta.get("val")
370 if isinstance(val, list):
371 # If a list is returned, in some cases it is represented as a
372 # singular node, like `split_copy_tensor` but EXIR will return a
373 # opened-up list like `[getitem1, getitem2]`
374 outputs = [
375 torch.fx.Proxy(outputs)[i].node for i in range(len(val))
376 ]
377 returns, out_spec = pytree.tree_flatten(outputs)
378 node.args = (returns,)
379 return
380
381
382def arrange_graph_placeholders(

Callers 1

Calls 2

inserting_beforeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected