Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4552f381
提交
4552f381
authored
9月 22, 2017
作者:
Frédéric Bastien
提交者:
GitHub
9月 22, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6425 from nouiz/remove_node
Remove ViewOp subclass during optimization
上级
d43e189b
77fa4682
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
48 行增加
和
21 行删除
+48
-21
opt.py
theano/gof/opt.py
+6
-3
test_type.py
theano/gpuarray/tests/test_type.py
+2
-1
opt.py
theano/tensor/opt.py
+6
-17
test_gradient.py
theano/tests/test_gradient.py
+34
-0
没有找到文件。
theano/gof/opt.py
浏览文件 @
4552f381
...
...
@@ -1333,9 +1333,12 @@ class LocalOptGroup(LocalOptimizer):
self
.
process_count
.
setdefault
(
o
,
0
)
self
.
applied_true
.
setdefault
(
o
,
0
)
self
.
node_created
.
setdefault
(
o
,
0
)
for
c
in
o
.
tracks
():
self
.
track_map
[
c
]
.
append
(
o
)
tracks
=
o
.
tracks
()
if
tracks
is
None
:
self
.
track_map
[
None
]
.
append
(
o
)
else
:
for
c
in
tracks
:
self
.
track_map
[
c
]
.
append
(
o
)
def
__str__
(
self
):
return
getattr
(
self
,
'__name__'
,
...
...
theano/gpuarray/tests/test_type.py
浏览文件 @
4552f381
...
...
@@ -39,7 +39,8 @@ def test_view():
a
=
rand_gpuarray
(
20
,
dtype
=
dtype
)
g
=
GpuArrayType
(
dtype
=
dtype
,
broadcastable
=
(
False
,))(
'g'
)
f
=
theano
.
function
([
g
],
ViewOp
()(
g
))
m
=
theano
.
compile
.
get_default_mode
()
.
excluding
(
"local_view_op"
)
f
=
theano
.
function
([
g
],
ViewOp
()(
g
),
mode
=
m
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
,
ViewOp
)
...
...
theano/tensor/opt.py
浏览文件 @
4552f381
...
...
@@ -7488,25 +7488,14 @@ def local_useless_composite(node):
# # Remove consider_constant #
# ############################
# Although the ops ConsiderConstant, ZeroGrad and DisconnectedGrad
# just returns the input, it should be removed from the graph to
# make sure all possible optimizations can be applied.
register_canonicalize
(
gof
.
OpRemove
(
theano
.
gradient
.
consider_constant_
),
'fast_compile'
,
'fast_run'
,
name
=
'remove_consider_constant'
)
register_canonicalize
(
gof
.
OpRemove
(
theano
.
gradient
.
zero_grad_
),
'fast_compile'
,
'fast_run'
,
name
=
'remove_zero_grad'
)
register_canonicalize
(
gof
.
OpRemove
(
theano
.
gradient
.
disconnected_grad_
),
'fast_compile'
,
'fast_run'
,
name
=
'remove_disconnected_grad'
)
@register_canonicalize
@gof.local_optimizer
([
theano
.
gradient
.
GradClip
])
def
local_grad_clip
(
node
):
if
isinstance
(
node
.
op
,
theano
.
gradient
.
GradClip
):
@register_canonicalize
(
'fast_compile'
)
@register_useless
(
'fast_compile'
)
@gof.local_optimizer
(
None
)
def
local_view_op
(
node
):
if
isinstance
(
node
.
op
,
theano
.
compile
.
ops
.
ViewOp
):
return
node
.
inputs
...
...
theano/tests/test_gradient.py
浏览文件 @
4552f381
...
...
@@ -16,6 +16,7 @@ from theano.tests import unittest_tools as utt
from
theano
import
gradient
from
theano
import
config
from
theano.gof.null_type
import
NullType
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
as
RandomStreams
one
=
theano
.
tensor
.
as_tensor_variable
(
1.
)
...
...
@@ -784,5 +785,38 @@ def test_grad_clip():
assert
np
.
allclose
(
out
,
(
1
,
4
))
assert
not
np
.
allclose
(
out
[
0
],
out
[
1
])
def
test_grad_scale
():
x
=
theano
.
tensor
.
scalar
()
z
=
theano
.
tensor
.
grad
(
gradient
.
grad_scale
(
x
,
2
)
**
2
,
x
)
z2
=
theano
.
tensor
.
grad
(
x
**
2
,
x
)
f
=
theano
.
function
([
x
],
outputs
=
[
z
,
z2
])
if
theano
.
config
.
mode
!=
"FAST_COMPILE"
:
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
not
any
([
isinstance
(
node
.
op
,
gradient
.
GradScale
)
for
node
in
topo
])
out
=
f
(
2.
)
assert
np
.
allclose
(
out
,
(
8
,
4
))
def
test_undefined_grad_opt
():
# Make sure that undefined grad get removed in optimized graph.
random
=
RandomStreams
(
np
.
random
.
randint
(
1
,
2147462579
))
pvals
=
theano
.
shared
(
np
.
random
.
rand
(
10
,
20
)
.
astype
(
theano
.
config
.
floatX
))
pvals
=
pvals
/
pvals
.
sum
(
axis
=
1
)
pvals
=
gradient
.
zero_grad
(
pvals
)
samples
=
random
.
multinomial
(
pvals
=
pvals
,
n
=
1
)
samples
=
theano
.
tensor
.
cast
(
samples
,
pvals
.
dtype
)
samples
=
gradient
.
zero_grad
(
samples
)
cost
=
theano
.
tensor
.
sum
(
samples
+
pvals
)
grad
=
theano
.
tensor
.
grad
(
cost
,
samples
)
f
=
theano
.
function
([],
grad
)
theano
.
printing
.
debugprint
(
f
)
assert
not
any
([
isinstance
(
node
.
op
,
gradient
.
UndefinedGrad
)
for
node
in
f
.
maker
.
fgraph
.
apply_nodes
])
if
__name__
==
'__main__'
:
unittest
.
main
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论