Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c356183f
提交
c356183f
authored
7月 17, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3152 from carriepl/scan_aswhile_opt
Don't push out the outputs of an 'as_while' Scan
上级
9df4e5dd
116eecaa
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
43 行增加
和
1 行删除
+43
-1
scan_opt.py
theano/scan_module/scan_opt.py
+6
-1
test_scan.py
theano/scan_module/tests/test_scan.py
+37
-0
没有找到文件。
theano/scan_module/scan_opt.py
浏览文件 @
c356183f
...
...
@@ -612,8 +612,13 @@ class PushOutScanOutput(gof.Optimizer):
fgraph
.
attach_feature
(
gof
.
toolbox
.
ReplaceValidate
())
def
apply
(
self
,
fgraph
):
# Don't perform the optimization on as_while scans. Because these scans
# don't run for a predetermined number of steps, handling them is
# more complicated and this optimization doesn't support it at the
# moment.
nodelist
=
[
x
for
x
in
fgraph
.
toposort
()
if
isinstance
(
x
.
op
,
scan_op
.
Scan
)]
if
(
isinstance
(
x
.
op
,
scan_op
.
Scan
)
and
not
x
.
op
.
as_while
)]
for
node
in
nodelist
:
# Process the node as long as something gets optimized
while
node
!=
None
:
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
c356183f
...
...
@@ -3029,6 +3029,43 @@ class T_Scan(unittest.TestCase):
sol
[:,
:]
=
v_out
utt
.
assert_allclose
(
sol
,
f
(
v_h
,
v_W1
,
v_W2
))
def
test_pushout_while
(
self
):
# Ensure that the optimizations for Scan that push computation out of
# the Scan don't alter the result for 'as_while' scans.
W1
=
tensor
.
matrix
(
'W1'
)
W2
=
tensor
.
matrix
(
'W2'
)
step_indices
=
tensor
.
vector
(
'step_indices'
)
def
lambda_fn
(
step_idx
,
W1
,
W2
):
until_condition
=
theano
.
scan_module
.
until
(
step_idx
>
2
)
return
tensor
.
dot
(
W1
,
W2
),
until_condition
# Compile a function with the optimization
o
,
_
=
theano
.
scan
(
lambda_fn
,
sequences
=
[
step_indices
,
W1
],
non_sequences
=
[
W2
],
n_steps
=
5
)
f
=
theano
.
function
([
W1
,
W2
,
step_indices
],
o
,
mode
=
mode_with_opt
)
# Compule an theano function without the optimization
o
,
_
=
theano
.
scan
(
lambda_fn
,
sequences
=
[
step_indices
,
W1
],
non_sequences
=
[
W2
],
n_steps
=
5
,
mode
=
'FAST_COMPILE'
)
f_ref
=
theano
.
function
([
W1
,
W2
,
step_indices
],
o
,
mode
=
'FAST_COMPILE'
)
# Compare the results of the two implementations
input_values
=
[
numpy
.
random
.
random
((
5
,
5
))
.
astype
(
"float32"
),
numpy
.
random
.
random
((
5
,
5
))
.
astype
(
"float32"
),
numpy
.
arange
(
5
)
.
astype
(
"float32"
)]
out
=
f
(
*
input_values
)
out_ref
=
f_ref
(
*
input_values
)
utt
.
assert_allclose
(
out
,
out_ref
)
def
test_pushout
(
self
):
W1
=
tensor
.
matrix
(
'W1'
)
W2
=
tensor
.
matrix
(
'W2'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论