Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3f597994
提交
3f597994
authored
5月 09, 2013
作者:
Ian Goodfellow
提交者:
Frederic
7月 09, 2013
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
check shapes of gradients
上级
85db6f61
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
33 行增加
和
0 行删除
+33
-0
gradient.py
theano/gradient.py
+33
-0
没有找到文件。
theano/gradient.py
浏览文件 @
3f597994
...
@@ -22,6 +22,7 @@ from theano import gof
...
@@ -22,6 +22,7 @@ from theano import gof
from
theano.gof
import
Variable
from
theano.gof
import
Variable
from
theano.gof.python25
import
OrderedDict
from
theano.gof.python25
import
OrderedDict
from
theano.gof.null_type
import
NullType
from
theano.gof.null_type
import
NullType
from
theano.gof.op
import
get_debug_values
# we can't do "import theano.tensor"
# we can't do "import theano.tensor"
# tensor depends on theano.compile
# tensor depends on theano.compile
...
@@ -897,6 +898,27 @@ def _populate_grad_dict(var_to_app_to_idx,
...
@@ -897,6 +898,27 @@ def _populate_grad_dict(var_to_app_to_idx,
assert
(
getattr
(
ng
.
type
,
'dtype'
,
None
)
assert
(
getattr
(
ng
.
type
,
'dtype'
,
None
)
not
in
theano
.
tensor
.
discrete_dtypes
)
not
in
theano
.
tensor
.
discrete_dtypes
)
# If config.compute_test_value is turned on, check that the gradients
# on the outputs of this node have the right shape.
# We also check the gradient on the inputs later--both checks are needed,
# because some gradients are only ever specified by the user, not computed
# by Op.grad, and some gradients are only computed and returned, but never
# passed as another node's output grads.
for
idx
,
packed
in
enumerate
(
izip
(
node
.
outputs
,
new_output_grads
)):
orig_output
,
new_output_grad
=
packed
if
not
hasattr
(
orig_output
,
'shape'
):
continue
for
orig_output_v
,
new_output_grad_v
in
get_debug_values
(
node
.
outputs
,
new_output_grads
):
o_shape
=
orig_output_v
.
shape
g_shape
=
new_output_grad_v
.
shape
if
o_shape
!=
g_shape
:
raise
ValueError
(
"Got a gradient of shape "
+
\
str
(
o_shape
)
+
" on an output of shape "
+
\
str
(
g_shape
))
input_grads
=
node
.
op
.
grad
(
inputs
,
new_output_grads
)
input_grads
=
node
.
op
.
grad
(
inputs
,
new_output_grads
)
if
input_grads
is
None
:
if
input_grads
is
None
:
...
@@ -936,6 +958,17 @@ def _populate_grad_dict(var_to_app_to_idx,
...
@@ -936,6 +958,17 @@ def _populate_grad_dict(var_to_app_to_idx,
'the grad_undefined or grad_unimplemented helper '
'the grad_undefined or grad_unimplemented helper '
'functions.'
)
%
node
.
op
)
'functions.'
)
%
node
.
op
)
# Check that the gradient term for this input has the right shape
if
hasattr
(
term
,
'shape'
):
orig_ipt
=
inputs
[
i
]
for
orig_ipt_v
,
term_v
in
get_debug_values
(
orig_ipt
,
term
):
i_shape
=
orig_ipt_v
.
shape
t_shape
=
term_v
.
shape
if
i_shape
!=
t_shape
:
raise
ValueError
(
"
%
s.grad returned object of "
"shape
%
s as gradient term on input of "
"shape
%
s"
%
(
node
.
op
,
t_shape
,
i_shape
))
if
not
isinstance
(
term
.
type
,
if
not
isinstance
(
term
.
type
,
(
NullType
,
DisconnectedType
)):
(
NullType
,
DisconnectedType
)):
if
term
.
type
.
dtype
not
in
theano
.
tensor
.
float_dtypes
:
if
term
.
type
.
dtype
not
in
theano
.
tensor
.
float_dtypes
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论