Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f018f34a
提交
f018f34a
authored
9月 09, 2014
作者:
Dustin Webb
提交者:
Frederic
9月 11, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reworked opt.register_specialize to match the way opt.register_canonicalize works.
上级
f34caad6
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
12 行删除
+13
-12
nnet.py
theano/tensor/nnet/nnet.py
+8
-12
opt.py
theano/tensor/opt.py
+5
-0
没有找到文件。
theano/tensor/nnet/nnet.py
浏览文件 @
f018f34a
...
@@ -577,6 +577,7 @@ class Softmax(gof.Op):
...
@@ -577,6 +577,7 @@ class Softmax(gof.Op):
softmax
=
Softmax
()
softmax
=
Softmax
()
@opt.register_specialize
(
'gpu'
)
@gof.local_optimizer
([
softmax
])
@gof.local_optimizer
([
softmax
])
def
local_softmax_with_bias
(
node
):
def
local_softmax_with_bias
(
node
):
"""Try to turn softmax(sum_of_stuff) -> softmax_w_bias(matrix, bias)
"""Try to turn softmax(sum_of_stuff) -> softmax_w_bias(matrix, bias)
...
@@ -635,7 +636,6 @@ def local_softmax_with_bias(node):
...
@@ -635,7 +636,6 @@ def local_softmax_with_bias(node):
#This condition is not always true. See the test
#This condition is not always true. See the test
#nnet/tests/test_nnet.py:T_SoftmaxWithBias.test_broadcast
#nnet/tests/test_nnet.py:T_SoftmaxWithBias.test_broadcast
return
[
sm_bias
]
return
[
sm_bias
]
opt
.
register_specialize
(
local_softmax_with_bias
,
'gpu'
)
def
softmax_simplifier
(
numerators
,
denominators
):
def
softmax_simplifier
(
numerators
,
denominators
):
...
@@ -1330,6 +1330,7 @@ class CrossentropyCategorical1Hot(gof.Op):
...
@@ -1330,6 +1330,7 @@ class CrossentropyCategorical1Hot(gof.Op):
crossentropy_categorical_1hot
=
CrossentropyCategorical1Hot
()
crossentropy_categorical_1hot
=
CrossentropyCategorical1Hot
()
@opt.register_specialize
(
'gpu'
)
@gof.optimizer
@gof.optimizer
def
crossentropy_to_crossentropy_with_softmax_with_bias
(
fgraph
):
def
crossentropy_to_crossentropy_with_softmax_with_bias
(
fgraph
):
"""This is a stabilization optimization
"""This is a stabilization optimization
...
@@ -1359,8 +1360,6 @@ def crossentropy_to_crossentropy_with_softmax_with_bias(fgraph):
...
@@ -1359,8 +1360,6 @@ def crossentropy_to_crossentropy_with_softmax_with_bias(fgraph):
return
return
opt
.
register_stabilize
(
crossentropy_to_crossentropy_with_softmax_with_bias
,
opt
.
register_stabilize
(
crossentropy_to_crossentropy_with_softmax_with_bias
,
'gpu'
)
'gpu'
)
opt
.
register_specialize
(
crossentropy_to_crossentropy_with_softmax_with_bias
,
'gpu'
)
@gof.optimizer
@gof.optimizer
...
@@ -1409,6 +1408,7 @@ optdb.register('crossentropy_to_crossentropy_with_softmax',
...
@@ -1409,6 +1408,7 @@ optdb.register('crossentropy_to_crossentropy_with_softmax',
'fast_run'
,
'xent'
,
'gpu'
)
'fast_run'
,
'xent'
,
'gpu'
)
@opt.register_specialize
(
'gpu'
)
@gof.local_optimizer
([
softmax_grad
])
@gof.local_optimizer
([
softmax_grad
])
def
local_crossentropy_to_crossentropy_with_softmax_grad
(
node
):
def
local_crossentropy_to_crossentropy_with_softmax_grad
(
node
):
if
node
.
op
==
softmax_grad
:
if
node
.
op
==
softmax_grad
:
...
@@ -1419,10 +1419,9 @@ def local_crossentropy_to_crossentropy_with_softmax_grad(node):
...
@@ -1419,10 +1419,9 @@ def local_crossentropy_to_crossentropy_with_softmax_grad(node):
dx
=
crossentropy_softmax_1hot_with_bias_dx
(
g_nll
,
dx
=
crossentropy_softmax_1hot_with_bias_dx
(
g_nll
,
coding_dist
,
true_one_of_n
)
coding_dist
,
true_one_of_n
)
return
[
dx
]
return
[
dx
]
opt
.
register_specialize
(
local_crossentropy_to_crossentropy_with_softmax_grad
,
'gpu'
)
@opt.register_specialize
(
'gpu'
)
@gof.local_optimizer
([
tensor
.
_max_and_argmax
])
@gof.local_optimizer
([
tensor
.
_max_and_argmax
])
def
local_argmax_pushdown
(
node
):
def
local_argmax_pushdown
(
node
):
if
node
.
op
==
tensor
.
_max_and_argmax
and
node
.
inputs
[
0
]
.
owner
and
\
if
node
.
op
==
tensor
.
_max_and_argmax
and
node
.
inputs
[
0
]
.
owner
and
\
...
@@ -1453,7 +1452,6 @@ def local_argmax_pushdown(node):
...
@@ -1453,7 +1452,6 @@ def local_argmax_pushdown(node):
tensor
.
DimShuffle
(
tensor
.
DimShuffle
(
pre_bias
.
broadcastable
,
pre_bias
.
broadcastable
,
(
'x'
,
0
))(
pre_bias
),
axis
)
(
'x'
,
0
))(
pre_bias
),
axis
)
opt
.
register_specialize
(
local_argmax_pushdown
,
'gpu'
)
# Utility function used by the two next optimizations
# Utility function used by the two next optimizations
...
@@ -1509,6 +1507,7 @@ def _is_const(z, val, approx=False):
...
@@ -1509,6 +1507,7 @@ def _is_const(z, val, approx=False):
return
numpy
.
all
(
maybe
==
val
)
return
numpy
.
all
(
maybe
==
val
)
@opt.register_specialize
(
'gpu'
)
@gof.local_optimizer
([
subtensor
.
AdvancedSubtensor
,
tensor
.
log
])
@gof.local_optimizer
([
subtensor
.
AdvancedSubtensor
,
tensor
.
log
])
def
local_advanced_indexing_crossentropy_onehot
(
node
):
def
local_advanced_indexing_crossentropy_onehot
(
node
):
log
=
None
log
=
None
...
@@ -1547,9 +1546,9 @@ def local_advanced_indexing_crossentropy_onehot(node):
...
@@ -1547,9 +1546,9 @@ def local_advanced_indexing_crossentropy_onehot(node):
return
[
-
crossentropy_softmax_argmax_1hot_with_bias
(
x_var
,
return
[
-
crossentropy_softmax_argmax_1hot_with_bias
(
x_var
,
b_var
,
b_var
,
labels
)[
0
]]
labels
)[
0
]]
opt
.
register_specialize
(
local_advanced_indexing_crossentropy_onehot
,
'gpu'
)
@opt.register_specialize
(
'gpu'
)
@gof.local_optimizer
([
softmax_grad
])
@gof.local_optimizer
([
softmax_grad
])
def
local_advanced_indexing_crossentropy_onehot_grad
(
node
):
def
local_advanced_indexing_crossentropy_onehot_grad
(
node
):
if
not
(
node
.
op
==
softmax_grad
):
if
not
(
node
.
op
==
softmax_grad
):
...
@@ -1769,11 +1768,10 @@ def local_advanced_indexing_crossentropy_onehot_grad(node):
...
@@ -1769,11 +1768,10 @@ def local_advanced_indexing_crossentropy_onehot_grad(node):
if
labels
.
ndim
==
1
and
x_var
.
ndim
==
2
:
if
labels
.
ndim
==
1
and
x_var
.
ndim
==
2
:
return
[
crossentropy_softmax_1hot_with_bias_dx
(
out_grad
,
sm
,
labels
)]
return
[
crossentropy_softmax_1hot_with_bias_dx
(
out_grad
,
sm
,
labels
)]
else
:
else
:
return
retur
opt
.
register_specialize
(
local_advanced_indexing_crossentropy_onehot_grad
,
'gpu'
)
@opt.register_specialize
(
'gpu'
)
@gof.local_optimizer
([
softmax_with_bias
])
@gof.local_optimizer
([
softmax_with_bias
])
def
graph_merge_softmax_with_crossentropy_softmax
(
node
):
def
graph_merge_softmax_with_crossentropy_softmax
(
node
):
if
node
.
op
==
softmax_with_bias
:
if
node
.
op
==
softmax_with_bias
:
...
@@ -1785,8 +1783,6 @@ def graph_merge_softmax_with_crossentropy_softmax(node):
...
@@ -1785,8 +1783,6 @@ def graph_merge_softmax_with_crossentropy_softmax(node):
xx
,
bb
,
ll
=
big_client
.
inputs
xx
,
bb
,
ll
=
big_client
.
inputs
mergeable_client
=
big_client
.
op
(
x
,
b
,
ll
)
mergeable_client
=
big_client
.
op
(
x
,
b
,
ll
)
return
[
mergeable_client
[
1
]]
return
[
mergeable_client
[
1
]]
opt
.
register_specialize
(
graph_merge_softmax_with_crossentropy_softmax
,
'gpu'
)
def
binary_crossentropy
(
output
,
target
):
def
binary_crossentropy
(
output
,
target
):
...
...
theano/tensor/opt.py
浏览文件 @
f018f34a
...
@@ -327,6 +327,11 @@ def register_stabilize(lopt, *tags, **kwargs):
...
@@ -327,6 +327,11 @@ def register_stabilize(lopt, *tags, **kwargs):
def
register_specialize
(
lopt
,
*
tags
,
**
kwargs
):
def
register_specialize
(
lopt
,
*
tags
,
**
kwargs
):
if
type
(
lopt
)
==
str
:
def
register
(
inner_lopt
):
return
register_specialize
(
inner_lopt
,
*
tags
,
**
kwargs
)
return
register
else
:
name
=
(
kwargs
and
kwargs
.
pop
(
'name'
))
or
lopt
.
__name__
name
=
(
kwargs
and
kwargs
.
pop
(
'name'
))
or
lopt
.
__name__
compile
.
optdb
[
'specialize'
]
.
register
(
name
,
lopt
,
'fast_run'
,
*
tags
)
compile
.
optdb
[
'specialize'
]
.
register
(
name
,
lopt
,
'fast_run'
,
*
tags
)
return
lopt
return
lopt
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论