Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5d3e508f
提交
5d3e508f
authored
10月 05, 2012
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix for the grad method
上级
8f087c62
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
39 行增加
和
6 行删除
+39
-6
scan_op.py
theano/scan_module/scan_op.py
+39
-6
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
5d3e508f
...
...
@@ -1198,6 +1198,37 @@ class Scan(PureOp):
for
o
,
x
in
izip
(
node
.
outputs
,
scan_outs
)]
return
scan_outs
def
get_input_pos
(
self
,
output_index
):
ipos
=
0
opos
=
output_index
for
otaps
,
itaps
in
zip
(
self
.
mitmot_out_taps
(),
self
.
mitmot_taps
()):
if
len
(
otaps
)
>
opos
:
return
ipos
else
:
opos
=
opos
-
len
(
otaps
)
ipos
+=
len
(
itaps
)
for
dx
,
taps
in
enumerate
(
self
.
mitsot_taps
()):
if
opos
==
0
:
return
ipos
else
:
opos
=
opos
-
1
ipos
+=
len
(
taps
)
if
opos
<
self
.
info
[
'n_sit_sot'
]:
return
ipos
+
opos
else
:
return
-
1
def
get_output_slice_idx
(
self
,
output_index
):
ipos
=
0
opos
=
output_index
for
otaps
in
zip
(
self
.
mitmot_out_taps
()):
if
len
(
otaps
)
>
0
:
return
ipos
else
:
opos
=
opos
-
1
ipos
+=
len
(
otaps
)
return
ipos
+
opos
### GRAD FUNCTION
def
grad
(
self
,
args
,
g_outs
):
...
...
@@ -1303,12 +1334,12 @@ class Scan(PureOp):
# 7.3. compute gradients of the inputs given one output
for
dx
,
out
in
enumerate
(
clean_outputs
):
if
g_outs
[
dx
]
!=
None
:
inner_g_out
=
safe_new
(
g_outs
[
dx
][
0
])
input_pos
=
self
.
get_input_pos
(
dx
)
if
input_pos
>=
0
:
corresponding_input
=
self_inputs
[
input_pos
]
tmp
=
tensor
.
grad
(
out
.
sum
(),
corresponding_input
)
inner_g_out
=
safe_new
(
tmp
)
else
:
# We do not have a gradient on this output so we need a
# placeholder, which for now has the same dtype as the
# output
inner_g_out
=
safe_new
(
out
)
###
#### I need to clip the gradient HERE !!
...
...
@@ -1356,7 +1387,9 @@ class Scan(PureOp):
# this try is for catching non ndarray inputs (random
# states) it is more of a safety check ( all random
# states should be after n_outs_not_shared ...
g_outs
[
i
]
=
tensor
.
zeros_like
(
scan_outputs
[
i
])
g_outs
[
i
]
=
tensor
.
cast
(
tensor
.
zeros_like
(
scan_outputs
[
i
]),
inner_gfn_outs
[
self
.
get_output_slice_idx
(
i
)]
.
dtype
)
except
Exception
:
g_outs
[
i
]
=
theano
.
tensor
.
constant
(
numpy
.
array
(
0
,
theano
.
config
.
floatX
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论