Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5611cf71
提交
5611cf71
authored
6月 02, 2021
作者:
kc611
提交者:
Brandon T. Willard
6月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor tests.gpuarray to use NumPy Generator
上级
39c11472
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
76 行增加
和
125 行删除
+76
-125
check_dnn_conv.py
tests/gpuarray/check_dnn_conv.py
+0
-1
test_basic_ops.py
tests/gpuarray/test_basic_ops.py
+24
-27
test_blocksparse.py
tests/gpuarray/test_blocksparse.py
+0
-1
test_dnn.py
tests/gpuarray/test_dnn.py
+2
-27
test_linalg.py
tests/gpuarray/test_linalg.py
+19
-25
test_nnet.py
tests/gpuarray/test_nnet.py
+0
-6
test_opt.py
tests/gpuarray/test_opt.py
+13
-12
test_pool.py
tests/gpuarray/test_pool.py
+10
-10
test_rng_mrg.py
tests/gpuarray/test_rng_mrg.py
+0
-3
test_scan.py
tests/gpuarray/test_scan.py
+8
-13
没有找到文件。
tests/gpuarray/check_dnn_conv.py
浏览文件 @
5611cf71
...
...
@@ -612,7 +612,6 @@ class BaseTestDnnConv:
return
None
,
None
def
__init__
(
self
):
utt
.
seed_rng
(
1234
)
self
.
dtype_configs
=
cudnn
.
get_supported_dtype_configs
(
check_dtype_config_support
)
...
...
tests/gpuarray/test_basic_ops.py
浏览文件 @
5611cf71
...
...
@@ -35,14 +35,13 @@ from tests.tensor.test_basic import (
TestJoinAndSplit
,
TestReshape
,
)
from
tests.tensor.utils
import
rand
,
safe_make_node
from
tests.tensor.utils
import
rand
om
,
safe_make_node
pygpu
=
pytest
.
importorskip
(
"pygpu"
)
gpuarray
=
pygpu
.
gpuarray
utt
.
seed_rng
()
rng
=
np
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
def
inplace_func
(
...
...
@@ -79,7 +78,7 @@ def fake_shared(value, name=None, strict=False, allow_downcast=None, **kwargs):
def
rand_gpuarray
(
*
shape
,
**
kwargs
):
r
=
rng
.
rand
(
*
shape
)
*
2
-
1
r
=
rng
.
rand
om
(
shape
)
*
2
-
1
dtype
=
kwargs
.
pop
(
"dtype"
,
aesara
.
config
.
floatX
)
cls
=
kwargs
.
pop
(
"cls"
,
None
)
if
len
(
kwargs
)
!=
0
:
...
...
@@ -219,7 +218,7 @@ def test_transfer_cpu_gpu():
a
=
fmatrix
(
"a"
)
g
=
GpuArrayType
(
dtype
=
"float32"
,
broadcastable
=
(
False
,
False
))(
"g"
)
av
=
np
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
"float32"
)
av
=
np
.
asarray
(
rng
.
rand
om
((
5
,
4
)
),
dtype
=
"float32"
)
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
f
=
aesara
.
function
([
a
],
GpuFromHost
(
test_ctx_name
)(
a
))
...
...
@@ -236,7 +235,7 @@ def test_transfer_gpu_gpu():
dtype
=
"float32"
,
broadcastable
=
(
False
,
False
),
context_name
=
test_ctx_name
)()
av
=
np
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
"float32"
)
av
=
np
.
asarray
(
rng
.
rand
om
((
5
,
4
)
),
dtype
=
"float32"
)
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
mode
=
mode_with_gpu
.
excluding
(
"cut_gpua_host_transfers"
,
"local_cut_gpua_host_gpua"
...
...
@@ -256,7 +255,7 @@ def test_transfer_strided():
a
=
fmatrix
(
"a"
)
g
=
GpuArrayType
(
dtype
=
"float32"
,
broadcastable
=
(
False
,
False
))(
"g"
)
av
=
np
.
asarray
(
rng
.
rand
(
5
,
8
),
dtype
=
"float32"
)
av
=
np
.
asarray
(
rng
.
rand
om
((
5
,
8
)
),
dtype
=
"float32"
)
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
av
=
av
[:,
::
2
]
...
...
@@ -283,14 +282,14 @@ TestGpuAlloc = makeTester(
op
=
lambda
*
args
:
alloc
(
*
args
)
+
1
,
gpu_op
=
GpuAlloc
(
test_ctx_name
),
cases
=
dict
(
correct01
=
(
rand
(),
np
.
int32
(
7
)),
correct01
=
(
rand
om
(),
np
.
int32
(
7
)),
# just gives a DeepCopyOp with possibly wrong results on the CPU
# correct01_bcast=(rand(1), np.int32(7)),
correct02
=
(
rand
(),
np
.
int32
(
4
),
np
.
int32
(
7
)),
correct12
=
(
rand
(
7
),
np
.
int32
(
4
),
np
.
int32
(
7
)),
correct13
=
(
rand
(
7
),
np
.
int32
(
2
),
np
.
int32
(
4
),
np
.
int32
(
7
)),
correct23
=
(
rand
(
4
,
7
),
np
.
int32
(
2
),
np
.
int32
(
4
),
np
.
int32
(
7
)),
bad_shape12
=
(
rand
(
7
),
np
.
int32
(
7
),
np
.
int32
(
5
)),
# correct01_bcast=(rand
om
(1), np.int32(7)),
correct02
=
(
rand
om
(),
np
.
int32
(
4
),
np
.
int32
(
7
)),
correct12
=
(
rand
om
(
7
),
np
.
int32
(
4
),
np
.
int32
(
7
)),
correct13
=
(
rand
om
(
7
),
np
.
int32
(
2
),
np
.
int32
(
4
),
np
.
int32
(
7
)),
correct23
=
(
rand
om
(
4
,
7
),
np
.
int32
(
2
),
np
.
int32
(
4
),
np
.
int32
(
7
)),
bad_shape12
=
(
rand
om
(
7
),
np
.
int32
(
7
),
np
.
int32
(
5
)),
),
)
...
...
@@ -357,7 +356,7 @@ def test_shape():
def
test_gpu_contiguous
():
a
=
fmatrix
(
"a"
)
i
=
iscalar
(
"i"
)
a_val
=
np
.
asarray
(
np
.
random
.
rand
(
4
,
5
),
dtype
=
"float32"
)
a_val
=
np
.
asarray
(
np
.
random
.
rand
om
(
4
,
5
),
dtype
=
"float32"
)
# The reshape is needed otherwise we make the subtensor on the CPU
# to transfer less data.
f
=
aesara
.
function
(
...
...
@@ -390,7 +389,6 @@ class TestGPUReshape(TestReshape):
class
TestGPUComparison
(
TestComparison
):
def
setup_method
(
self
):
utt
.
seed_rng
()
self
.
mode
=
mode_with_gpu
self
.
shared
=
gpuarray_shared_constructor
self
.
dtypes
=
[
"float64"
,
"float32"
]
...
...
@@ -415,8 +413,8 @@ class TestGPUJoinAndSplit(TestJoinAndSplit):
def
test_gpusplit_opt
(
self
):
# Test that we move the node to the GPU
# Also test float16 computation at the same time.
rng
=
np
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
m
=
self
.
shared
(
rng
.
rand
(
4
,
6
)
.
astype
(
"float16"
))
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
m
=
self
.
shared
(
rng
.
rand
om
((
4
,
6
)
)
.
astype
(
"float16"
))
o
=
Split
(
2
)(
m
,
0
,
[
2
,
2
])
assert
o
[
0
]
.
dtype
==
"float16"
f
=
aesara
.
function
([],
o
,
mode
=
self
.
mode
)
...
...
@@ -433,9 +431,9 @@ class TestGPUJoinAndSplit(TestJoinAndSplit):
def
test_gpujoin_gpualloc
():
a
=
fmatrix
(
"a"
)
a_val
=
np
.
asarray
(
np
.
random
.
rand
(
4
,
5
),
dtype
=
"float32"
)
a_val
=
np
.
asarray
(
np
.
random
.
rand
om
(
4
,
5
),
dtype
=
"float32"
)
b
=
fmatrix
(
"b"
)
b_val
=
np
.
asarray
(
np
.
random
.
rand
(
3
,
5
),
dtype
=
"float32"
)
b_val
=
np
.
asarray
(
np
.
random
.
rand
om
(
3
,
5
),
dtype
=
"float32"
)
f
=
aesara
.
function
(
[
a
,
b
],
...
...
@@ -514,9 +512,9 @@ def test_hostfromgpu_shape_i():
)
a
=
fmatrix
(
"a"
)
ca
=
aesara
.
gpuarray
.
type
.
GpuArrayType
(
"float32"
,
(
False
,
False
))()
av
=
np
.
asarray
(
np
.
random
.
rand
(
5
,
4
),
dtype
=
"float32"
)
av
=
np
.
asarray
(
np
.
random
.
rand
om
(
5
,
4
),
dtype
=
"float32"
)
cv
=
gpuarray
.
asarray
(
np
.
random
.
rand
(
5
,
4
),
dtype
=
"float32"
,
context
=
get_context
(
test_ctx_name
)
np
.
random
.
rand
om
(
5
,
4
),
dtype
=
"float32"
,
context
=
get_context
(
test_ctx_name
)
)
f
=
aesara
.
function
([
a
],
GpuFromHost
(
test_ctx_name
)(
a
),
mode
=
m
)
...
...
@@ -583,12 +581,11 @@ def test_gpu_tril_triu():
assert
result
.
dtype
==
np
.
dtype
(
dtype
)
assert
any
([
isinstance
(
node
.
op
,
GpuTri
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
utt
.
seed_rng
()
test_rng
=
np
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
test_rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
for
dtype
in
[
"float64"
,
"float32"
,
"float16"
]:
# try a big one
m
=
np
.
asarray
(
test_rng
.
rand
(
5000
,
5000
)
*
2
-
1
,
dtype
=
dtype
)
m
=
np
.
asarray
(
test_rng
.
rand
om
((
5000
,
5000
)
)
*
2
-
1
,
dtype
=
dtype
)
check_l
(
m
,
0
)
check_l
(
m
,
1
)
check_l
(
m
,
-
1
)
...
...
@@ -597,7 +594,7 @@ def test_gpu_tril_triu():
check_u
(
m
,
1
)
check_u
(
m
,
-
1
)
m
=
np
.
asarray
(
test_rng
.
rand
(
10
,
10
)
*
2
-
1
,
dtype
=
dtype
)
m
=
np
.
asarray
(
test_rng
.
rand
om
((
10
,
10
)
)
*
2
-
1
,
dtype
=
dtype
)
check_l
(
m
,
0
)
check_l
(
m
,
1
)
check_l
(
m
,
-
1
)
...
...
@@ -606,7 +603,7 @@ def test_gpu_tril_triu():
check_u
(
m
,
1
)
check_u
(
m
,
-
1
)
m
=
np
.
asarray
(
test_rng
.
rand
(
10
,
5
)
*
2
-
1
,
dtype
=
dtype
)
m
=
np
.
asarray
(
test_rng
.
rand
om
((
10
,
5
)
)
*
2
-
1
,
dtype
=
dtype
)
check_l
(
m
,
0
)
check_l
(
m
,
1
)
check_l
(
m
,
-
1
)
...
...
tests/gpuarray/test_blocksparse.py
浏览文件 @
5611cf71
...
...
@@ -17,7 +17,6 @@ from tests.tensor.nnet.test_blocksparse import TestBlockSparseGemvAndOuter
class
TestBlockSparseGemvAndOuterGPUarray
(
TestBlockSparseGemvAndOuter
):
def
setup_method
(
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
...
...
tests/gpuarray/test_dnn.py
浏览文件 @
5611cf71
...
...
@@ -170,7 +170,6 @@ def test_dnn_conv_merge():
def
test_dnn_conv_inplace
():
# This test that we have inplace work correctly even when
# GpuAllocEmpty get merged together.
utt
.
seed_rng
()
img_shp
=
[
2
,
5
,
6
,
8
]
kern_shp
=
[
3
,
5
,
5
,
6
]
...
...
@@ -312,7 +311,6 @@ def test_dnn_conv3d_mixed_dtype():
def
test_pooling
():
utt
.
seed_rng
()
modes
=
get_dnn_pool_modes
()
...
...
@@ -420,7 +418,6 @@ def test_pooling():
# This test will be run with different values of 'mode'
# (see next test below).
def
run_pooling_with_tensor_vars
(
mode
):
utt
.
seed_rng
()
x
=
tensor4
()
ws
=
aesara
.
shared
(
np
.
array
([
2
,
2
],
dtype
=
"int32"
))
...
...
@@ -473,7 +470,6 @@ def test_pooling_with_tensor_vars():
@pytest.mark.skipif
(
dnn
.
version
(
raises
=
False
)
<
3000
,
reason
=
dnn
.
dnn_available
.
msg
)
def
test_pooling3d
():
# 3d pooling requires version 3 or newer.
utt
.
seed_rng
()
# We force the FAST_RUN as we don't want the reference to run in DebugMode.
mode_without_gpu_ref
=
aesara
.
compile
.
mode
.
get_mode
(
"FAST_RUN"
)
.
excluding
(
...
...
@@ -582,7 +578,6 @@ def test_pooling3d():
def
test_pooling_opt
():
utt
.
seed_rng
()
# 2D pooling
x
=
matrix
()
...
...
@@ -654,7 +649,6 @@ def test_pooling_opt():
def
test_pooling_opt_arbitrary_dimensions
():
# test if input with an arbitrary number of non-pooling dimensions
# is correctly reshaped to run on the GPU
utt
.
seed_rng
()
modes
=
get_dnn_pool_modes
()
...
...
@@ -1081,7 +1075,6 @@ def test_dnn_conv_border_mode():
def
test_dnn_conv_alpha_output_merge
():
utt
.
seed_rng
()
img
=
tensor4
()
kern
=
tensor4
()
...
...
@@ -1151,7 +1144,6 @@ def test_dnn_conv_alpha_output_merge():
def
test_dnn_conv_grad
():
utt
.
seed_rng
()
b
=
1
c
=
4
...
...
@@ -1261,7 +1253,6 @@ def run_conv_small_batched_vs_multicall(inputs_shape, filters_shape, batch_sub):
batch_size
=
inputs_shape
[
0
]
utt
.
seed_rng
()
inputs_val
=
np
.
random
.
random
(
inputs_shape
)
.
astype
(
"float32"
)
filters_val
=
np
.
random
.
random
(
filters_shape
)
.
astype
(
"float32"
)
# Scale down the input values to prevent very large absolute errors
...
...
@@ -1311,8 +1302,6 @@ def test_batched_conv3d_small():
def
test_conv3d_fwd
():
utt
.
seed_rng
()
def
run_conv3d_fwd
(
inputs_shape
,
filters_shape
,
subsample
,
dilation
,
border_mode
,
conv_mode
):
...
...
@@ -1378,8 +1367,6 @@ def test_conv3d_fwd():
def
test_conv3d_bwd
():
utt
.
seed_rng
()
def
run_conv3d_bwd
(
inputs_shape
,
filters_shape
,
subsample
,
dilation
,
border_mode
,
conv_mode
):
...
...
@@ -1819,7 +1806,6 @@ def test_dnn_maxandargmax_opt():
def
test_dnn_batchnorm_train
():
utt
.
seed_rng
()
for
mode
in
(
"per-activation"
,
"spatial"
):
for
vartype
in
(
...
...
@@ -2022,7 +2008,6 @@ def test_dnn_batchnorm_train():
def
test_dnn_batchnorm_train_without_running_averages
():
# compile and run batch_normalization_train without running averages
utt
.
seed_rng
()
x
,
scale
,
bias
,
dy
=
(
tensor4
(
"x"
),
...
...
@@ -2096,7 +2081,6 @@ def test_dnn_batchnorm_train_without_running_averages():
def
test_without_dnn_batchnorm_train_without_running_averages
():
# compile and run batch_normalization_train without running averages
# But disable cudnn and make sure it run on the GPU.
utt
.
seed_rng
()
x
,
scale
,
bias
,
dy
=
(
tensor4
(
"x"
),
...
...
@@ -2163,7 +2147,6 @@ def test_without_dnn_batchnorm_train_without_running_averages():
@utt.assertFailure_fast
def
test_dnn_batchnorm_train_inplace
():
# test inplace_running_mean and inplace_running_var
utt
.
seed_rng
()
x
,
scale
,
bias
=
tensor4
(
"x"
),
tensor4
(
"scale"
),
tensor4
(
"bias"
)
data_shape
=
(
5
,
10
,
30
,
25
)
...
...
@@ -2218,7 +2201,6 @@ def test_dnn_batchnorm_train_inplace():
def
test_batchnorm_inference
():
utt
.
seed_rng
()
for
mode
in
(
"per-activation"
,
"spatial"
):
for
vartype
in
(
...
...
@@ -2344,7 +2326,6 @@ def test_batchnorm_inference():
@utt.assertFailure_fast
def
test_batchnorm_inference_inplace
():
# test inplace
utt
.
seed_rng
()
x
,
scale
,
bias
,
mean
,
var
=
(
tensor4
(
n
)
for
n
in
(
"x"
,
"scale"
,
"bias"
,
"mean"
,
"var"
)
...
...
@@ -2460,7 +2441,6 @@ def test_dnn_batchnorm_valid_and_invalid_axes():
def
test_dnn_rnn_gru
():
utt
.
seed_rng
()
# test params
input_dim
=
32
...
...
@@ -2569,7 +2549,6 @@ def test_dnn_rnn_gru():
def
test_dnn_rnn_gru_bidi
():
utt
.
seed_rng
()
# test params
input_dim
=
32
...
...
@@ -2630,7 +2609,6 @@ def test_dnn_rnn_gru_bidi():
def
test_dnn_rnn_lstm
():
utt
.
seed_rng
()
# test params
input_dim
=
32
...
...
@@ -2716,7 +2694,6 @@ def test_dnn_rnn_lstm():
def
test_dnn_rnn_lstm_grad_c
():
utt
.
seed_rng
()
# test params
input_dim
=
32
...
...
@@ -2819,7 +2796,6 @@ class Cudnn_grouped_conv3d(TestGroupedConv3dNoOptim):
def
test_dnn_spatialtf
():
utt
.
seed_rng
()
"""
Spatial Transformer implementation using Aesara from Lasagne
...
...
@@ -3023,7 +2999,6 @@ def test_dnn_spatialtf_invalid_shapes():
def
test_dnn_spatialtf_grad
():
utt
.
seed_rng
()
inputs
=
tensor4
(
"inputs"
)
theta
=
tensor3
(
"theta"
)
...
...
@@ -3097,7 +3072,7 @@ class TestDnnConv2DRuntimeAlgorithms:
]
def
__init__
(
self
):
utt
.
seed_rng
()
self
.
runtime_algorithms
=
(
"time_once"
,
"guess_once"
,
...
...
@@ -3286,7 +3261,7 @@ class TestDnnConv3DRuntimeAlgorithms(TestDnnConv2DRuntimeAlgorithms):
def
test_conv_guess_once_with_dtypes
():
# This test checks that runtime conv algorithm selection does not raise any exception
# when consecutive functions with different dtypes and precisions are executed.
utt
.
seed_rng
()
inputs_shape
=
(
2
,
3
,
5
,
5
)
filters_shape
=
(
2
,
3
,
40
,
4
)
border_mode
=
"full"
...
...
tests/gpuarray/test_linalg.py
浏览文件 @
5611cf71
...
...
@@ -27,7 +27,7 @@ from aesara.tensor.slinalg import Cholesky, cholesky, imported_scipy
from
aesara.tensor.type
import
fmatrix
,
matrix
,
tensor3
,
vector
from
tests
import
unittest_tools
as
utt
from
tests.gpuarray.config
import
mode_with_gpu
,
mode_without_gpu
from
tests.gpuarray.test_basic_ops
import
rand
from
tests.gpuarray.test_basic_ops
import
rand
om
@pytest.mark.skipif
(
...
...
@@ -149,7 +149,7 @@ class TestCusolver:
utt
.
verify_grad
(
solve_op
,
[
A_val
,
b_val
],
3
,
rng
,
eps
=
eps
)
def
test_solve_grad
(
self
):
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
structures
=
[
"general"
,
"lower_triangular"
,
"upper_triangular"
]
for
A_structure
in
structures
:
lower
=
A_structure
==
"lower_triangular"
...
...
@@ -166,9 +166,6 @@ class TestCusolver:
reason
=
"Optional package scikits.cuda.cusolver not available"
,
)
class
TestGpuCholesky
:
def
setup_method
(
self
):
utt
.
seed_rng
()
def
get_gpu_cholesky_func
(
self
,
lower
=
True
,
inplace
=
False
):
# Helper function to compile function from GPU Cholesky op.
A
=
matrix
(
"A"
,
dtype
=
"float32"
)
...
...
@@ -267,9 +264,6 @@ class TestGpuCholesky:
reason
=
"Optional package scikits.cuda.cusolver not available"
,
)
class
TestGpuCholesky64
:
def
setup_method
(
self
):
utt
.
seed_rng
()
def
get_gpu_cholesky_func
(
self
,
lower
=
True
,
inplace
=
False
):
# Helper function to compile function from GPU Cholesky op.
A
=
matrix
(
"A"
,
dtype
=
"float64"
)
...
...
@@ -388,18 +382,18 @@ class TestMagma:
fn
=
aesara
.
function
([
A
],
gpu_matrix_inverse
(
A
),
mode
=
mode_with_gpu
)
N
=
1000
test_rng
=
np
.
random
.
RandomState
(
seed
=
1
)
# Copied from tests.tensor.utils.rand.
A_val
=
test_rng
.
rand
(
N
,
N
)
.
astype
(
"float32"
)
*
2
-
1
test_rng
=
np
.
random
.
default_rng
(
seed
=
1
)
# Copied from tests.tensor.utils.rand
om
.
A_val
=
test_rng
.
rand
om
((
N
,
N
)
)
.
astype
(
"float32"
)
*
2
-
1
A_val_inv
=
fn
(
A_val
)
utt
.
assert_allclose
(
np
.
eye
(
N
),
np
.
dot
(
A_val_inv
,
A_val
),
atol
=
1e-2
)
@utt.assertFailure_fast
def
test_gpu_matrix_inverse_inplace
(
self
):
N
=
1000
test_rng
=
np
.
random
.
RandomState
(
seed
=
1
)
test_rng
=
np
.
random
.
default_rng
(
seed
=
1
)
A_val_gpu
=
gpuarray_shared_constructor
(
test_rng
.
rand
(
N
,
N
)
.
astype
(
"float32"
)
*
2
-
1
test_rng
.
rand
om
((
N
,
N
)
)
.
astype
(
"float32"
)
*
2
-
1
)
A_val_copy
=
A_val_gpu
.
get_value
()
A_val_gpu_inv
=
GpuMagmaMatrixInverse
()(
A_val_gpu
)
...
...
@@ -448,7 +442,7 @@ class TestMagma:
utt
.
assert_allclose
(
np
.
dot
(
np
.
dot
(
U
,
S_m
),
VT
),
A
,
rtol
=
rtol
,
atol
=
atol
)
def
test_gpu_svd_wide
(
self
):
A
=
rand
(
100
,
50
)
.
astype
(
"float32"
)
A
=
rand
om
(
100
,
50
)
.
astype
(
"float32"
)
M
,
N
=
A
.
shape
U
,
S
,
VT
=
self
.
run_gpu_svd
(
A
)
...
...
@@ -463,7 +457,7 @@ class TestMagma:
self
.
assert_column_orthonormal
(
VT
.
T
)
def
test_gpu_svd_tall
(
self
):
A
=
rand
(
50
,
100
)
.
astype
(
"float32"
)
A
=
rand
om
(
50
,
100
)
.
astype
(
"float32"
)
M
,
N
=
A
.
shape
U
,
S
,
VT
=
self
.
run_gpu_svd
(
A
)
...
...
@@ -484,10 +478,10 @@ class TestMagma:
)
f_gpu
=
aesara
.
function
([
A
],
gpu_svd
(
A
,
compute_uv
=
False
),
mode
=
mode_with_gpu
)
A_val
=
rand
(
50
,
100
)
.
astype
(
"float32"
)
A_val
=
rand
om
(
50
,
100
)
.
astype
(
"float32"
)
utt
.
assert_allclose
(
f_cpu
(
A_val
),
f_gpu
(
A_val
))
A_val
=
rand
(
100
,
50
)
.
astype
(
"float32"
)
A_val
=
rand
om
(
100
,
50
)
.
astype
(
"float32"
)
utt
.
assert_allclose
(
f_cpu
(
A_val
),
f_gpu
(
A_val
))
def
run_gpu_cholesky
(
self
,
A_val
,
lower
=
True
):
...
...
@@ -500,7 +494,7 @@ class TestMagma:
return
f
(
A_val
)
def
rand_symmetric
(
self
,
N
):
A
=
rand
(
N
,
N
)
.
astype
(
"float32"
)
A
=
rand
om
(
N
,
N
)
.
astype
(
"float32"
)
# ensure that eigenvalues are not too small which sometimes results in
# magma cholesky failure due to gpu limited numerical precision
D
,
W
=
np
.
linalg
.
eigh
(
A
)
...
...
@@ -566,7 +560,7 @@ class TestMagma:
return
fn
(
A_val
)
def
check_gpu_qr
(
self
,
M
,
N
,
complete
=
True
,
rtol
=
None
,
atol
=
None
):
A
=
rand
(
M
,
N
)
.
astype
(
"float32"
)
A
=
rand
om
(
M
,
N
)
.
astype
(
"float32"
)
if
complete
:
Q_gpu
,
R_gpu
=
self
.
run_gpu_qr
(
A
,
complete
=
complete
)
else
:
...
...
@@ -611,7 +605,7 @@ class TestMagma:
return
fn
(
A_val
)
def
check_gpu_eigh
(
self
,
N
,
UPLO
=
"L"
,
compute_v
=
True
,
rtol
=
None
,
atol
=
None
):
A
=
rand
(
N
,
N
)
.
astype
(
"float32"
)
A
=
rand
om
(
N
,
N
)
.
astype
(
"float32"
)
A
=
np
.
dot
(
A
.
T
,
A
)
d_np
,
v_np
=
np
.
linalg
.
eigh
(
A
,
UPLO
=
UPLO
)
if
compute_v
:
...
...
@@ -643,8 +637,8 @@ class TestMagma:
# mostly copied from aesara/tensor/tests/test_slinalg.py
def
test_cholesky_grad
():
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
r
=
rng
.
randn
(
5
,
5
)
.
astype
(
config
.
floatX
)
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
r
=
rng
.
standard_normal
((
5
,
5
)
)
.
astype
(
config
.
floatX
)
# The dots are inside the graph since Cholesky needs separable matrices
...
...
@@ -681,9 +675,9 @@ def test_lower_triangular_and_cholesky_grad():
N
=
100
else
:
N
=
5
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
r
=
rng
.
randn
(
N
,
N
)
.
astype
(
config
.
floatX
)
y
=
rng
.
rand
(
N
,
1
)
.
astype
(
config
.
floatX
)
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
r
=
rng
.
standard_normal
((
N
,
N
)
)
.
astype
(
config
.
floatX
)
y
=
rng
.
rand
om
((
N
,
1
)
)
.
astype
(
config
.
floatX
)
def
f
(
r
,
y
):
PD
=
r
.
dot
(
r
.
T
)
...
...
tests/gpuarray/test_nnet.py
浏览文件 @
5611cf71
...
...
@@ -42,9 +42,6 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
# case.
dot_result
=
fmatrix
(
"dot_result"
)
# Seed numpy.random with config.unittests__rseed
utt
.
seed_rng
()
xx
=
np
.
asarray
(
np
.
random
.
rand
(
batch_size
,
n_in
),
dtype
=
np
.
float32
)
yy
=
np
.
ones
((
batch_size
,),
dtype
=
"int32"
)
b_values
=
np
.
zeros
((
n_out
,),
dtype
=
"float32"
)
...
...
@@ -97,9 +94,6 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
if
not
isinstance
(
mode_with_gpu
,
aesara
.
compile
.
debugmode
.
DebugMode
):
n_out
=
4099
# Seed numpy.random with config.unittests__rseed
utt
.
seed_rng
()
softmax_output_value
=
np
.
random
.
rand
(
batch_size
,
n_out
)
.
astype
(
"float32"
)
dnll_value
=
np
.
asarray
(
np
.
random
.
rand
(
batch_size
),
dtype
=
"float32"
)
y_idx_value
=
np
.
random
.
randint
(
low
=
0
,
high
=
5
,
size
=
batch_size
)
...
...
tests/gpuarray/test_opt.py
浏览文件 @
5611cf71
...
...
@@ -595,14 +595,15 @@ def test_many_arg_elemwise():
# This test checks whether the + and * elemwise ops can handle
# extremely large numbers of arguments on gpu.
rng
=
np
.
random
.
RandomState
([
1
,
2
,
3
])
rng
=
np
.
random
.
default_rng
([
1
,
2
,
3
])
nb_of_inputs_overflows
=
[]
for
num_args
in
[
64
]:
for
op_to_test
in
[
aesara
.
tensor
.
add
,
aesara
.
tensor
.
mul
]:
for
nb_dim
in
[
2
,
8
]:
shapes
=
[
rng
.
randint
(
1
,
5
)
for
i
in
range
(
nb_dim
)]
shapes
=
[
rng
.
integers
(
1
,
5
)
for
i
in
range
(
nb_dim
)]
args
=
[
np
.
cast
[
"float32"
](
rng
.
randn
(
*
shapes
))
for
arg
in
range
(
0
,
num_args
)
np
.
cast
[
"float32"
](
rng
.
standard_normal
(
shapes
))
for
arg
in
range
(
0
,
num_args
)
]
symb_args
=
[
...
...
@@ -645,8 +646,8 @@ def test_not_useless_scalar_gpuelemwise():
with
config
.
change_flags
(
warn_float64
=
"ignore"
):
X
=
fmatrix
()
x
=
np
.
random
.
randn
(
32
,
32
)
.
astype
(
np
.
float32
)
m1
=
aesara
.
shared
(
np
.
random
.
randn
(
32
,
32
)
.
astype
(
np
.
float32
))
x
=
np
.
random
.
standard_normal
((
32
,
32
)
)
.
astype
(
np
.
float32
)
m1
=
aesara
.
shared
(
np
.
random
.
standard_normal
((
32
,
32
)
)
.
astype
(
np
.
float32
))
loss
=
(
X
-
dot
(
X
,
m1
))
.
norm
(
L
=
2
)
lr
=
aesara
.
shared
(
np
.
asarray
(
0.001
,
dtype
=
np
.
float32
))
grad
=
aesara
.
grad
(
loss
,
m1
)
...
...
@@ -672,7 +673,7 @@ def test_local_lift_abstractconv_gpu_shape():
def
test_local_assert_no_cpu_op
():
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
m
=
rng
.
uniform
(
-
1
,
1
,
(
10
,
10
))
.
astype
(
"float32"
)
ms
=
gpuarray_shared_constructor
(
m
,
name
=
"m_shared"
)
out
=
tanh
(
ms
)
.
dot
(
ms
.
T
)
...
...
@@ -806,17 +807,17 @@ def test_local_gpua_advanced_incsubtensor():
def
test_batched_dot_lifter
():
# The CPU Op accepts 2D and 3D inputs, as well as mixed dtypes.
# Make sure the lifter adds the appropriate dimshuffles and casts
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
def
randX
(
*
args
):
return
rng
.
rand
(
*
args
)
.
astype
(
config
.
floatX
)
return
rng
.
rand
om
(
args
)
.
astype
(
config
.
floatX
)
cases
=
[
(
randX
(
3
,
5
,
7
),
randX
(
3
,
7
)),
(
randX
(
3
,
5
),
randX
(
3
,
5
,
7
)),
(
randX
(
3
,
5
),
randX
(
3
,
5
)),
(
rng
.
rand
(
3
,
5
,
7
)
.
astype
(
"float32"
),
randX
(
3
,
7
,
9
)),
(
rng
.
rand
(
3
,
5
,
7
)
.
astype
(
"float64"
),
randX
(
3
,
7
,
9
)),
(
rng
.
rand
om
((
3
,
5
,
7
)
)
.
astype
(
"float32"
),
randX
(
3
,
7
,
9
)),
(
rng
.
rand
om
((
3
,
5
,
7
)
)
.
astype
(
"float64"
),
randX
(
3
,
7
,
9
)),
]
for
x_val
,
y_val
in
cases
:
x
=
TensorType
(
broadcastable
=
[
s
==
1
for
s
in
x_val
.
shape
],
dtype
=
x_val
.
dtype
)(
...
...
@@ -832,7 +833,7 @@ def test_batched_dot_lifter():
def
test_crossentropycategorical1hot_lifter
():
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
x
=
matrix
()
y
=
lvector
()
z
=
aesara
.
tensor
.
nnet
.
crossentropy_categorical_1hot
(
x
,
y
)
...
...
@@ -850,7 +851,7 @@ def test_crossentropycategorical1hot_lifter():
)
f
(
rng
.
uniform
(
0.1
,
0.9
,
(
13
,
5
))
.
astype
(
config
.
floatX
),
rng
.
randint
(
5
,
size
=
(
13
,)),
rng
.
integers
(
5
,
size
=
(
13
,)),
)
...
...
tests/gpuarray/test_pool.py
浏览文件 @
5611cf71
...
...
@@ -21,13 +21,13 @@ from aesara.tensor.signal.pool import (
)
from
tests
import
unittest_tools
as
utt
from
tests.gpuarray.config
import
mode_with_gpu
,
mode_without_gpu
from
tests.gpuarray.test_basic_ops
import
rand
from
tests.gpuarray.test_basic_ops
import
rand
om
class
TestPool
:
def
test_pool_py_interface
(
self
):
shp
=
(
2
,
2
,
2
,
2
)
inp
=
aesara
.
shared
(
rand
(
*
shp
),
"a"
)
inp
=
aesara
.
shared
(
rand
om
(
*
shp
),
"a"
)
inp
=
aet
.
as_tensor_variable
(
inp
)
with
pytest
.
raises
(
ValueError
):
# test when pad >= ws
...
...
@@ -43,7 +43,7 @@ class TestPool:
gpu_mode
.
check_py_code
=
False
shp
=
(
2
,
2
,
2
,
2
)
inp
=
aesara
.
shared
(
rand
(
*
shp
),
"a"
)
inp
=
aesara
.
shared
(
rand
om
(
*
shp
),
"a"
)
inp
=
aet
.
as_tensor_variable
(
inp
)
with
pytest
.
raises
(
ValueError
):
# test when ignore_border and pad >= 0
...
...
@@ -57,7 +57,7 @@ class TestPool:
gpu_mode
.
check_py_code
=
False
shp
=
(
2
,
2
,
2
,
2
)
inp
=
aesara
.
shared
(
rand
(
*
shp
),
"a"
)
inp
=
aesara
.
shared
(
rand
om
(
*
shp
),
"a"
)
inp
=
aet
.
as_tensor_variable
(
inp
)
ds_op
=
GpuPool
(
ignore_border
=
False
,
mode
=
"average_exc_pad"
,
ndim
=
2
)
pad
=
aet
.
as_tensor_variable
([
0
,
0
])
...
...
@@ -102,7 +102,7 @@ def test_pool2d():
(
3
,
2
,
6
,
6
,
6
,
5
,
7
),
]
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
shuffle
(
shps
)
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
.
shuffle
(
shps
)
test_ws
=
(
2
,
2
),
(
3
,
2
),
(
1
,
1
)
test_st
=
(
2
,
2
),
(
3
,
2
),
(
1
,
1
)
test_mode
=
[
"max"
,
"sum"
,
"average_inc_pad"
,
"average_exc_pad"
]
...
...
@@ -124,7 +124,7 @@ def test_pool2d():
# print('test_pool2d', shp, ws, st, pad, mode, ignore_border)
ds_op
=
Pool
(
ndim
=
len
(
ws
),
mode
=
mode
,
ignore_border
=
ignore_border
)
a
=
aesara
.
shared
(
rand
(
*
shp
),
"a"
)
a
=
aesara
.
shared
(
rand
om
(
*
shp
),
"a"
)
a_pooled
=
ds_op
(
aet
.
as_tensor_variable
(
a
),
ws
,
st
,
pad
)
f
=
aesara
.
function
([],
a_pooled
,
mode
=
gpu_mode
)
...
...
@@ -163,7 +163,7 @@ def test_pool2d():
if
mode
!=
"max"
:
continue
ea
=
aesara
.
shared
(
rand
(
*
shp
),
"ea"
)
ea
=
aesara
.
shared
(
rand
om
(
*
shp
),
"ea"
)
gr
=
aesara
.
function
([],
Rop
(
a_pooled
,
a
,
ea
),
mode
=
gpu_mode
)
gr2
=
aesara
.
function
([],
Rop
(
a_pooled
,
a
,
ea
),
mode
=
ref_mode
)
...
...
@@ -226,7 +226,7 @@ def test_pool3d():
(
3
,
2
,
6
,
6
,
6
,
5
,
7
),
]
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
shuffle
(
shps
)
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
.
shuffle
(
shps
)
test_ws
=
(
2
,
2
,
2
),
(
3
,
2
,
3
),
(
1
,
1
,
1
)
test_st
=
(
2
,
2
,
2
),
(
2
,
3
,
2
),
(
1
,
1
,
1
)
test_mode
=
[
"max"
,
"sum"
,
"average_inc_pad"
,
"average_exc_pad"
]
...
...
@@ -250,7 +250,7 @@ def test_pool3d():
# print('test_pool3d', shp, ws, st, pad, mode, ignore_border)
ds_op
=
Pool
(
ndim
=
len
(
ws
),
mode
=
mode
,
ignore_border
=
ignore_border
)
a
=
aesara
.
shared
(
rand
(
*
shp
),
"a"
)
a
=
aesara
.
shared
(
rand
om
(
*
shp
),
"a"
)
a_pooled
=
ds_op
(
aet
.
as_tensor_variable
(
a
),
ws
,
st
,
pad
)
f
=
aesara
.
function
([],
a_pooled
,
mode
=
gpu_mode
)
...
...
@@ -289,7 +289,7 @@ def test_pool3d():
if
mode
!=
"max"
:
continue
ea
=
aesara
.
shared
(
rand
(
*
shp
),
"ea"
)
ea
=
aesara
.
shared
(
rand
om
(
*
shp
),
"ea"
)
gr
=
aesara
.
function
([],
Rop
(
a_pooled
,
a
,
ea
),
mode
=
gpu_mode
)
gr2
=
aesara
.
function
([],
Rop
(
a_pooled
,
a
,
ea
),
mode
=
ref_mode
)
...
...
tests/gpuarray/test_rng_mrg.py
浏览文件 @
5611cf71
...
...
@@ -15,9 +15,6 @@ from tests.sandbox.test_rng_mrg import java_samples, rng_mrg_overflow
from
tests.sandbox.test_rng_mrg
import
test_f16_nonzero
as
cpu_f16_nonzero
utt
.
seed_rng
()
def
test_consistency_GPUA_serial
():
# Verify that the random numbers generated by GPUA_mrg_uniform, serially,
# are the same as the reference (Java) implementation by L'Ecuyer et al.
...
...
tests/gpuarray/test_scan.py
浏览文件 @
5611cf71
...
...
@@ -32,9 +32,6 @@ else:
class
TestScan
:
def
setup_method
(
self
):
utt
.
seed_rng
()
def
test_one_sequence_one_output_weights_gpu1
(
self
):
def
f_rnn
(
u_t
,
x_tm1
,
W_in
,
W
):
return
u_t
*
W_in
+
x_tm1
*
W
...
...
@@ -65,7 +62,7 @@ class TestScan:
mode
=
mode
,
)
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.0
,
high
=
5.0
)
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
...
...
@@ -134,7 +131,7 @@ class TestScan:
)
# get random initial values
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.0
,
high
=
5.0
)
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
...
...
@@ -193,7 +190,7 @@ class TestScan:
)
# get random initial values
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.0
,
high
=
5.0
)
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
...
...
@@ -225,7 +222,7 @@ class TestScan:
assert
not
any
([
isinstance
(
node
.
op
,
GpuFromHost
)
for
node
in
scan_node_topo
])
def
test_gpu4_gibbs_chain
(
self
):
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
v_vsample
=
np
.
array
(
rng
.
binomial
(
1
,
...
...
@@ -313,7 +310,7 @@ class ScanGpuTests:
)
# get random initial values
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.0
,
high
=
5.0
)
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
...
...
@@ -402,7 +399,7 @@ class ScanGpuTests:
)
# get random initial values
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.0
,
high
=
5.0
)
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
...
...
@@ -481,7 +478,7 @@ class ScanGpuTests:
)
# get random initial values
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.0
,
high
=
5.0
)
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
...
...
@@ -507,7 +504,7 @@ class ScanGpuTests:
assert
self
.
is_scan_on_gpu
(
scan_node
)
def
test_gibbs_chain
(
self
):
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
v_vsample
=
np
.
array
(
rng
.
binomial
(
1
,
...
...
@@ -681,8 +678,6 @@ class TestScanGpuarray(ScanGpuTests):
if
not
self
.
gpu_backend
.
pygpu_activated
:
pytest
.
skip
(
"Optional package pygpu disabled"
)
utt
.
seed_rng
()
def
is_scan_on_gpu
(
self
,
node
):
return
node
.
op
.
info
.
get
(
"gpua"
,
False
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论