Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f02b01d4
提交
f02b01d4
authored
9月 05, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
got rid of warn_type flag--the new type system doesn't enforce that a
gradient and an input have the same type, so the warning makes no sense
上级
3625c701
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
12 行增加
和
32 行删除
+12
-32
gradient.py
theano/gradient.py
+12
-32
没有找到文件。
theano/gradient.py
浏览文件 @
f02b01d4
...
...
@@ -478,8 +478,7 @@ def grad(cost, wrt, g_cost=None, consider_constant=None, warn_type=False,
cost_name
=
cost
.
name
rval
=
_populate_grad_dict
(
var_to_node_to_idx
,
grad_dict
,
wrt
,
warn_type
,
cost_name
)
grad_dict
,
wrt
,
cost_name
)
for
i
in
xrange
(
len
(
rval
)):
if
isinstance
(
rval
[
i
]
.
type
,
DisconnectedType
):
...
...
@@ -632,7 +631,7 @@ def _populate_var_to_node_to_idx(outputs, wrt):
def
_populate_grad_dict
(
var_to_node_to_idx
,
grad_dict
,
wrt
,
warn_type
,
cost_name
=
None
):
grad_dict
,
wrt
,
cost_name
=
None
):
"""
Common code shared between grad_sources_inputs and grad
...
...
@@ -765,32 +764,17 @@ def _populate_grad_dict(var_to_node_to_idx,
msg
+=
' connection_pattern method for it.'
warnings
.
warn
(
msg
)
# Process out any Nones
for
i
,
term
in
enumerate
(
input_grads
):
# Disallow Nones
if
term
is
None
:
# we don't know what None means. in the past it has been
# used to
# mean undefined, zero, or disconnected. So for now we
# assume it is
# zero. Assuming it is zero prevents
# us from disconnecting NaNs above.
# eventually we should disallow this
# return type and force all ops
# to return the correct thing
#raise AssertionError(('%s returned None for' +\
# ' a gradient term, '
# 'this is prohibited') % node.op)
input_grads
[
i
]
=
node
.
inputs
[
i
]
.
zeros_like
()
if
warn_type
:
g_r_type
=
term_dict
[
node
][
i
]
.
type
r_type
=
inputs
[
i
]
.
type
if
g_r_type
!=
r_type
:
_logger
.
warning
(
'
%
s.grad returned a different type (
%
s) '
'for input
%
i of type (
%
s)'
,
node
.
op
,
g_r_type
,
i
,
r_type
)
# We don't know what None means. in the past it has been
# used to mean undefined, zero, or disconnected.
# We therefore don't allow it because its usage has become
# so muddied.
raise
TypeError
((
'
%
s returned None for'
+
\
' a gradient term, '
'this is prohibited'
)
%
node
.
op
)
#cache the result
term_dict
[
node
]
=
input_grads
...
...
@@ -845,7 +829,7 @@ def _populate_grad_dict(var_to_node_to_idx,
return
rval
def
grad_sources_inputs
(
sources
,
graph_inputs
,
warn_type
=
True
):
def
grad_sources_inputs
(
sources
,
graph_inputs
):
"""
Used to compute the gradient of a cost with respect to all the
variables between graph_input and cost, but in the special
...
...
@@ -889,10 +873,6 @@ def grad_sources_inputs(sources, graph_inputs, warn_type=True):
:type graph_inputs: list of Variable
:param graph_inputs: variables considered to be constant
(do not backpropagate through them)
:type warn_type: bool
:param warn_type: True will trigger warnings via the logging module when
the gradient on an expression has a different type than the original
expression
:rtype: dictionary whose keys and values are of type Variable
:return: mapping from each Variable encountered in the backward
...
...
@@ -934,7 +914,7 @@ def grad_sources_inputs(sources, graph_inputs, warn_type=True):
grad_dict
[
elem
]
=
DisconnectedType
()()
_populate_grad_dict
(
var_to_node_to_idx
,
grad_dict
,
wrt
,
warn_type
)
grad_dict
,
wrt
)
# post-process out the DisconnectedTypes
for
key
in
grad_dict
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论