Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e648ddeb
提交
e648ddeb
authored
7月 31, 2017
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update tests for GpuAdvancedSubtensor and disable optimizations
because of a slow down that is too big
上级
f62366bc
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
28 行增加
和
31 行删除
+28
-31
opt.py
theano/gpuarray/opt.py
+5
-3
subtensor.py
theano/gpuarray/subtensor.py
+9
-16
test_subtensor.py
theano/gpuarray/tests/test_subtensor.py
+6
-6
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+8
-6
没有找到文件。
theano/gpuarray/opt.py
浏览文件 @
e648ddeb
...
@@ -1095,9 +1095,11 @@ def local_gpua_advanced_incsubtensor1(op, context_name, inputs, outputs):
...
@@ -1095,9 +1095,11 @@ def local_gpua_advanced_incsubtensor1(op, context_name, inputs, outputs):
set_instead_of_inc
=
set_instead_of_inc
)
set_instead_of_inc
=
set_instead_of_inc
)
@register_opt
(
'fast_compile'
)
# Do not register this optimization for now, as it slows down the
@op_lifter
([
tensor
.
AdvancedIncSubtensor
])
# execution by a lot in important cases.
@register_opt2
([
tensor
.
AdvancedIncSubtensor
],
'fast_compile'
)
# @register_opt('fast_compile')
# @op_lifter([tensor.AdvancedIncSubtensor])
# @register_opt2([tensor.AdvancedIncSubtensor], 'fast_compile')
def
local_gpua_advanced_incsubtensor
(
op
,
context_name
,
inputs
,
outputs
):
def
local_gpua_advanced_incsubtensor
(
op
,
context_name
,
inputs
,
outputs
):
if
not
op
.
set_instead_of_inc
:
if
not
op
.
set_instead_of_inc
:
return
GpuAdvancedIncSubtensor
()
return
GpuAdvancedIncSubtensor
()
...
...
theano/gpuarray/subtensor.py
浏览文件 @
e648ddeb
...
@@ -621,6 +621,10 @@ class GpuAdvancedIncSubtensor(HideC, tensor.AdvancedIncSubtensor):
...
@@ -621,6 +621,10 @@ class GpuAdvancedIncSubtensor(HideC, tensor.AdvancedIncSubtensor):
y
=
inp
[
1
]
y
=
inp
[
1
]
idx
=
inp
[
2
:]
idx
=
inp
[
2
:]
x
=
x
.
copy
()
x
=
x
.
copy
()
# Get a handle to the GpuElemwise object that will be called.
# It is not necessary to have the right number of dimensions,
# so we just pass symbolic x and y.
iadd
=
get_iadd
(
node
.
inputs
[
0
],
node
.
inputs
[
1
])
# convert all indices to np.array
# convert all indices to np.array
for
i
in
range
(
len
(
idx
)):
for
i
in
range
(
len
(
idx
)):
...
@@ -699,15 +703,10 @@ class GpuAdvancedIncSubtensor(HideC, tensor.AdvancedIncSubtensor):
...
@@ -699,15 +703,10 @@ class GpuAdvancedIncSubtensor(HideC, tensor.AdvancedIncSubtensor):
else
:
else
:
val
=
y_flat
[
j
]
val
=
y_flat
[
j
]
tmp
=
pygpu
.
elemwise
.
elemwise2
(
iadd
(
x_flat
[
i
],
val
,
broadcast
=
True
)
x_flat
[
i
],
'+'
,
val
,
x_flat
[
i
],
broadcast
=
True
,
convert_f16
=
True
)
x_flat
.
__setitem__
(
i
,
tmp
)
else
:
else
:
k
=
get_iadd
(
node
.
inputs
[
0
],
node
.
inputs
[
1
])
if
(
x_flat
.
shape
[
-
len
(
y_flat
.
shape
):]
==
y_flat
.
shape
or
if
x_flat
.
shape
[
-
len
(
y_flat
.
shape
):]
==
y_flat
.
shape
or
y_flat
.
shape
==
(
):
y_flat
.
shape
==
()
):
# y_flat has to be broadcast over axes of x_flat[i]
# y_flat has to be broadcast over axes of x_flat[i]
for
i
in
take_idx
.
flatten
():
for
i
in
take_idx
.
flatten
():
...
@@ -715,13 +714,7 @@ class GpuAdvancedIncSubtensor(HideC, tensor.AdvancedIncSubtensor):
...
@@ -715,13 +714,7 @@ class GpuAdvancedIncSubtensor(HideC, tensor.AdvancedIncSubtensor):
x_flat_sub
=
x_flat
[
i
]
.
__getitem__
(
index
)
x_flat_sub
=
x_flat
[
i
]
.
__getitem__
(
index
)
else
:
else
:
x_flat_sub
=
x_flat
[
i
]
x_flat_sub
=
x_flat
[
i
]
tmp
=
pygpu
.
elemwise
.
elemwise2
(
iadd
(
x_flat_sub
,
y_flat
,
broadcast
=
True
)
x_flat_sub
,
'+'
,
y_flat
,
x_flat_sub
,
broadcast
=
True
,
convert_f16
=
True
)
x_flat
[
i
]
.
__setitem__
(
index
,
tmp
)
else
:
else
:
# y_flat's first axis corresponds to first exist of x_flat
# y_flat's first axis corresponds to first exist of x_flat
for
j
,
i
in
enumerate
(
take_idx
.
flatten
()):
for
j
,
i
in
enumerate
(
take_idx
.
flatten
()):
...
@@ -729,7 +722,7 @@ class GpuAdvancedIncSubtensor(HideC, tensor.AdvancedIncSubtensor):
...
@@ -729,7 +722,7 @@ class GpuAdvancedIncSubtensor(HideC, tensor.AdvancedIncSubtensor):
x_flat_sub
=
x_flat
[
i
]
.
__getitem__
(
index
)
x_flat_sub
=
x_flat
[
i
]
.
__getitem__
(
index
)
else
:
else
:
x_flat_sub
=
x_flat
[
i
]
x_flat_sub
=
x_flat
[
i
]
k
(
x_flat_sub
,
y_flat
[
j
%
y_flat
.
shape
[
0
]],
broadcast
=
True
)
iadd
(
x_flat_sub
,
y_flat
[
j
%
y_flat
.
shape
[
0
]],
broadcast
=
True
)
x_
=
x_flat
.
reshape
(
x_
.
shape
)
.
transpose
(
*
rtransp
)
x_
=
x_flat
.
reshape
(
x_
.
shape
)
.
transpose
(
*
rtransp
)
out
[
0
]
=
x_
out
[
0
]
=
x_
...
...
theano/gpuarray/tests/test_subtensor.py
浏览文件 @
e648ddeb
...
@@ -328,8 +328,8 @@ class test_gpuallocdiag(unittest.TestCase):
...
@@ -328,8 +328,8 @@ class test_gpuallocdiag(unittest.TestCase):
grad_x
=
tensor
.
grad
(
sum_mtx_x
,
x
)
grad_x
=
tensor
.
grad
(
sum_mtx_x
,
x
)
grad_mtx_x
=
tensor
.
grad
(
sum_mtx_x
,
mtx_x
)
grad_mtx_x
=
tensor
.
grad
(
sum_mtx_x
,
mtx_x
)
fn_grad_x
=
theano
.
function
([
x
],
grad_x
)
fn_grad_x
=
theano
.
function
([
x
],
grad_x
,
mode
=
mode_with_gpu
)
fn_grad_mtx_x
=
theano
.
function
([
x
],
grad_mtx_x
)
fn_grad_mtx_x
=
theano
.
function
([
x
],
grad_mtx_x
,
mode
=
mode_with_gpu
)
computed_grad_x
=
fn_grad_x
(
np_x
)
computed_grad_x
=
fn_grad_x
(
np_x
)
computed_grad_mtx_x
=
fn_grad_mtx_x
(
np_x
)
computed_grad_mtx_x
=
fn_grad_mtx_x
(
np_x
)
...
@@ -342,8 +342,8 @@ class test_gpuallocdiag(unittest.TestCase):
...
@@ -342,8 +342,8 @@ class test_gpuallocdiag(unittest.TestCase):
grad_x
=
tensor
.
grad
(
sum_mtx_x
,
x
)
grad_x
=
tensor
.
grad
(
sum_mtx_x
,
x
)
grad_mtx_x
=
tensor
.
grad
(
sum_mtx_x
,
mtx_x
)
grad_mtx_x
=
tensor
.
grad
(
sum_mtx_x
,
mtx_x
)
fn_grad_x
=
theano
.
function
([
x
],
grad_x
)
fn_grad_x
=
theano
.
function
([
x
],
grad_x
,
mode
=
mode_with_gpu
)
fn_grad_mtx_x
=
theano
.
function
([
x
],
grad_mtx_x
)
fn_grad_mtx_x
=
theano
.
function
([
x
],
grad_mtx_x
,
mode
=
mode_with_gpu
)
computed_grad_x
=
fn_grad_x
(
np_x
)
computed_grad_x
=
fn_grad_x
(
np_x
)
computed_grad_mtx_x
=
fn_grad_mtx_x
(
np_x
)
computed_grad_mtx_x
=
fn_grad_mtx_x
(
np_x
)
...
@@ -356,8 +356,8 @@ class test_gpuallocdiag(unittest.TestCase):
...
@@ -356,8 +356,8 @@ class test_gpuallocdiag(unittest.TestCase):
grad_x
=
tensor
.
grad
(
sum_mtx_x
,
x
)
grad_x
=
tensor
.
grad
(
sum_mtx_x
,
x
)
grad_mtx_x
=
tensor
.
grad
(
sum_mtx_x
,
mtx_x
)
grad_mtx_x
=
tensor
.
grad
(
sum_mtx_x
,
mtx_x
)
fn_grad_x
=
theano
.
function
([
x
],
grad_x
)
fn_grad_x
=
theano
.
function
([
x
],
grad_x
,
mode
=
mode_with_gpu
)
fn_grad_mtx_x
=
theano
.
function
([
x
],
grad_mtx_x
)
fn_grad_mtx_x
=
theano
.
function
([
x
],
grad_mtx_x
,
mode
=
mode_with_gpu
)
computed_grad_x
=
fn_grad_x
(
np_x
)
computed_grad_x
=
fn_grad_x
(
np_x
)
computed_grad_mtx_x
=
fn_grad_mtx_x
(
np_x
)
computed_grad_mtx_x
=
fn_grad_mtx_x
(
np_x
)
...
...
theano/tensor/tests/test_subtensor.py
浏览文件 @
e648ddeb
...
@@ -402,7 +402,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -402,7 +402,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
s1
=
s
[
newaxis
]
s1
=
s
[
newaxis
]
assert
s1
.
broadcastable
==
(
True
,),
s1
assert
s1
.
broadcastable
==
(
True
,),
s1
vs1
,
vn3
,
vn4
=
theano
.
function
([
s
],
[
s1
,
n3
,
n4
])(
-
2.0
)
vs1
,
vn3
,
vn4
=
theano
.
function
([
s
],
[
s1
,
n3
,
n4
]
,
mode
=
self
.
mode
)(
-
2.0
)
assert
np
.
all
(
vs1
==
[
-
2.0
])
assert
np
.
all
(
vs1
==
[
-
2.0
])
assert
np
.
all
(
vn3
==
assert
np
.
all
(
vn3
==
...
@@ -1148,7 +1148,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -1148,7 +1148,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
m1
=
set_subtensor
(
m
[:,
i
],
0
)
m1
=
set_subtensor
(
m
[:,
i
],
0
)
m2
=
inc_subtensor
(
m
[:,
i
],
1
)
m2
=
inc_subtensor
(
m
[:,
i
],
1
)
f
=
theano
.
function
([
m
,
i
],
[
m1
,
m2
])
f
=
theano
.
function
([
m
,
i
],
[
m1
,
m2
]
,
mode
=
self
.
mode
)
m_val
=
rand
(
3
,
5
)
m_val
=
rand
(
3
,
5
)
i_val
=
randint_ranged
(
min
=
0
,
max
=
4
,
shape
=
(
4
,))
i_val
=
randint_ranged
(
min
=
0
,
max
=
4
,
shape
=
(
4
,))
...
@@ -1173,7 +1173,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -1173,7 +1173,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
m1
=
set_subtensor
(
m
[:,
i
],
0
)
m1
=
set_subtensor
(
m
[:,
i
],
0
)
m2
=
inc_subtensor
(
m
[:,
i
],
1
)
m2
=
inc_subtensor
(
m
[:,
i
],
1
)
f
=
theano
.
function
([
m
,
i
],
[
m1
,
m2
])
f
=
theano
.
function
([
m
,
i
],
[
m1
,
m2
]
,
mode
=
self
.
mode
)
m_val
=
rand
(
5
,
7
)
m_val
=
rand
(
5
,
7
)
i_val
=
randint_ranged
(
min
=
0
,
max
=
6
,
shape
=
(
4
,
2
))
i_val
=
randint_ranged
(
min
=
0
,
max
=
6
,
shape
=
(
4
,
2
))
...
@@ -1208,7 +1208,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -1208,7 +1208,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
sub_m
=
m
[:,
i
]
sub_m
=
m
[:,
i
]
m1
=
set_subtensor
(
sub_m
,
np
.
zeros
(
shp_v
))
m1
=
set_subtensor
(
sub_m
,
np
.
zeros
(
shp_v
))
m2
=
inc_subtensor
(
sub_m
,
np
.
ones
(
shp_v
))
m2
=
inc_subtensor
(
sub_m
,
np
.
ones
(
shp_v
))
f
=
theano
.
function
([
m
,
i
],
[
m1
,
m2
])
f
=
theano
.
function
([
m
,
i
],
[
m1
,
m2
]
,
mode
=
self
.
mode
)
m_val
=
rand
(
3
,
5
)
m_val
=
rand
(
3
,
5
)
i_val
=
randint_ranged
(
min
=
0
,
max
=
4
,
shape
=
shp_i
)
i_val
=
randint_ranged
(
min
=
0
,
max
=
4
,
shape
=
shp_i
)
...
@@ -1245,7 +1245,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -1245,7 +1245,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
sub_m
=
m
[:,
i
]
sub_m
=
m
[:,
i
]
m1
=
set_subtensor
(
sub_m
,
np
.
zeros
(
shp_v
))
m1
=
set_subtensor
(
sub_m
,
np
.
zeros
(
shp_v
))
m2
=
inc_subtensor
(
sub_m
,
np
.
ones
(
shp_v
))
m2
=
inc_subtensor
(
sub_m
,
np
.
ones
(
shp_v
))
f
=
theano
.
function
([
m
,
i
],
[
m1
,
m2
])
f
=
theano
.
function
([
m
,
i
],
[
m1
,
m2
]
,
mode
=
self
.
mode
)
m_val
=
rand
(
3
,
5
)
m_val
=
rand
(
3
,
5
)
i_val
=
randint_ranged
(
min
=
0
,
max
=
4
,
shape
=
shp_i
)
i_val
=
randint_ranged
(
min
=
0
,
max
=
4
,
shape
=
shp_i
)
...
@@ -1267,7 +1267,9 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -1267,7 +1267,9 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
def
test_take
(
self
):
def
test_take
(
self
):
a
=
tensor
.
matrix
()
a
=
tensor
.
matrix
()
f
=
theano
.
function
([
a
],
a
.
take
(
0
,
axis
=-
1
),
allow_input_downcast
=
True
)
f
=
theano
.
function
(
[
a
],
a
.
take
(
0
,
axis
=-
1
),
allow_input_downcast
=
True
,
mode
=
self
.
mode
)
f
(
np
.
random
.
normal
(
0
,
1
,
(
30
,
4
)))
f
(
np
.
random
.
normal
(
0
,
1
,
(
30
,
4
)))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论