Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7f031251
提交
7f031251
authored
2月 24, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
2月 25, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow ignoring printing of specific rewrites from optimizer_verbose
上级
5008fab7
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
77 行增加
和
8 行删除
+77
-8
configdefaults.py
pytensor/configdefaults.py
+8
-1
configparser.py
pytensor/configparser.py
+1
-0
features.py
pytensor/graph/features.py
+8
-1
fg.py
pytensor/graph/fg.py
+11
-3
basic.py
pytensor/graph/rewriting/basic.py
+9
-3
test_fg.py
tests/graph/test_fg.py
+40
-0
没有找到文件。
pytensor/configdefaults.py
浏览文件 @
7f031251
...
...
@@ -418,11 +418,18 @@ def add_compile_configvars():
config
.
add
(
"optimizer_verbose"
,
"
If True, we print all optimization being applied
"
,
"
Print information about rewrites that are applied during a graph transformation.
"
,
BoolParam
(
False
),
in_c_key
=
False
,
)
config
.
add
(
"optimizer_verbose_ignore"
,
"Do not print information for rewrites with these names when `optimizer_verbose` is `True`. Separate names with ','"
,
StrParam
(
""
),
in_c_key
=
False
,
)
config
.
add
(
"on_opt_error"
,
(
...
...
pytensor/configparser.py
浏览文件 @
7f031251
...
...
@@ -81,6 +81,7 @@ class PyTensorConfigParser:
allow_gc
:
bool
optimizer
:
str
optimizer_verbose
:
bool
optimizer_verbose_ignore
:
str
on_opt_error
:
str
nocleanup
:
bool
on_unused_input
:
str
...
...
pytensor/graph/features.py
浏览文件 @
7f031251
...
...
@@ -567,6 +567,13 @@ class ReplaceValidate(History, Validator):
if
verbose
is
None
:
verbose
=
config
.
optimizer_verbose
if
verbose
:
print_reason
=
True
if
config
.
optimizer_verbose_ignore
:
print_reason
=
str
(
reason
)
not
in
config
.
optimizer_verbose_ignore
.
split
(
","
)
for
r
,
new_r
in
replacements
:
try
:
fgraph
.
replace
(
r
,
new_r
,
reason
=
reason
,
verbose
=
False
,
**
kwargs
)
...
...
@@ -608,7 +615,7 @@ class ReplaceValidate(History, Validator):
)
raise
if
verbose
:
if
verbose
and
print_reason
:
print
(
# noqa: T201
f
"rewriting: rewrite {reason} replaces {r} of {r.owner} with {new_r} of {new_r.owner}"
)
...
...
pytensor/graph/fg.py
浏览文件 @
7f031251
...
...
@@ -490,10 +490,18 @@ class FunctionGraph(MetaObject):
"""
if
verbose
is
None
:
verbose
=
config
.
optimizer_verbose
if
verbose
:
print
(
# noqa: T201
f
"rewriting: rewrite {reason} replaces {var} of {var.owner} with {new_var} of {new_var.owner}"
)
print_reason
=
True
if
config
.
optimizer_verbose_ignore
:
print_reason
=
str
(
reason
)
not
in
config
.
optimizer_verbose_ignore
.
split
(
","
)
if
print_reason
:
print
(
# noqa: T201
f
"rewriting: rewrite {reason} replaces {var} of {var.owner} with {new_var} of {new_var.owner}"
)
new_var
=
var
.
type
.
filter_variable
(
new_var
,
allow_convert
=
True
)
...
...
pytensor/graph/rewriting/basic.py
浏览文件 @
7f031251
...
...
@@ -1305,9 +1305,15 @@ class SequentialNodeRewriter(NodeRewriter):
new_vars
=
list
(
new_repl
.
values
())
if
config
.
optimizer_verbose
:
print
(
# noqa: T201
f
"rewriting: rewrite {rewrite} replaces node {node} with {new_repl}"
)
print_reason
=
True
if
config
.
optimizer_verbose_ignore
:
print_reason
=
str
(
rewrite
)
not
in
config
.
optimizer_verbose_ignore
.
split
(
","
)
if
print_reason
:
print
(
# noqa: T201
f
"rewriting: rewrite {rewrite} replaces node {node} with {new_repl}"
)
if
self
.
profile
:
self
.
node_created
[
rewrite
]
+=
len
(
...
...
tests/graph/test_fg.py
浏览文件 @
7f031251
...
...
@@ -731,3 +731,43 @@ class TestFunctionGraph:
o1
=
op1
(
r1
,
r2
)
fg
=
FunctionGraph
([
r1
,
r2
],
[
o1
],
clone
=
False
)
assert
fg
.
dprint
(
file
=
"str"
)
==
debugprint
(
fg
,
file
=
"str"
)
def
test_optimizer_verbose
(
self
,
capsys
):
x
=
MyVariable
(
"x"
)
y
=
MyVariable
(
"y"
)
z
=
MyVariable
(
"z"
)
o1
=
op1
(
x
,
y
)
fgraph
=
FunctionGraph
([
x
,
y
,
z
],
[
o1
],
clone
=
False
)
with
config
.
change_flags
(
optimizer_verbose
=
False
):
fgraph
.
replace
(
y
,
z
,
reason
=
"y->z"
)
cap_out
=
capsys
.
readouterr
()
.
out
assert
cap_out
==
""
with
config
.
change_flags
(
optimizer_verbose
=
True
):
fgraph
.
replace
(
z
,
y
,
reason
=
"z->y"
)
cap_out
=
capsys
.
readouterr
()
.
out
assert
"z->y"
in
cap_out
with
config
.
change_flags
(
optimizer_verbose
=
True
,
optimizer_verbose_ignore
=
"y->z"
):
fgraph
.
replace
(
y
,
z
,
reason
=
"y->z"
)
fgraph
.
replace
(
z
,
y
,
reason
=
"z->y"
)
cap_out
=
capsys
.
readouterr
()
.
out
assert
"y->z"
not
in
cap_out
assert
"z->y"
in
cap_out
with
config
.
change_flags
(
optimizer_verbose
=
True
,
optimizer_verbose_ignore
=
"y->z,z->y"
):
fgraph
.
replace
(
y
,
z
,
reason
=
"y->z"
)
fgraph
.
replace
(
z
,
y
,
reason
=
"z->y"
)
cap_out
=
capsys
.
readouterr
()
.
out
assert
"y->z"
not
in
cap_out
assert
"z->y"
not
in
cap_out
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论