Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
801845cc
提交
801845cc
authored
8月 28, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
9月 03, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Skip scan rewrites if there is no Scan Op in the graph
上级
051b32da
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
7 行删除
+21
-7
db.py
pytensor/graph/rewriting/db.py
+9
-5
rewriting.py
pytensor/scan/rewriting.py
+12
-2
没有找到文件。
pytensor/graph/rewriting/db.py
浏览文件 @
801845cc
...
@@ -310,18 +310,21 @@ class EquilibriumDB(RewriteDatabase):
...
@@ -310,18 +310,21 @@ class EquilibriumDB(RewriteDatabase):
"""
"""
def
__init__
(
def
__init__
(
self
,
ignore_newtrees
:
bool
=
True
,
tracks_on_change_inputs
:
bool
=
False
self
,
ignore_newtrees
:
bool
=
True
,
tracks_on_change_inputs
:
bool
=
False
,
eq_rewriter_class
=
pytensor_rewriting
.
EquilibriumGraphRewriter
,
):
):
"""
"""
Parameters
Parameters
----------
----------
ignore_newtrees
ignore_newtrees
If ``False``, apply rewrites to new nodes introduced during
If ``False``, apply rewrites to new nodes introduced during rewritings.
rewriting.
tracks_on_change_inputs
tracks_on_change_inputs
If ``True``, re-apply rewrites on nodes with changed inputs.
If ``True``, re-apply rewrites on nodes with changed inputs.
eq_rewriter_class: EquilibriumGraphRewriter class, optional
The class used to create the equilibrium rewriter. Defaults to EquilibriumGraphRewriter.
"""
"""
super
()
.
__init__
()
super
()
.
__init__
()
...
@@ -329,6 +332,7 @@ class EquilibriumDB(RewriteDatabase):
...
@@ -329,6 +332,7 @@ class EquilibriumDB(RewriteDatabase):
self
.
tracks_on_change_inputs
=
tracks_on_change_inputs
self
.
tracks_on_change_inputs
=
tracks_on_change_inputs
self
.
__final__
:
dict
[
str
,
bool
]
=
{}
self
.
__final__
:
dict
[
str
,
bool
]
=
{}
self
.
__cleanup__
:
dict
[
str
,
bool
]
=
{}
self
.
__cleanup__
:
dict
[
str
,
bool
]
=
{}
self
.
eq_rewriter_class
=
eq_rewriter_class
def
register
(
def
register
(
self
,
self
,
...
@@ -360,7 +364,7 @@ class EquilibriumDB(RewriteDatabase):
...
@@ -360,7 +364,7 @@ class EquilibriumDB(RewriteDatabase):
final_rewriters
=
None
final_rewriters
=
None
if
len
(
cleanup_rewriters
)
==
0
:
if
len
(
cleanup_rewriters
)
==
0
:
cleanup_rewriters
=
None
cleanup_rewriters
=
None
return
pytensor_rewriting
.
EquilibriumGraphRewriter
(
return
self
.
eq_rewriter_class
(
rewriters
,
rewriters
,
max_use_ratio
=
config
.
optdb__max_use_ratio
,
max_use_ratio
=
config
.
optdb__max_use_ratio
,
ignore_newtrees
=
self
.
ignore_newtrees
,
ignore_newtrees
=
self
.
ignore_newtrees
,
...
...
pytensor/scan/rewriting.py
浏览文件 @
801845cc
...
@@ -30,6 +30,7 @@ from pytensor.graph.fg import FunctionGraph, Output
...
@@ -30,6 +30,7 @@ from pytensor.graph.fg import FunctionGraph, Output
from
pytensor.graph.op
import
compute_test_value
from
pytensor.graph.op
import
compute_test_value
from
pytensor.graph.replace
import
clone_replace
from
pytensor.graph.replace
import
clone_replace
from
pytensor.graph.rewriting.basic
import
(
from
pytensor.graph.rewriting.basic
import
(
EquilibriumGraphRewriter
,
GraphRewriter
,
GraphRewriter
,
copy_stack_trace
,
copy_stack_trace
,
in2out
,
in2out
,
...
@@ -2517,12 +2518,21 @@ def scan_push_out_dot1(fgraph, node):
...
@@ -2517,12 +2518,21 @@ def scan_push_out_dot1(fgraph, node):
return
False
return
False
class
ScanEquilibriumGraphRewriter
(
EquilibriumGraphRewriter
):
"""Subclass of EquilibriumGraphRewriter that aborts early if there are no Scan Ops in the graph"""
def
apply
(
self
,
fgraph
,
start_from
=
None
):
if
not
any
(
isinstance
(
node
.
op
,
Scan
)
for
node
in
fgraph
.
apply_nodes
):
return
super
()
.
apply
(
fgraph
=
fgraph
,
start_from
=
start_from
)
# I've added an equilibrium because later scan optimization in the sequence
# I've added an equilibrium because later scan optimization in the sequence
# can make it such that earlier optimizations should apply. However, in
# can make it such that earlier optimizations should apply. However, in
# general I do not expect the sequence to run more then once
# general I do not expect the sequence to run more then once
scan_eqopt1
=
EquilibriumDB
()
scan_eqopt1
=
EquilibriumDB
(
eq_rewriter_class
=
ScanEquilibriumGraphRewriter
)
scan_seqopt1
=
SequenceDB
()
scan_seqopt1
=
SequenceDB
()
scan_eqopt2
=
EquilibriumDB
()
scan_eqopt2
=
EquilibriumDB
(
eq_rewriter_class
=
ScanEquilibriumGraphRewriter
)
# scan_eqopt1 before ShapeOpt at 0.1
# scan_eqopt1 before ShapeOpt at 0.1
# This is needed to don't have ShapeFeature trac old Scan that we
# This is needed to don't have ShapeFeature trac old Scan that we
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论