Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0d299695
提交
0d299695
authored
8月 15, 2016
作者:
sentient07
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanups
上级
d73bfb97
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
22 行增加
和
30 行删除
+22
-30
opt.py
theano/gof/opt.py
+13
-25
optdb.py
theano/gof/optdb.py
+2
-2
opt.py
theano/tensor/opt.py
+7
-3
没有找到文件。
theano/gof/opt.py
浏览文件 @
0d299695
...
@@ -200,7 +200,7 @@ class SeqOptimizer(Optimizer, list):
...
@@ -200,7 +200,7 @@ class SeqOptimizer(Optimizer, list):
opts : List
opts : List
The List of optimizers to be applied to a node
The List of optimizers to be applied to a node
kw : Dict
kw : Dict
Dictonary containing failure call
back message
Dictonary containing failure call
back. The only supported keyword is `failure_callback`.
"""
"""
if
len
(
opts
)
==
1
and
isinstance
(
opts
[
0
],
(
list
,
tuple
)):
if
len
(
opts
)
==
1
and
isinstance
(
opts
[
0
],
(
list
,
tuple
)):
...
@@ -1238,8 +1238,8 @@ def local_optimizer(tracks, inplace=False, requirements=()):
...
@@ -1238,8 +1238,8 @@ def local_optimizer(tracks, inplace=False, requirements=()):
class
LocalOptGroup
(
LocalOptimizer
):
class
LocalOptGroup
(
LocalOptimizer
):
"""
"""
Takes a list of LocalOptimizer and applies them to the nodes.
Takes a list of LocalOptimizer and applies them to the nodes.
When apply_all_opts is set to True, it tries multiple optimization to a node
.
If apply_all_opts is False, it will return after the first optimizer applied
.
A node is first optimized and the list of optimizers for the optimized node is applied
Otherwise, it will start again with the node returned by the previous optimizer.
Parameters
Parameters
----------
----------
...
@@ -1291,35 +1291,30 @@ class LocalOptGroup(LocalOptimizer):
...
@@ -1291,35 +1291,30 @@ class LocalOptGroup(LocalOptimizer):
if
len
(
self
.
opts
)
==
0
:
if
len
(
self
.
opts
)
==
0
:
return
return
def
compute_opts
(
node
):
def
apply_mult_opts
(
node
,
multiple_opts
=
False
):
opts
=
self
.
track_map
.
get
(
type
(
node
.
op
),
[])
opts
+=
self
.
track_map
.
get
(
node
.
op
,
[])
opts
+=
self
.
track_map
.
get
(
None
,
[])
return
opts
def
apply_mult_opts
(
opt_list
,
node
,
multiple_opts
=
False
):
repl
=
False
repl
=
False
opts
=
[]
opts
.
append
(
self
.
track_map
.
get
(
type
(
node
.
op
),
[])
+
self
.
track_map
.
get
(
node
.
op
,
[])
+
self
.
track_map
.
get
(
None
,
[]))
for
opt
in
opt
_list
:
for
opt
in
opt
s
:
opt_start
=
time
.
time
()
opt_start
=
time
.
time
()
repl
=
opt
.
transform
(
node
)
repl
=
opt
.
transform
(
node
)
opt_finish
=
time
.
time
()
opt_finish
=
time
.
time
()
self
.
time_opts
[
opt
]
=
opt_start
-
opt_finish
self
.
process_count
[
opt
]
+=
1
if
not
repl
:
if
not
repl
:
continue
continue
else
:
else
:
self
.
time_opts
[
opt
]
=
opt_start
-
opt_finish
self
.
process_count
[
opt
]
+=
1
if
not
multiple_opts
or
not
repl
[
0
]
.
owner
:
if
not
multiple_opts
or
not
repl
[
0
]
.
owner
:
return
repl
return
repl
assert
len
(
repl
)
==
1
assert
len
(
repl
)
==
1
# Ensuring not the input of graph
# Ensuring not the input of graph
assert
repl
[
0
]
.
owner
assert
repl
[
0
]
.
owner
new_node
=
repl
[
0
]
.
owner
new_node
=
repl
[
0
]
.
owner
new_opts
=
compute_opts
(
new_node
)
apply_mult_opts
(
new_node
,
True
)
apply_mult_opts
(
new_opts
,
new_node
,
True
)
return
repl
return
repl
node_start
=
time
.
time
()
node_start
=
time
.
time
()
new_var
=
apply_mult_opts
(
compute_opts
(
node
),
node
,
self
.
apply_all_opts
)
new_var
=
apply_mult_opts
(
node
,
self
.
apply_all_opts
)
node_finish
=
time
.
time
()
node_finish
=
time
.
time
()
self
.
time_nodes
[
node
]
=
node_finish
-
node_start
self
.
time_nodes
[
node
]
=
node_finish
-
node_start
return
new_var
return
new_var
...
@@ -1344,7 +1339,7 @@ class LocalOptGroup(LocalOptimizer):
...
@@ -1344,7 +1339,7 @@ class LocalOptGroup(LocalOptimizer):
file
=
stream
)
file
=
stream
)
count_opt
.
sort
()
count_opt
.
sort
()
for
(
t
,
count
,
o
)
in
count_opt
[::
-
1
]:
for
(
t
,
count
,
o
)
in
count_opt
[::
-
1
]:
print
(
blanc
,
'
%.3
fs -
%
d -
%
d -
%
s'
%
(
print
(
blanc
,
'
%.3
fs -
%
d -
%
s'
%
(
t
,
count
,
o
),
file
=
stream
)
t
,
count
,
o
),
file
=
stream
)
print
(
blanc
,
'
%.3
fs - in
%
d optimization that were not used (display those with runtime greater than 0)'
%
(
print
(
blanc
,
'
%.3
fs - in
%
d optimization that were not used (display those with runtime greater than 0)'
%
(
not_used_time
,
len
(
not_used
)),
file
=
stream
)
not_used_time
,
len
(
not_used
)),
file
=
stream
)
...
@@ -1356,7 +1351,6 @@ class LocalOptGroup(LocalOptimizer):
...
@@ -1356,7 +1351,6 @@ class LocalOptGroup(LocalOptimizer):
print
(
file
=
stream
)
print
(
file
=
stream
)
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
blanc
=
(
' '
*
level
)
print
(
"
%
s
%
s id=
%
i"
%
(
print
(
"
%
s
%
s id=
%
i"
%
(
(
' '
*
level
),
self
.
__class__
.
__name__
,
id
(
self
)),
file
=
stream
)
(
' '
*
level
),
self
.
__class__
.
__name__
,
id
(
self
)),
file
=
stream
)
if
depth
!=
0
:
if
depth
!=
0
:
...
@@ -1874,12 +1868,6 @@ class NavigatorOptimizer(Optimizer):
...
@@ -1874,12 +1868,6 @@ class NavigatorOptimizer(Optimizer):
if
u
is
not
None
:
if
u
is
not
None
:
fgraph
.
remove_feature
(
u
)
fgraph
.
remove_feature
(
u
)
@staticmethod
def
print_profile
(
stream
,
prof
,
level
=
0
):
import
pdb
pdb
.
set_trace
()
def
process_node
(
self
,
fgraph
,
node
,
lopt
=
None
):
def
process_node
(
self
,
fgraph
,
node
,
lopt
=
None
):
"""
"""
This function will use `lopt` to `transform` the `node`. The
This function will use `lopt` to `transform` the `node`. The
...
@@ -2059,7 +2047,7 @@ class TopoOptimizer(NavigatorOptimizer):
...
@@ -2059,7 +2047,7 @@ class TopoOptimizer(NavigatorOptimizer):
def
out2in
(
*
local_opts
,
**
kwargs
):
def
out2in
(
*
local_opts
,
**
kwargs
):
"""
"""
Uses the TopoOptimizer from the output nodes to input nodes of the graph.
Uses the TopoOptimizer from the output nodes to input nodes of the graph.
"""
"""
name
=
(
kwargs
and
kwargs
.
pop
(
'name'
,
None
))
name
=
(
kwargs
and
kwargs
.
pop
(
'name'
,
None
))
...
...
theano/gof/optdb.py
浏览文件 @
0d299695
...
@@ -322,7 +322,7 @@ class SequenceDB(DB):
...
@@ -322,7 +322,7 @@ class SequenceDB(DB):
def
register
(
self
,
name
,
obj
,
position
,
*
tags
):
def
register
(
self
,
name
,
obj
,
position
,
*
tags
):
super
(
SequenceDB
,
self
)
.
register
(
name
,
obj
,
*
tags
)
super
(
SequenceDB
,
self
)
.
register
(
name
,
obj
,
*
tags
)
if
position
==
'last'
:
if
position
==
'last'
:
self
.
__position__
[
name
]
=
len
(
self
.
__position__
)
self
.
position
[
name
]
=
max
(
self
.
position
.
values
()
)
else
:
else
:
assert
isinstance
(
position
,
(
integer_types
,
float
))
assert
isinstance
(
position
,
(
integer_types
,
float
))
self
.
__position__
[
name
]
=
position
self
.
__position__
[
name
]
=
position
...
@@ -417,7 +417,7 @@ class LocalGroupDB(DB):
...
@@ -417,7 +417,7 @@ class LocalGroupDB(DB):
class
TopoDB
(
DB
):
class
TopoDB
(
DB
):
"""
"""
Generate a
local o
ptimizer of type TopoOptimizer.
Generate a
Global O
ptimizer of type TopoOptimizer.
"""
"""
...
...
theano/tensor/opt.py
浏览文件 @
0d299695
...
@@ -1730,7 +1730,6 @@ compile.optdb.register('local_elemwise_alloc',
...
@@ -1730,7 +1730,6 @@ compile.optdb.register('local_elemwise_alloc',
1.52
,
'fast_run'
)
1.52
,
'fast_run'
)
@register_canonicalize
(
"fast_compile"
)
@register_useless
@register_useless
@gof.local_optimizer
([
T
.
fill
])
@gof.local_optimizer
([
T
.
fill
])
def
local_useless_fill
(
node
):
def
local_useless_fill
(
node
):
...
@@ -2558,7 +2557,6 @@ def local_useless_slice(node):
...
@@ -2558,7 +2557,6 @@ def local_useless_slice(node):
return
[
out
]
return
[
out
]
@register_useless
@register_canonicalize
@register_canonicalize
@register_specialize
@register_specialize
@gof.local_optimizer
([
Subtensor
,
AdvancedSubtensor1
])
@gof.local_optimizer
([
Subtensor
,
AdvancedSubtensor1
])
...
@@ -3010,7 +3008,13 @@ def local_subtensor_merge(node):
...
@@ -3010,7 +3008,13 @@ def local_subtensor_merge(node):
@register_specialize
@register_specialize
@gof.local_optimizer
([
Subtensor
])
@gof.local_optimizer
([
Subtensor
])
def
local_subtensor_of_alloc
(
node
):
def
local_subtensor_of_alloc
(
node
):
"""alloc[x:y] -> alloc"""
"""
alloc(val)[x:y] -> alloc(val[...])
alloc(val)[x:y] -> alloc(val)
This can be seen as a lift, but it also reduce the number of computation/memory.
"""
if
not
isinstance
(
node
.
op
,
Subtensor
):
if
not
isinstance
(
node
.
op
,
Subtensor
):
return
False
return
False
u
=
node
.
inputs
[
0
]
u
=
node
.
inputs
[
0
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论