Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9eb0b187
提交
9eb0b187
authored
3月 25, 2011
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moved greedy_local_optimizer to theano/got/opt.py and renamed it to pre_greedy_local_optimizer.
上级
34123842
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
67 行增加
和
68 行删除
+67
-68
opt.py
theano/gof/opt.py
+60
-0
opt.py
theano/tensor/opt.py
+7
-68
没有找到文件。
theano/gof/opt.py
浏览文件 @
9eb0b187
...
...
@@ -1142,6 +1142,66 @@ def check_chain(r, *chain):
return
_check_chain
(
r
,
reduce
(
list
.
__iadd__
,
([
x
,
0
]
for
x
in
chain
)))
def
pre_greedy_local_optimizer
(
list_optimizations
,
out
):
'''
This function traverses the computation graph described by all
``node`` in the graph before the variable out but that are not in the env.
it applies each of the local_optimizations on the traversed graph.
Its main use is to apply locally constant folding when generating
the graph of the indices of a subtensor.
We should not apply optimizations on node that are in env.
So we don't optimize node that have an attribute env.
:note: This don't do an equilibrium... So if there is optimization
like local_upcast_elemwise_constant_inputs in the list, that
add additional node to the inputs of the node, it can
be needed to call this function multiple time.
'''
def
local_recursive_function
(
list_opt
,
out
,
optimized_vars
,
depth
):
if
not
out
.
owner
:
return
[
out
],
optimized_vars
node
=
out
.
owner
if
hasattr
(
node
,
'env'
):
return
node
.
outputs
,
optimized_vars
for
idx
,
inp
in
enumerate
(
node
.
inputs
):
if
inp
in
optimized_vars
:
nw_in
=
optimized_vars
[
inp
]
else
:
if
inp
.
owner
:
outs
,
optimized_vars
=
local_recursive_function
(
list_opt
,
inp
,
optimized_vars
,
depth
+
1
)
for
k
,
v
in
zip
(
inp
.
owner
.
outputs
,
outs
):
optimized_vars
[
k
]
=
v
nw_in
=
outs
[
inp
.
owner
.
outputs
.
index
(
inp
)]
else
:
nw_in
=
inp
optimized_vars
[
inp
]
=
inp
node
.
inputs
[
idx
]
=
nw_in
results
=
node
.
outputs
for
opt
in
list_opt
:
ret
=
opt
.
transform
(
node
)
if
ret
is
not
False
and
ret
is
not
None
:
assert
len
(
ret
)
==
len
(
node
.
outputs
)
for
k
,
v
in
zip
(
node
.
outputs
,
ret
):
optimized_vars
[
k
]
=
v
results
=
ret
if
ret
[
0
]
.
owner
:
node
=
out
.
owner
else
:
break
return
results
,
optimized_vars
final_outs
,
optimized_nodes
=
local_recursive_function
(
list_optimizations
,
out
,
{},
0
)
return
final_outs
[
0
]
...
...
theano/tensor/opt.py
浏览文件 @
9eb0b187
...
...
@@ -25,7 +25,7 @@ import basic as T
from
theano
import
compile
#to register the optimizer built by this file
from
theano.gof.python25
import
any
,
all
from
theano.gof.opt
import
Optimizer
,
pre_constant_merge
from
theano.gof.opt
import
Optimizer
,
pre_constant_merge
,
pre_greedy_local_optimizer
from
theano.gof
import
toolbox
,
DestroyHandler
from
basic
import
get_constant_value
...
...
@@ -1230,67 +1230,6 @@ def local_subtensor_lift(node):
return
[
u
.
owner
.
op
(
*
new_inputs
)]
def
greedy_local_optimizer
(
list_optimizations
,
out
):
'''
This function traverses the computation graph described by all
``node`` in the graph before the variable out but that are not in the env.
it applies each of the local_optimizations on the traversed graph.
Its main use is to apply locally constant folding when generating
the graph of the indices of a subtensor.
We should not apply optimizations on node that are in env.
So we don't optimize node that have an attribute env.
:note: This don't do an equilibrium... So if there is optimization
like local_upcast_elemwise_constant_inputs in the list, that
add additional node to the inputs of the node, it can
be needed to call this function multiple time.
'''
def
local_recursive_function
(
list_opt
,
out
,
optimized_vars
,
depth
):
if
not
out
.
owner
:
return
[
out
],
optimized_vars
node
=
out
.
owner
if
hasattr
(
node
,
'env'
):
return
node
.
outputs
,
optimized_vars
for
idx
,
inp
in
enumerate
(
node
.
inputs
):
if
inp
in
optimized_vars
:
nw_in
=
optimized_vars
[
inp
]
else
:
if
inp
.
owner
:
outs
,
optimized_vars
=
local_recursive_function
(
list_opt
,
inp
,
optimized_vars
,
depth
+
1
)
for
k
,
v
in
zip
(
inp
.
owner
.
outputs
,
outs
):
optimized_vars
[
k
]
=
v
nw_in
=
outs
[
inp
.
owner
.
outputs
.
index
(
inp
)]
else
:
nw_in
=
inp
optimized_vars
[
inp
]
=
inp
node
.
inputs
[
idx
]
=
nw_in
results
=
node
.
outputs
for
opt
in
list_opt
:
ret
=
opt
.
transform
(
node
)
if
ret
is
not
False
and
ret
is
not
None
:
assert
len
(
ret
)
==
len
(
node
.
outputs
)
for
k
,
v
in
zip
(
node
.
outputs
,
ret
):
optimized_vars
[
k
]
=
v
results
=
ret
if
ret
[
0
]
.
owner
:
node
=
out
.
owner
else
:
break
return
results
,
optimized_vars
final_outs
,
optimized_nodes
=
local_recursive_function
(
list_optimizations
,
out
,
{},
0
)
return
final_outs
[
0
]
def
merge_two_slices
(
slice1
,
len1
,
slice2
,
len2
):
'''
This function merges two slices into a single slice. The code works on
...
...
@@ -1408,12 +1347,12 @@ def merge_two_slices(slice1, len1, slice2, len2):
# and is not simplified. We simplify it in advance here
# as otherwise this create too many useless optimization that
# DebugMode must check.
start
=
greedy_local_optimizer
(
list_opt
,
start
)
stop
=
greedy_local_optimizer
(
list_opt
,
stop
)
step
=
greedy_local_optimizer
(
list_opt
,
step
)
start
=
greedy_local_optimizer
(
list_opt
,
start
)
stop
=
greedy_local_optimizer
(
list_opt
,
stop
)
step
=
greedy_local_optimizer
(
list_opt
,
step
)
start
=
pre_
greedy_local_optimizer
(
list_opt
,
start
)
stop
=
pre_
greedy_local_optimizer
(
list_opt
,
stop
)
step
=
pre_
greedy_local_optimizer
(
list_opt
,
step
)
start
=
pre_
greedy_local_optimizer
(
list_opt
,
start
)
stop
=
pre_
greedy_local_optimizer
(
list_opt
,
stop
)
step
=
pre_
greedy_local_optimizer
(
list_opt
,
step
)
#Pre merge constant for the same reason.
start
,
stop
,
step
=
pre_constant_merge
([
start
,
stop
,
step
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论