Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3c4ac6d0
提交
3c4ac6d0
authored
3月 29, 2017
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move the gpuarray ops and tests under the gpuarray directory.
上级
ae9139ac
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
173 行增加
和
160 行删除
+173
-160
rng_mrg.py
theano/gpuarray/rng_mrg.py
+0
-0
test_others.py
theano/gpuarray/tests/test_others.py
+2
-0
test_rng_mrg.py
theano/gpuarray/tests/test_rng_mrg.py
+171
-0
rng_mrg.py
theano/sandbox/rng_mrg.py
+0
-0
test_rng_mrg.py
theano/sandbox/tests/test_rng_mrg.py
+0
-160
没有找到文件。
theano/gpuarray/rng_mrg.py
0 → 100644
浏览文件 @
3c4ac6d0
差异被折叠。
点击展开。
theano/gpuarray/tests/test_others.py
浏览文件 @
3c4ac6d0
from
__future__
import
absolute_import
,
print_function
,
division
from
.config
import
test_ctx_name
,
mode_with_gpu
from
.config
import
test_ctx_name
,
mode_with_gpu
from
..type
import
(
get_context
,
GpuArrayType
,
GpuArraySharedVariable
,
from
..type
import
(
get_context
,
GpuArrayType
,
GpuArraySharedVariable
,
...
@@ -11,6 +12,7 @@ from theano.misc.pkl_utils import dump, load
...
@@ -11,6 +12,7 @@ from theano.misc.pkl_utils import dump, load
from
theano.tensor.tests.test_opt
import
test_fusion
as
t_fusion
from
theano.tensor.tests.test_opt
import
test_fusion
as
t_fusion
class
test_fusion
(
t_fusion
):
class
test_fusion
(
t_fusion
):
mode
=
mode_with_gpu
mode
=
mode_with_gpu
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
...
...
theano/gpuarray/tests/test_rng_mrg.py
0 → 100644
浏览文件 @
3c4ac6d0
from
__future__
import
absolute_import
,
print_function
,
division
import
functools
import
numpy
import
theano
from
theano
import
tensor
from
theano.sandbox
import
rng_mrg
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
from
theano.sandbox.tests.test_rng_mrg
import
java_samples
,
rng_mrg_overflow
from
theano.tests
import
unittest_tools
as
utt
from
theano.gpuarray.tests.config
import
mode_with_gpu
as
mode
from
theano.gpuarray.type
import
gpuarray_shared_constructor
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.
seed
=
12345
n_samples
=
5
n_streams
=
12
n_substreams
=
7
samples
=
[]
curr_rstate
=
numpy
.
array
([
seed
]
*
6
,
dtype
=
'int32'
)
for
i
in
range
(
n_streams
):
stream_rstate
=
curr_rstate
.
copy
()
for
j
in
range
(
n_substreams
):
substream_rstate
=
numpy
.
array
([
stream_rstate
.
copy
()],
dtype
=
'int32'
)
# Transfer to device
rstate
=
gpuarray_shared_constructor
(
substream_rstate
)
new_rstate
,
sample
=
rng_mrg
.
GPUA_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
'float32'
,
size
=
(
1
,))
rstate
.
default_update
=
new_rstate
# Not really necessary, just mimicking
# rng_mrg.MRG_RandomStreams' behavior
sample
.
rstate
=
rstate
sample
.
update
=
(
rstate
,
new_rstate
)
# We need the sample back in the main memory
cpu_sample
=
tensor
.
as_tensor_variable
(
sample
)
f
=
theano
.
function
([],
cpu_sample
,
mode
=
mode
)
for
k
in
range
(
n_samples
):
s
=
f
()
samples
.
append
(
s
)
# next substream
stream_rstate
=
rng_mrg
.
ff_2p72
(
stream_rstate
)
# next stream
curr_rstate
=
rng_mrg
.
ff_2p134
(
curr_rstate
)
samples
=
numpy
.
array
(
samples
)
.
flatten
()
assert
(
numpy
.
allclose
(
samples
,
java_samples
))
def
test_consistency_GPUA_parallel
():
# Verify that the random numbers generated by GPUA_mrg_uniform, in
# parallel, are the same as the reference (Java) implementation by
# L'Ecuyer et al.
seed
=
12345
n_samples
=
5
n_streams
=
12
n_substreams
=
7
# 7 samples will be drawn in parallel
samples
=
[]
curr_rstate
=
numpy
.
array
([
seed
]
*
6
,
dtype
=
'int32'
)
for
i
in
range
(
n_streams
):
stream_samples
=
[]
rstate
=
[
curr_rstate
.
copy
()]
for
j
in
range
(
1
,
n_substreams
):
rstate
.
append
(
rng_mrg
.
ff_2p72
(
rstate
[
-
1
]))
rstate
=
numpy
.
asarray
(
rstate
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
new_rstate
,
sample
=
rng_mrg
.
GPUA_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
'float32'
,
size
=
(
n_substreams
,))
rstate
.
default_update
=
new_rstate
# Not really necessary, just mimicking
# rng_mrg.MRG_RandomStreams' behavior
sample
.
rstate
=
rstate
sample
.
update
=
(
rstate
,
new_rstate
)
# We need the sample back in the main memory
cpu_sample
=
tensor
.
as_tensor_variable
(
sample
)
f
=
theano
.
function
([],
cpu_sample
,
mode
=
mode
)
for
k
in
range
(
n_samples
):
s
=
f
()
stream_samples
.
append
(
s
)
samples
.
append
(
numpy
.
array
(
stream_samples
)
.
T
.
flatten
())
# next stream
curr_rstate
=
rng_mrg
.
ff_2p134
(
curr_rstate
)
samples
=
numpy
.
array
(
samples
)
.
flatten
()
assert
(
numpy
.
allclose
(
samples
,
java_samples
))
def
test_GPUA_full_fill
():
# Make sure the whole sample buffer is filled. Also make sure
# large samples are consistent with CPU results.
import
theano.gpuarray.tests.config
from
theano.gpuarray.type
import
gpuarray_shared_constructor
# This needs to be large to trigger the problem on GPU
size
=
(
10
,
1000
)
R
=
MRG_RandomStreams
(
234
)
uni
=
R
.
uniform
(
size
,
nstreams
=
60
*
256
)
f_cpu
=
theano
.
function
([],
uni
)
rstate_gpu
=
gpuarray_shared_constructor
(
R
.
state_updates
[
-
1
][
0
]
.
get_value
())
new_rstate
,
sample
=
rng_mrg
.
GPUA_mrg_uniform
.
new
(
rstate_gpu
,
ndim
=
None
,
dtype
=
'float32'
,
size
=
size
)
rstate_gpu
.
default_update
=
new_rstate
f_gpu
=
theano
.
function
([],
sample
)
utt
.
assert_allclose
(
f_cpu
(),
f_gpu
())
def
test_overflow_gpu_new_backend
():
from
theano.gpuarray.tests.test_basic_ops
import
\
mode_with_gpu
as
mode
from
theano.gpuarray.type
import
gpuarray_shared_constructor
seed
=
12345
n_substreams
=
7
curr_rstate
=
numpy
.
array
([
seed
]
*
6
,
dtype
=
'int32'
)
rstate
=
[
curr_rstate
.
copy
()]
for
j
in
range
(
1
,
n_substreams
):
rstate
.
append
(
rng_mrg
.
ff_2p72
(
rstate
[
-
1
]))
rstate
=
numpy
.
asarray
(
rstate
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
fct
=
functools
.
partial
(
rng_mrg
.
GPUA_mrg_uniform
.
new
,
rstate
,
ndim
=
None
,
dtype
=
'float32'
)
# should raise error as the size overflows
sizes
=
[(
2
**
31
,
),
(
2
**
32
,
),
(
2
**
15
,
2
**
16
,),
(
2
,
2
**
15
,
2
**
15
)]
rng_mrg_overflow
(
sizes
,
fct
,
mode
,
should_raise_error
=
True
)
# should not raise error
sizes
=
[(
2
**
5
,
),
(
2
**
5
,
2
**
5
),
(
2
**
5
,
2
**
5
,
2
**
5
)]
rng_mrg_overflow
(
sizes
,
fct
,
mode
,
should_raise_error
=
False
)
# should support int32 sizes
sizes
=
[(
numpy
.
int32
(
2
**
10
),
),
(
numpy
.
int32
(
2
),
numpy
.
int32
(
2
**
10
),
numpy
.
int32
(
2
**
10
))]
rng_mrg_overflow
(
sizes
,
fct
,
mode
,
should_raise_error
=
False
)
def
test_validate_input_types_gpuarray_backend
():
from
theano.sandbox.rng_mrg
import
mrg_uniform
from
theano.gpuarray.type
import
gpuarray_shared_constructor
from
theano.configparser
import
change_flags
with
change_flags
(
compute_test_value
=
"raise"
):
rstate
=
numpy
.
zeros
((
7
,
6
),
dtype
=
"int32"
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
"float32"
,
size
=
(
3
,))
theano/sandbox/rng_mrg.py
浏览文件 @
3c4ac6d0
差异被折叠。
点击展开。
theano/sandbox/tests/test_rng_mrg.py
浏览文件 @
3c4ac6d0
...
@@ -17,7 +17,6 @@ from theano.sandbox import rng_mrg
...
@@ -17,7 +17,6 @@ from theano.sandbox import rng_mrg
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests.unittest_tools
import
attr
from
theano.tests.unittest_tools
import
attr
import
theano.gpuarray.tests.config
# TODO: test MRG_RandomStreams
# TODO: test MRG_RandomStreams
# Partly done in test_consistency_randomstreams
# Partly done in test_consistency_randomstreams
...
@@ -186,129 +185,6 @@ def test_consistency_cpu_parallel():
...
@@ -186,129 +185,6 @@ def test_consistency_cpu_parallel():
assert
(
np
.
allclose
(
samples
,
java_samples
))
assert
(
np
.
allclose
(
samples
,
java_samples
))
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.
from
theano.gpuarray.tests.config
import
mode_with_gpu
as
mode
from
theano.gpuarray.type
import
gpuarray_shared_constructor
seed
=
12345
n_samples
=
5
n_streams
=
12
n_substreams
=
7
samples
=
[]
curr_rstate
=
np
.
array
([
seed
]
*
6
,
dtype
=
'int32'
)
for
i
in
range
(
n_streams
):
stream_rstate
=
curr_rstate
.
copy
()
for
j
in
range
(
n_substreams
):
substream_rstate
=
np
.
array
([
stream_rstate
.
copy
()],
dtype
=
'int32'
)
# Transfer to device
rstate
=
gpuarray_shared_constructor
(
substream_rstate
)
new_rstate
,
sample
=
rng_mrg
.
GPUA_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
'float32'
,
size
=
(
1
,))
rstate
.
default_update
=
new_rstate
# Not really necessary, just mimicking
# rng_mrg.MRG_RandomStreams' behavior
sample
.
rstate
=
rstate
sample
.
update
=
(
rstate
,
new_rstate
)
# We need the sample back in the main memory
cpu_sample
=
tensor
.
as_tensor_variable
(
sample
)
f
=
theano
.
function
([],
cpu_sample
,
mode
=
mode
)
for
k
in
range
(
n_samples
):
s
=
f
()
samples
.
append
(
s
)
# next substream
stream_rstate
=
rng_mrg
.
ff_2p72
(
stream_rstate
)
# next stream
curr_rstate
=
rng_mrg
.
ff_2p134
(
curr_rstate
)
samples
=
np
.
array
(
samples
)
.
flatten
()
assert
(
np
.
allclose
(
samples
,
java_samples
))
def
test_consistency_GPUA_parallel
():
# Verify that the random numbers generated by GPUA_mrg_uniform, in
# parallel, are the same as the reference (Java) implementation by
# L'Ecuyer et al.
from
theano.gpuarray.tests.config
import
mode_with_gpu
as
mode
from
theano.gpuarray.type
import
gpuarray_shared_constructor
seed
=
12345
n_samples
=
5
n_streams
=
12
n_substreams
=
7
# 7 samples will be drawn in parallel
samples
=
[]
curr_rstate
=
np
.
array
([
seed
]
*
6
,
dtype
=
'int32'
)
for
i
in
range
(
n_streams
):
stream_samples
=
[]
rstate
=
[
curr_rstate
.
copy
()]
for
j
in
range
(
1
,
n_substreams
):
rstate
.
append
(
rng_mrg
.
ff_2p72
(
rstate
[
-
1
]))
rstate
=
np
.
asarray
(
rstate
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
new_rstate
,
sample
=
rng_mrg
.
GPUA_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
'float32'
,
size
=
(
n_substreams
,))
rstate
.
default_update
=
new_rstate
# Not really necessary, just mimicking
# rng_mrg.MRG_RandomStreams' behavior
sample
.
rstate
=
rstate
sample
.
update
=
(
rstate
,
new_rstate
)
# We need the sample back in the main memory
cpu_sample
=
tensor
.
as_tensor_variable
(
sample
)
f
=
theano
.
function
([],
cpu_sample
,
mode
=
mode
)
for
k
in
range
(
n_samples
):
s
=
f
()
stream_samples
.
append
(
s
)
samples
.
append
(
np
.
array
(
stream_samples
)
.
T
.
flatten
())
# next stream
curr_rstate
=
rng_mrg
.
ff_2p134
(
curr_rstate
)
samples
=
np
.
array
(
samples
)
.
flatten
()
assert
(
np
.
allclose
(
samples
,
java_samples
))
def
test_GPUA_full_fill
():
# Make sure the whole sample buffer is filled. Also make sure
# large samples are consistent with CPU results.
import
theano.gpuarray.tests.config
from
theano.gpuarray.type
import
gpuarray_shared_constructor
# This needs to be large to trigger the problem on GPU
size
=
(
10
,
1000
)
R
=
MRG_RandomStreams
(
234
)
uni
=
R
.
uniform
(
size
,
nstreams
=
60
*
256
)
f_cpu
=
theano
.
function
([],
uni
)
rstate_gpu
=
gpuarray_shared_constructor
(
R
.
state_updates
[
-
1
][
0
]
.
get_value
())
new_rstate
,
sample
=
rng_mrg
.
GPUA_mrg_uniform
.
new
(
rstate_gpu
,
ndim
=
None
,
dtype
=
'float32'
,
size
=
size
)
rstate_gpu
.
default_update
=
new_rstate
f_gpu
=
theano
.
function
([],
sample
)
utt
.
assert_allclose
(
f_cpu
(),
f_gpu
())
def
basictest
(
f
,
steps
,
sample_size
,
prefix
=
""
,
allow_01
=
False
,
inputs
=
None
,
def
basictest
(
f
,
steps
,
sample_size
,
prefix
=
""
,
allow_01
=
False
,
inputs
=
None
,
target_avg
=
0.5
,
target_std
=
None
,
mean_rtol
=
0.01
,
std_tol
=
0.01
):
target_avg
=
0.5
,
target_std
=
None
,
mean_rtol
=
0.01
,
std_tol
=
0.01
):
if
inputs
is
None
:
if
inputs
is
None
:
...
@@ -842,42 +718,6 @@ def test_overflow_cpu():
...
@@ -842,42 +718,6 @@ def test_overflow_cpu():
rng_mrg_overflow
(
sizes
,
fct
,
config
.
mode
,
should_raise_error
=
False
)
rng_mrg_overflow
(
sizes
,
fct
,
config
.
mode
,
should_raise_error
=
False
)
def
test_overflow_gpu_new_backend
():
from
theano.gpuarray.tests.test_basic_ops
import
\
mode_with_gpu
as
mode
from
theano.gpuarray.type
import
gpuarray_shared_constructor
seed
=
12345
n_substreams
=
7
curr_rstate
=
np
.
array
([
seed
]
*
6
,
dtype
=
'int32'
)
rstate
=
[
curr_rstate
.
copy
()]
for
j
in
range
(
1
,
n_substreams
):
rstate
.
append
(
rng_mrg
.
ff_2p72
(
rstate
[
-
1
]))
rstate
=
np
.
asarray
(
rstate
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
fct
=
functools
.
partial
(
rng_mrg
.
GPUA_mrg_uniform
.
new
,
rstate
,
ndim
=
None
,
dtype
=
'float32'
)
# should raise error as the size overflows
sizes
=
[(
2
**
31
,
),
(
2
**
32
,
),
(
2
**
15
,
2
**
16
,),
(
2
,
2
**
15
,
2
**
15
)]
rng_mrg_overflow
(
sizes
,
fct
,
mode
,
should_raise_error
=
True
)
# should not raise error
sizes
=
[(
2
**
5
,
),
(
2
**
5
,
2
**
5
),
(
2
**
5
,
2
**
5
,
2
**
5
)]
rng_mrg_overflow
(
sizes
,
fct
,
mode
,
should_raise_error
=
False
)
# should support int32 sizes
sizes
=
[(
np
.
int32
(
2
**
10
),
),
(
np
.
int32
(
2
),
np
.
int32
(
2
**
10
),
np
.
int32
(
2
**
10
))]
rng_mrg_overflow
(
sizes
,
fct
,
mode
,
should_raise_error
=
False
)
def
test_validate_input_types_gpuarray_backend
():
from
theano.sandbox.rng_mrg
import
mrg_uniform
from
theano.gpuarray.type
import
gpuarray_shared_constructor
from
theano.configparser
import
change_flags
with
change_flags
(
compute_test_value
=
"raise"
):
rstate
=
np
.
zeros
((
7
,
6
),
dtype
=
"int32"
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
"float32"
,
size
=
(
3
,))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
rng
=
MRG_RandomStreams
(
np
.
random
.
randint
(
2147462579
))
rng
=
MRG_RandomStreams
(
np
.
random
.
randint
(
2147462579
))
print
(
theano
.
__file__
)
print
(
theano
.
__file__
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论