Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b129fb77
提交
b129fb77
authored
7月 10, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flake8 theano/gof/opt.py; 2 E left
上级
de08b763
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
35 行增加
和
31 行删除
+35
-31
opt.py
theano/gof/opt.py
+35
-30
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/gof/opt.py
浏览文件 @
b129fb77
...
@@ -29,6 +29,7 @@ from . import destroyhandler as dh
...
@@ -29,6 +29,7 @@ from . import destroyhandler as dh
_logger
=
logging
.
getLogger
(
'theano.gof.opt'
)
_logger
=
logging
.
getLogger
(
'theano.gof.opt'
)
_optimizer_idx
=
[
0
]
_optimizer_idx
=
[
0
]
def
_list_of_nodes
(
fgraph
):
def
_list_of_nodes
(
fgraph
):
return
list
(
graph
.
io_toposort
(
fgraph
.
inputs
,
fgraph
.
outputs
))
return
list
(
graph
.
io_toposort
(
fgraph
.
inputs
,
fgraph
.
outputs
))
...
@@ -729,6 +730,7 @@ def pre_constant_merge(vars):
...
@@ -729,6 +730,7 @@ def pre_constant_merge(vars):
const_sig_inv
=
{}
const_sig_inv
=
{}
if
isinstance
(
vars
,
graph
.
Variable
):
if
isinstance
(
vars
,
graph
.
Variable
):
vars
=
[
vars
]
vars
=
[
vars
]
def
recursive_merge
(
var
):
def
recursive_merge
(
var
):
if
var
in
seen_var
:
if
var
in
seen_var
:
return
var
return
var
...
@@ -761,7 +763,7 @@ def pre_constant_merge(vars):
...
@@ -761,7 +763,7 @@ def pre_constant_merge(vars):
########################
########################
#
## Local Optimizers ##
#
#
Local Optimizers
#
########################
########################
class
LocalOptimizer
(
object
):
class
LocalOptimizer
(
object
):
...
@@ -820,9 +822,11 @@ class LocalOptimizer(object):
...
@@ -820,9 +822,11 @@ class LocalOptimizer(object):
(
' '
*
level
),
self
.
__class__
.
__name__
,
id
(
self
)),
file
=
stream
)
(
' '
*
level
),
self
.
__class__
.
__name__
,
id
(
self
)),
file
=
stream
)
theano
.
configparser
.
AddConfigVar
(
'metaopt.verbose'
,
theano
.
configparser
.
AddConfigVar
(
'metaopt.verbose'
,
"Enable verbose output for meta optimizers"
,
"Enable verbose output for meta optimizers"
,
theano
.
configparser
.
BoolParam
(
False
),
in_c_key
=
False
)
theano
.
configparser
.
BoolParam
(
False
),
in_c_key
=
False
)
class
LocalMetaOptimizer
(
LocalOptimizer
):
class
LocalMetaOptimizer
(
LocalOptimizer
):
...
@@ -1217,6 +1221,7 @@ class PatternSub(LocalOptimizer):
...
@@ -1217,6 +1221,7 @@ class PatternSub(LocalOptimizer):
if
node
.
op
!=
self
.
op
:
if
node
.
op
!=
self
.
op
:
return
False
return
False
# TODO: if we remove pdb, do this speed things up?
# TODO: if we remove pdb, do this speed things up?
def
match
(
pattern
,
expr
,
u
,
allow_multiple_clients
=
False
,
pdb
=
False
):
def
match
(
pattern
,
expr
,
u
,
allow_multiple_clients
=
False
,
pdb
=
False
):
# TODO move outside match
# TODO move outside match
def
retry_with_equiv
():
def
retry_with_equiv
():
...
@@ -1233,9 +1238,8 @@ class PatternSub(LocalOptimizer):
...
@@ -1233,9 +1238,8 @@ class PatternSub(LocalOptimizer):
if
isinstance
(
pattern
,
(
list
,
tuple
)):
if
isinstance
(
pattern
,
(
list
,
tuple
)):
if
expr
.
owner
is
None
:
if
expr
.
owner
is
None
:
return
False
return
False
if
(
not
(
expr
.
owner
.
op
==
pattern
[
0
])
if
(
not
(
expr
.
owner
.
op
==
pattern
[
0
])
or
or
(
not
allow_multiple_clients
(
not
allow_multiple_clients
and
len
(
expr
.
clients
)
>
1
)):
and
len
(
expr
.
clients
)
>
1
)):
return
retry_with_equiv
()
return
retry_with_equiv
()
if
len
(
pattern
)
-
1
!=
len
(
expr
.
owner
.
inputs
):
if
len
(
pattern
)
-
1
!=
len
(
expr
.
owner
.
inputs
):
return
retry_with_equiv
()
return
retry_with_equiv
()
...
@@ -1263,16 +1267,16 @@ class PatternSub(LocalOptimizer):
...
@@ -1263,16 +1267,16 @@ class PatternSub(LocalOptimizer):
return
retry_with_equiv
()
return
retry_with_equiv
()
else
:
else
:
u
=
u
.
merge
(
expr
,
v
)
u
=
u
.
merge
(
expr
,
v
)
elif
(
isinstance
(
pattern
,
(
int
,
float
))
elif
(
isinstance
(
pattern
,
(
int
,
float
))
and
and
isinstance
(
expr
,
graph
.
Constant
)):
isinstance
(
expr
,
graph
.
Constant
)):
if
numpy
.
all
(
if
numpy
.
all
(
theano
.
tensor
.
constant
(
pattern
)
.
value
==
expr
.
value
):
theano
.
tensor
.
constant
(
pattern
)
.
value
==
expr
.
value
):
return
u
return
u
else
:
else
:
return
retry_with_equiv
()
return
retry_with_equiv
()
elif
(
isinstance
(
pattern
,
graph
.
Constant
)
elif
(
isinstance
(
pattern
,
graph
.
Constant
)
and
and
isinstance
(
expr
,
graph
.
Constant
)
isinstance
(
expr
,
graph
.
Constant
)
and
and
pattern
.
equals
(
expr
)):
pattern
.
equals
(
expr
)):
return
u
return
u
else
:
else
:
return
retry_with_equiv
()
return
retry_with_equiv
()
...
@@ -1335,7 +1339,7 @@ class PatternSub(LocalOptimizer):
...
@@ -1335,7 +1339,7 @@ class PatternSub(LocalOptimizer):
##################
##################
#
## Navigators ##
#
#
Navigators
#
##################
##################
# Use the following classes to apply LocalOptimizers
# Use the following classes to apply LocalOptimizers
...
@@ -1811,8 +1815,8 @@ class EquilibriumOptimizer(NavigatorOptimizer):
...
@@ -1811,8 +1815,8 @@ class EquilibriumOptimizer(NavigatorOptimizer):
node_created
[
gopt
]
+=
change_tracker
.
nb_imported
-
nb
node_created
[
gopt
]
+=
change_tracker
.
nb_imported
-
nb
if
global_process_count
[
gopt
]
>
max_use
:
if
global_process_count
[
gopt
]
>
max_use
:
max_use_abort
=
True
max_use_abort
=
True
opt_name
=
(
getattr
(
gopt
,
"name"
,
None
)
opt_name
=
(
getattr
(
gopt
,
"name"
,
None
)
or
or
getattr
(
gopt
,
"__name__"
,
""
))
getattr
(
gopt
,
"__name__"
,
""
))
global_sub_profs
.
append
(
sub_profs
)
global_sub_profs
.
append
(
sub_profs
)
global_opt_timing
.
append
(
float
(
time
.
time
()
-
t0
))
global_opt_timing
.
append
(
float
(
time
.
time
()
-
t0
))
...
@@ -1858,8 +1862,8 @@ class EquilibriumOptimizer(NavigatorOptimizer):
...
@@ -1858,8 +1862,8 @@ class EquilibriumOptimizer(NavigatorOptimizer):
node_created
[
lopt
]
+=
change_tracker
.
nb_imported
-
nb
node_created
[
lopt
]
+=
change_tracker
.
nb_imported
-
nb
if
global_process_count
[
lopt
]
>
max_use
:
if
global_process_count
[
lopt
]
>
max_use
:
max_use_abort
=
True
max_use_abort
=
True
opt_name
=
(
getattr
(
lopt
,
"name"
,
None
)
opt_name
=
(
getattr
(
lopt
,
"name"
,
None
)
or
or
getattr
(
lopt
,
"__name__"
,
""
))
getattr
(
lopt
,
"__name__"
,
""
))
if
node
not
in
fgraph
.
apply_nodes
:
if
node
not
in
fgraph
.
apply_nodes
:
# go to next node
# go to next node
break
break
...
@@ -1884,8 +1888,8 @@ class EquilibriumOptimizer(NavigatorOptimizer):
...
@@ -1884,8 +1888,8 @@ class EquilibriumOptimizer(NavigatorOptimizer):
node_created
[
gopt
]
+=
change_tracker
.
nb_imported
-
nb
node_created
[
gopt
]
+=
change_tracker
.
nb_imported
-
nb
if
global_process_count
[
gopt
]
>
max_use
:
if
global_process_count
[
gopt
]
>
max_use
:
max_use_abort
=
True
max_use_abort
=
True
opt_name
=
(
getattr
(
gopt
,
"name"
,
None
)
opt_name
=
(
getattr
(
gopt
,
"name"
,
None
)
or
or
getattr
(
gopt
,
"__name__"
,
""
))
getattr
(
gopt
,
"__name__"
,
""
))
final_sub_profs
.
append
(
sub_profs
)
final_sub_profs
.
append
(
sub_profs
)
global_opt_timing
[
-
1
]
+=
time
.
time
()
-
t_before_final_opt
global_opt_timing
[
-
1
]
+=
time
.
time
()
-
t_before_final_opt
...
@@ -1896,9 +1900,9 @@ class EquilibriumOptimizer(NavigatorOptimizer):
...
@@ -1896,9 +1900,9 @@ class EquilibriumOptimizer(NavigatorOptimizer):
end_nb_nodes
=
len
(
fgraph
.
apply_nodes
)
end_nb_nodes
=
len
(
fgraph
.
apply_nodes
)
if
max_use_abort
:
if
max_use_abort
:
_logger
.
error
(
"EquilibriumOptimizer max'ed out by '
%
s'"
%
opt_name
_logger
.
error
(
"EquilibriumOptimizer max'ed out by '
%
s'"
%
opt_name
+
+
". You can safely raise the current threshold of "
". You can safely raise the current threshold of "
+
+
"
%
f with the theano flag 'optdb.max_use_ratio'."
%
"
%
f with the theano flag 'optdb.max_use_ratio'."
%
config
.
optdb
.
max_use_ratio
)
config
.
optdb
.
max_use_ratio
)
fgraph
.
remove_feature
(
change_tracker
)
fgraph
.
remove_feature
(
change_tracker
)
return
(
self
,
loop_timing
,
loop_process_count
,
return
(
self
,
loop_timing
,
loop_process_count
,
...
@@ -1975,8 +1979,9 @@ class EquilibriumOptimizer(NavigatorOptimizer):
...
@@ -1975,8 +1979,9 @@ class EquilibriumOptimizer(NavigatorOptimizer):
not_used_time
+=
time_opts
[
o
]
not_used_time
+=
time_opts
[
o
]
if
count_opt
:
if
count_opt
:
print
(
blanc
,
\
print
(
blanc
,
' times - times applied - nb node created - name:'
,
file
=
stream
)
' times - times applied - nb node created - name:'
,
file
=
stream
)
count_opt
.
sort
()
count_opt
.
sort
()
for
(
t
,
count
,
n_created
,
o
)
in
count_opt
[::
-
1
]:
for
(
t
,
count
,
n_created
,
o
)
in
count_opt
[::
-
1
]:
print
(
blanc
,
'
%.3
fs -
%
d -
%
d -
%
s'
%
(
print
(
blanc
,
'
%.3
fs -
%
d -
%
d -
%
s'
%
(
...
@@ -2010,7 +2015,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
...
@@ -2010,7 +2015,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
@staticmethod
@staticmethod
def
merge_profile
(
prof1
,
prof2
):
def
merge_profile
(
prof1
,
prof2
):
#(opt, loop_timing, loop_process_count, max_nb_nodes,
#
(opt, loop_timing, loop_process_count, max_nb_nodes,
# global_opt_timing, nb_nodes, time_opts, io_toposort_timing) = prof1
# global_opt_timing, nb_nodes, time_opts, io_toposort_timing) = prof1
local_optimizers
=
OrderedSet
(
prof1
[
0
]
.
get_local_optimizers
())
.
union
(
local_optimizers
=
OrderedSet
(
prof1
[
0
]
.
get_local_optimizers
())
.
union
(
prof2
[
0
]
.
get_local_optimizers
())
prof2
[
0
]
.
get_local_optimizers
())
...
@@ -2085,7 +2090,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
...
@@ -2085,7 +2090,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
final_sub_profs
)
final_sub_profs
)
#################
#################
#
## Utilities ##
#
#
Utilities
#
#################
#################
...
@@ -2096,7 +2101,7 @@ def _check_chain(r, chain):
...
@@ -2096,7 +2101,7 @@ def _check_chain(r, chain):
while
chain
:
while
chain
:
elem
=
chain
.
pop
()
elem
=
chain
.
pop
()
if
elem
is
None
:
if
elem
is
None
:
if
not
r
.
owner
is
None
:
if
r
.
owner
is
not
None
:
return
False
return
False
elif
r
.
owner
is
None
:
elif
r
.
owner
is
None
:
return
False
return
False
...
@@ -2105,20 +2110,20 @@ def _check_chain(r, chain):
...
@@ -2105,20 +2110,20 @@ def _check_chain(r, chain):
return
False
return
False
else
:
else
:
try
:
try
:
if
(
issubclass
(
elem
,
op
.
Op
)
if
(
issubclass
(
elem
,
op
.
Op
)
and
and
not
isinstance
(
r
.
owner
.
op
,
elem
)):
not
isinstance
(
r
.
owner
.
op
,
elem
)):
return
False
return
False
except
TypeError
:
except
TypeError
:
return
False
return
False
if
chain
:
if
chain
:
r
=
r
.
owner
.
inputs
[
chain
.
pop
()]
r
=
r
.
owner
.
inputs
[
chain
.
pop
()]
# print 'check_chain', _check_chain.n_calls
# print 'check_chain', _check_chain.n_calls
#_check_chain.n_calls += 1
#
_check_chain.n_calls += 1
# The return value will be used as a Boolean, but some Variables cannot
# The return value will be used as a Boolean, but some Variables cannot
# be used as Booleans (the results of comparisons, for instance)
# be used as Booleans (the results of comparisons, for instance)
return
(
r
is
not
None
)
return
(
r
is
not
None
)
#_check_chain.n_calls = 0
#
_check_chain.n_calls = 0
def
check_chain
(
r
,
*
chain
):
def
check_chain
(
r
,
*
chain
):
...
...
theano/tests/test_flake8.py
浏览文件 @
b129fb77
...
@@ -244,7 +244,6 @@ whitelist_flake8 = [
...
@@ -244,7 +244,6 @@ whitelist_flake8 = [
"gof/unify.py"
,
"gof/unify.py"
,
"gof/graph.py"
,
"gof/graph.py"
,
"gof/__init__.py"
,
"gof/__init__.py"
,
"gof/opt.py"
,
"gof/link.py"
,
"gof/link.py"
,
"gof/fg.py"
,
"gof/fg.py"
,
"gof/op.py"
,
"gof/op.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论