Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8a8fe4a1
提交
8a8fe4a1
authored
4月 14, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests.
上级
983ed2a2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
71 行增加
和
0 行删除
+71
-0
test_blocksparse.py
theano/sandbox/gpuarray/tests/test_blocksparse.py
+71
-0
没有找到文件。
theano/sandbox/gpuarray/tests/test_blocksparse.py
0 → 100644
浏览文件 @
8a8fe4a1
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
theano
from
theano
import
tensor
import
theano.tests.unittest_tools
as
utt
from
theano.tensor.nnet.tests
import
test_blocksparse
from
.config
import
mode_with_gpu
,
test_ctx_name
from
..type
import
gpuarray_shared_constructor
from
..blocksparse
import
(
GpuSparseBlockGemv
,
GpuSparseBlockOuter
,
gpu_sparse_block_gemv
,
gpu_sparse_block_outer
)
class
BlockSparse_Gemv_and_Outer
(
test_blocksparse
.
BlockSparse_Gemv_and_Outer
):
def
setUp
(
self
):
utt
.
seed_rng
()
self
.
mode
=
mode_with_gpu
.
excluding
(
'constant_folding'
)
self
.
gemv_op
=
gpu_sparse_block_gemv
self
.
outer_op
=
gpu_sparse_block_outer
self
.
gemv_class
=
GpuSparseBlockGemv
self
.
outer_class
=
GpuSparseBlockOuter
# This test is temporarily disabled since we disabled the output_merge
# and alpha_merge optimizations for blocksparse due to brokeness.
# Re-enable when those are re-added.
def
Xtest_blocksparse_grad_merge
(
self
):
b
=
tensor
.
fmatrix
()
h
=
tensor
.
ftensor3
()
iIdx
=
tensor
.
lmatrix
()
oIdx
=
tensor
.
lmatrix
()
W_val
,
h_val
,
iIdx_val
,
b_val
,
oIdx_val
=
self
.
gemv_data
()
W
=
gpuarray_shared_constructor
(
W_val
,
context
=
test_ctx_name
)
o
=
gpu_sparse_block_gemv
(
b
.
take
(
oIdx
,
axis
=
0
),
W
,
h
,
iIdx
,
oIdx
)
gW
=
theano
.
grad
(
o
.
sum
(),
W
)
lr
=
numpy
.
asarray
(
0.05
,
dtype
=
'float32'
)
upd
=
W
-
lr
*
gW
f1
=
theano
.
function
([
h
,
iIdx
,
b
,
oIdx
],
updates
=
[(
W
,
upd
)],
mode
=
mode_with_gpu
)
# Make sure the lr update was merged.
assert
isinstance
(
f1
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
op
,
GpuSparseBlockOuter
)
# Exclude the merge optimizations.
mode
=
mode_with_gpu
.
excluding
(
'local_merge_blocksparse_alpha'
)
mode
=
mode
.
excluding
(
'local_merge_blocksparse_output'
)
f2
=
theano
.
function
([
h
,
iIdx
,
b
,
oIdx
],
updates
=
[(
W
,
upd
)],
mode
=
mode
)
# Make sure the lr update is not merged.
assert
not
isinstance
(
f2
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
op
,
GpuSparseBlockOuter
)
f2
(
h_val
,
iIdx_val
,
b_val
,
oIdx_val
)
W_ref
=
W
.
get_value
()
# reset the var
W
.
set_value
(
W_val
)
f1
(
h_val
,
iIdx_val
,
b_val
,
oIdx_val
)
W_opt
=
W
.
get_value
()
utt
.
assert_allclose
(
W_ref
,
W_opt
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论