Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b68c74dc
提交
b68c74dc
authored
10月 06, 2025
作者:
ricardoV94
提交者:
Ricardo Vieira
10月 07, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Small tweaks to FusionOptimizer
上级
1d825dd6
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
11 行删除
+13
-11
elemwise.py
pytensor/tensor/rewriting/elemwise.py
+13
-11
没有找到文件。
pytensor/tensor/rewriting/elemwise.py
浏览文件 @
b68c74dc
...
...
@@ -652,12 +652,12 @@ class FusionOptimizer(GraphRewriter):
# `ancestors_bitset[C] & (node_bitset[A] | node_bitset[B]) != 0`
nodes_bitflags
=
{
node
:
1
<<
i
for
i
,
node
in
enumerate
(
fgraph
.
toposort
())}
# Root variables have `None` as owner, which we can handle with a bitset of 0
ancestors_bitset
=
{
None
:
0
}
ancestors_bitset
s
=
{
None
:
0
}
for
node
,
node_bitflag
in
nodes_bitflags
.
items
():
# The bitset of each node is the union of the bitsets of its inputs, plus its own bit flag
ancestors_bitset
[
node
]
=
reduce
(
ancestors_bitset
s
[
node
]
=
reduce
(
or_
,
(
ancestors_bitset
[
inp
.
owner
]
for
inp
in
node
.
inputs
),
(
ancestors_bitset
s
[
inp
.
owner
]
for
inp
in
node
.
inputs
),
node_bitflag
,
)
# Handle root and leaf nodes gracefully
...
...
@@ -666,10 +666,12 @@ class FusionOptimizer(GraphRewriter):
nodes_bitflags
[
None
]
=
0
# Nothing ever depends on the special Output nodes, so just use a new bit for all of them
out_bitflag
=
1
<<
len
(
nodes_bitflags
)
for
out
in
fg
.
outputs
:
for
client
,
_
in
fg_clients
[
out
]:
if
isinstance
(
client
.
op
,
Output
):
nodes_bitflags
[
client
]
=
out_bitflag
nodes_bitflags
|=
(
(
client
,
out_bitflag
)
for
out
in
fg
.
outputs
for
client
,
_
in
fg_clients
[
out
]
if
isinstance
(
client
.
op
,
Output
)
)
# Start main loop to find collection of fuseable subgraphs
# We store the collection in `sorted_subgraphs`, in reverse topological order
...
...
@@ -726,7 +728,7 @@ class FusionOptimizer(GraphRewriter):
if
node_bitflag
&
unfuseable_ancestors_bitset
:
# An unfuseable ancestor of the subgraph depends on this node, can't fuse
continue
elif
ancestors_bitset
[
node
]
&
unfuseable_clients_bitset
:
elif
ancestors_bitset
s
[
node
]
&
unfuseable_clients_bitset
:
# This node depends on an unfuseable client of the subgraph, can't fuse
continue
...
...
@@ -742,7 +744,7 @@ class FusionOptimizer(GraphRewriter):
for
inp
in
node
.
inputs
:
ancestor_node
=
inp
.
owner
ancestor_bitflag
=
nodes_bitflags
[
ancestor_node
]
if
ancestor_bitflag
&
subgraph_bitset
:
if
(
not
is_ancestor
)
and
(
ancestor_bitflag
&
subgraph_bitset
)
:
continue
if
node
in
fuseable_clients
.
get
(
ancestor_node
,
()):
heappush
(
...
...
@@ -752,14 +754,14 @@ class FusionOptimizer(GraphRewriter):
else
:
# If the node is not in the ancestor's fuseable clients set, it's not fuseable with it,
# nor with any of the ancestor's ancestors
unfuseable_ancestors_bitset
|=
ancestors_bitset
[
unfuseable_ancestors_bitset
|=
ancestors_bitset
s
[
ancestor_node
]
next_fuseable_clients
=
fuseable_clients
.
get
(
node
,
())
for
client
,
_
in
fg_clients
[
node
.
outputs
[
0
]]:
client_bitflag
=
nodes_bitflags
[
client
]
if
client_bitflag
&
subgraph_bitset
:
if
is_ancestor
and
(
client_bitflag
&
subgraph_bitset
)
:
continue
if
client
in
next_fuseable_clients
:
heappush
(
fuseables_nodes_queue
,
(
client_bitflag
,
client
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论