Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8b239b25
提交
8b239b25
authored
9月 18, 2015
作者:
Kelvin Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reflect various comments + pep8
上级
9ee7cb64
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
17 行增加
和
16 行删除
+17
-16
nnet.py
theano/tensor/nnet/nnet.py
+17
-16
没有找到文件。
theano/tensor/nnet/nnet.py
浏览文件 @
8b239b25
...
@@ -21,7 +21,6 @@ from theano import gof
...
@@ -21,7 +21,6 @@ from theano import gof
from
theano
import
scalar
from
theano
import
scalar
from
theano.tensor
import
basic
as
tensor
from
theano.tensor
import
basic
as
tensor
from
theano.tensor
import
subtensor
from
theano.tensor
import
subtensor
from
theano.tensor
import
elemwise
from
theano.tensor
import
opt
from
theano.tensor
import
opt
from
theano.tensor.opt
import
copy_stack_trace
from
theano.tensor.opt
import
copy_stack_trace
from
theano.compile
import
optdb
from
theano.compile
import
optdb
...
@@ -115,7 +114,8 @@ class SoftmaxWithBias(gof.Op):
...
@@ -115,7 +114,8 @@ class SoftmaxWithBias(gof.Op):
# TODO: set error messages for failures in this code
# TODO: set error messages for failures in this code
# TODO: use this to accept float32 and int32: node.inputs[0].type.dtype_specs()[1]
# TODO: use this to accept float32 and int32:
# node.inputs[0].type.dtype_specs()[1]
init_decl
=
"""
init_decl
=
"""
npy_intp* Nx = PyArray_DIMS(
%(x)
s);
npy_intp* Nx = PyArray_DIMS(
%(x)
s);
npy_intp Sx = 0;
npy_intp Sx = 0;
...
@@ -593,7 +593,7 @@ def softmax_graph(c):
...
@@ -593,7 +593,7 @@ def softmax_graph(c):
def
softmax
(
c
):
def
softmax
(
c
):
return
softmax_op
(
c
)
return
softmax_op
(
c
)
# seems like need to change softmax_with_bias
@opt.register_specialize
(
'fast_compile_gpu'
)
@opt.register_specialize
(
'fast_compile_gpu'
)
@gof.local_optimizer
([
softmax_op
])
@gof.local_optimizer
([
softmax_op
])
def
local_softmax_with_bias
(
node
):
def
local_softmax_with_bias
(
node
):
...
@@ -636,19 +636,19 @@ def local_softmax_with_bias(node):
...
@@ -636,19 +636,19 @@ def local_softmax_with_bias(node):
# we're in business...
# we're in business...
if
len
(
vectors
)
>
1
:
if
len
(
vectors
)
>
1
:
vector_sum
=
tensor
.
add
(
*
vectors
)
vector_sum
=
tensor
.
add
(
*
vectors
)
copy_stack_trace
(
x_in
,
vector_sum
)
else
:
else
:
vector_sum
=
vectors
[
0
]
vector_sum
=
vectors
[
0
]
copy_stack_trace
(
x_in
,
vector_sum
)
if
len
(
non_vectors
)
>
1
:
if
len
(
non_vectors
)
>
1
:
non_vector_sum
=
tensor
.
add
(
*
non_vectors
)
non_vector_sum
=
tensor
.
add
(
*
non_vectors
)
copy_stack_trace
(
x_in
,
non_vector_sum
)
else
:
else
:
non_vector_sum
=
non_vectors
[
0
]
non_vector_sum
=
non_vectors
[
0
]
copy_stack_trace
(
x_in
,
non_vector_sum
)
try
:
try
:
sm_bias
=
softmax_with_bias
(
non_vector_sum
,
vector_sum
)
sm_bias
=
softmax_with_bias
(
non_vector_sum
,
vector_sum
)
copy_stack_trace
(
x_in
,
non_vector_sum
)
copy_stack_trace
(
node
.
outputs
[
0
],
sm_bias
)
except
Exception
:
except
Exception
:
# if our arguments have the wrong types, then
# if our arguments have the wrong types, then
# forget about it
# forget about it
...
@@ -1384,7 +1384,7 @@ def local_argmax_pushdown(node):
...
@@ -1384,7 +1384,7 @@ def local_argmax_pushdown(node):
tensor
.
log
,
tensor
.
tanh
,
sigmoid
):
tensor
.
log
,
tensor
.
tanh
,
sigmoid
):
pre_x
,
=
x
.
owner
.
inputs
pre_x
,
=
x
.
owner
.
inputs
ret
=
tensor
.
_max_and_argmax
(
pre_x
,
axis
)
ret
=
tensor
.
_max_and_argmax
(
pre_x
,
axis
)
copy_stack_trace
(
pre_
x
,
ret
)
copy_stack_trace
(
x_ma
x
,
ret
)
return
ret
return
ret
if
x
.
owner
and
x
.
owner
.
op
==
softmax_with_bias
:
if
x
.
owner
and
x
.
owner
.
op
==
softmax_with_bias
:
pre_x
,
pre_bias
=
x
.
owner
.
inputs
pre_x
,
pre_bias
=
x
.
owner
.
inputs
...
@@ -1393,7 +1393,7 @@ def local_argmax_pushdown(node):
...
@@ -1393,7 +1393,7 @@ def local_argmax_pushdown(node):
pre_bias
.
broadcastable
,
pre_bias
.
broadcastable
,
(
'x'
,
0
))(
pre_bias
),
axis
)
(
'x'
,
0
))(
pre_bias
),
axis
)
# copy both stack traces
# copy both stack traces
copy_stack_trace
(
[
pre_x
,
pre_bias
],
ret
)
copy_stack_trace
(
x_max
,
ret
)
return
ret
return
ret
# Utility function used by the two next optimizations
# Utility function used by the two next optimizations
...
@@ -1488,10 +1488,11 @@ def local_advanced_indexing_crossentropy_onehot(node):
...
@@ -1488,10 +1488,11 @@ def local_advanced_indexing_crossentropy_onehot(node):
# Check that rows == arange(labels.shape[0])
# Check that rows == arange(labels.shape[0])
if
_check_rows_is_arange_len_labels
(
rows
,
labels
):
if
_check_rows_is_arange_len_labels
(
rows
,
labels
):
if
labels
.
ndim
==
1
and
x_var
.
ndim
==
2
:
if
labels
.
ndim
==
1
and
x_var
.
ndim
==
2
:
ret
=
-
crossentropy_softmax_argmax_1hot_with_bias
(
x_var
,
minus_ret
=
crossentropy_softmax_argmax_1hot_with_bias
(
x_var
,
b_var
,
b_var
,
labels
)[
0
]
labels
)[
0
]
copy_stack_trace
([
x_var
,
b_var
,
labels
],
ret
)
ret
=
-
minus_ret
copy_stack_trace
(
node
.
outputs
[
0
],
[
minus_ret
,
ret
])
return
[
ret
]
return
[
ret
]
...
@@ -1715,13 +1716,14 @@ def local_advanced_indexing_crossentropy_onehot_grad(node):
...
@@ -1715,13 +1716,14 @@ def local_advanced_indexing_crossentropy_onehot_grad(node):
# Dimension check before substitution
# Dimension check before substitution
if
labels
.
ndim
==
1
and
x_var
.
ndim
==
2
:
if
labels
.
ndim
==
1
and
x_var
.
ndim
==
2
:
ret
=
crossentropy_softmax_1hot_with_bias_dx
(
out_grad
,
sm
,
labels
)
ret
=
crossentropy_softmax_1hot_with_bias_dx
(
out_grad
,
sm
,
labels
)
# The stack trace
of output_grad, sm and labels are not added
# The stack trace
is not added to output_grad, sm and labels at
# but may need to be added at a future point
#
the moment
but may need to be added at a future point
copy_stack_trace
(
node
.
outputs
[
0
],
ret
)
copy_stack_trace
(
node
.
outputs
[
0
],
ret
)
return
[
ret
]
return
[
ret
]
else
:
else
:
return
return
@opt.register_specialize
(
'fast_compile_gpu'
)
@opt.register_specialize
(
'fast_compile_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
):
...
@@ -1733,7 +1735,7 @@ def graph_merge_softmax_with_crossentropy_softmax(node):
...
@@ -1733,7 +1735,7 @@ def graph_merge_softmax_with_crossentropy_softmax(node):
if
big_client
in
[
b_client
[
0
]
for
b_client
in
b
.
clients
]:
if
big_client
in
[
b_client
[
0
]
for
b_client
in
b
.
clients
]:
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
)
copy_stack_trace
(
node
.
ouputs
[
0
],
mergeable_client
[
1
])
copy_stack_trace
(
node
.
ou
t
puts
[
0
],
mergeable_client
[
1
])
return
[
mergeable_client
[
1
]]
return
[
mergeable_client
[
1
]]
...
@@ -1795,7 +1797,6 @@ def local_useless_crossentropy_softmax_1hot_with_bias_dx_alloc(node):
...
@@ -1795,7 +1797,6 @@ def local_useless_crossentropy_softmax_1hot_with_bias_dx_alloc(node):
dz
=
opt
.
Assert
(
msg
)(
dz
,
cond
)
dz
=
opt
.
Assert
(
msg
)(
dz
,
cond
)
ret
=
node
.
op
(
dz
,
sm
,
y_idx
)
ret
=
node
.
op
(
dz
,
sm
,
y_idx
)
# copy node.outputs[0] to ret according to Pascal
copy_stack_trace
(
node
.
outputs
[
0
],
ret
)
copy_stack_trace
(
node
.
outputs
[
0
],
ret
)
return
[
ret
]
return
[
ret
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论