Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
71618f60
提交
71618f60
authored
9月 12, 2025
作者:
ricardoV94
提交者:
Ricardo Vieira
9月 30, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not recompute toposort in every iteration of FusionOptimizer
It's not really needed as we never expand on the new nodes
上级
9ef575b7
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
8 行增加
和
7 行删除
+8
-7
elemwise.py
pytensor/tensor/rewriting/elemwise.py
+8
-7
没有找到文件。
pytensor/tensor/rewriting/elemwise.py
浏览文件 @
71618f60
...
...
@@ -625,10 +625,10 @@ class FusionOptimizer(GraphRewriter):
def
find_fuseable_subgraph
(
*
,
fg
:
FunctionGraph
,
visited_nodes
:
set
[
Apply
],
fuseable_clients
:
FUSEABLE_MAPPING
,
unfuseable_clients
:
UNFUSEABLE_MAPPING
,
toposort_index
:
dict
[
Apply
,
int
],
)
->
tuple
[
list
[
Variable
],
list
[
Variable
]]:
KT
=
TypeVar
(
"KT"
)
VT
=
TypeVar
(
"VT"
,
list
,
set
)
...
...
@@ -648,8 +648,7 @@ class FusionOptimizer(GraphRewriter):
for
a
in
ancestors
(
variables
,
blockers
=
stop_search_at
)
)
toposort
=
fg
.
toposort
()
for
starting_node
in
toposort
:
for
starting_node
in
toposort_index
:
if
starting_node
in
visited_nodes
:
continue
...
...
@@ -791,7 +790,7 @@ class FusionOptimizer(GraphRewriter):
and
inp
.
owner
not
in
visited_nodes
)
),
key
=
lambda
inp
:
toposort
.
index
(
inp
.
owner
)
,
key
=
lambda
inp
:
toposort
_index
[
inp
.
owner
]
,
reverse
=
True
,
):
fuseable_nodes_to_visit
.
appendleft
(
inp
.
owner
)
...
...
@@ -803,7 +802,7 @@ class FusionOptimizer(GraphRewriter):
for
node
in
fuseable_clients_temp
.
get
(
next_out
,
())
if
node
not
in
visited_nodes
),
key
=
lambda
node
:
toposort
.
index
(
node
)
,
key
=
lambda
node
:
toposort
_index
[
node
]
,
):
fuseable_nodes_to_visit
.
append
(
next_node
)
...
...
@@ -877,20 +876,22 @@ class FusionOptimizer(GraphRewriter):
# client (those that don't fit into 1))
fuseable_clients
,
unfuseable_clients
=
initialize_fuseable_mappings
(
fg
=
fg
)
visited_nodes
:
set
[
Apply
]
=
set
()
toposort_index
=
{
node
:
i
for
i
,
node
in
enumerate
(
fgraph
.
toposort
())}
while
True
:
starting_nodes
=
fg
.
apply_nodes
.
copy
()
try
:
subgraph_inputs
,
subgraph_outputs
=
find_fuseable_subgraph
(
fg
=
fg
,
visited_nodes
=
visited_nodes
,
fuseable_clients
=
fuseable_clients
,
unfuseable_clients
=
unfuseable_clients
,
toposort_index
=
toposort_index
,
)
except
ValueError
:
return
else
:
# The caller is now expected to update fg in place,
# by replacing the subgraph with a Composite Op
starting_nodes
=
fg
.
apply_nodes
.
copy
()
yield
subgraph_inputs
,
subgraph_outputs
# This is where we avoid repeated work by using a stateful
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论