Skip to content

Conversation

leon062112
Copy link

@leon062112 leon062112 commented Aug 20, 2025

PR Category

Feature Enhancement

Description

  • 一个简易的subrange_graph_extract函数,能够按照给定的节点索引范围对线性的计算图提取子图,正确处理依赖关系(外部输入转 placeholder)和设置输出。
  • 实现简单,目标明确,不过基于索引范围的提取方式很脆弱,且无法处理复杂计算图(无法处理并行分支,多输出的情况)。
  • 下一步打算引入 networkx,建立从 fx.Graph 到 nx.DiGraph 的桥梁,并基于此提供一系列图分析的工具函数,分析计算图拓扑,分析节点间的依赖关系,子图的连通性等。

Demo:
GraphModule:
image
extract [2,5] subrange:
image

Copy link

paddle-bot bot commented Aug 20, 2025

Thanks for your contribution!

external_inputs = set()
for node in selected_nodes:
if hasattr(node, "args") and hasattr(node, "kwargs"):
for arg in itertools.chain(node.args, node.kwargs.values()):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嵌套太深

missing_deps = []
if hasattr(node, "args"):
for arg in node.args:
if isinstance(arg, fx.Node) and arg not in node_map:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嵌套太深

import argparse


def subrange_graph_extract(original_gm: fx.GraphModule, start_idx: int, end_idx: int):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这函数太长了,没法一分钟内理解

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants