Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
337609b2
提交
337609b2
authored
1月 26, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
manual merge
上级
cfd94c87
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
40 行增加
和
14 行删除
+40
-14
opt.py
theano/sandbox/cuda/opt.py
+12
-0
rng_mrg.py
theano/sandbox/rng_mrg.py
+28
-14
没有找到文件。
theano/sandbox/cuda/opt.py
浏览文件 @
337609b2
...
@@ -604,6 +604,13 @@ def local_gpu_conv(node):
...
@@ -604,6 +604,13 @@ def local_gpu_conv(node):
logical_img_hw
=
None
logical_img_hw
=
None
if
op
.
imshp_logical
is
not
None
:
if
op
.
imshp_logical
is
not
None
:
logical_img_hw
=
op
.
imshp_logical
[
1
:
3
]
logical_img_hw
=
op
.
imshp_logical
[
1
:
3
]
if
logical_img_hw
!=
op
.
imshp
[
1
:
3
]:
# this case is not implemented
return
None
if
op
.
kshp_logical
is
not
None
and
op
.
kshp_logical
!=
op
.
kshp
:
return
None
#print op.kshp, op.imshp[1:3]
#print op.kshp_logical, logical_img_hw
ret
=
GpuConv
(
border_mode
=
op
.
out_mode
,
ret
=
GpuConv
(
border_mode
=
op
.
out_mode
,
subsample
=
(
op
.
dx
,
op
.
dy
),
subsample
=
(
op
.
dx
,
op
.
dy
),
logical_img_hw
=
logical_img_hw
,
logical_img_hw
=
logical_img_hw
,
...
@@ -619,11 +626,14 @@ def local_gpu_conv(node):
...
@@ -619,11 +626,14 @@ def local_gpu_conv(node):
ret
.
flops
=
op
.
flops
ret
.
flops
=
op
.
flops
return
ret
return
ret
if
node
.
op
==
gpu_from_host
:
if
node
.
op
==
gpu_from_host
:
#gpu_from_host(conv) -> gpu_conv(gpu_from_host)
#gpu_from_host(conv) -> gpu_conv(gpu_from_host)
host_input
=
node
.
inputs
[
0
]
host_input
=
node
.
inputs
[
0
]
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
conv
.
ConvOp
):
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
conv
.
ConvOp
):
gpu_conv
=
GpuConvOp_from_ConvOp
(
host_input
.
owner
.
op
)
gpu_conv
=
GpuConvOp_from_ConvOp
(
host_input
.
owner
.
op
)
if
gpu_conv
is
None
:
return
img
,
kern
=
host_input
.
owner
.
inputs
img
,
kern
=
host_input
.
owner
.
inputs
#in some case the ConvOp broadcast the last 2 dimensions differently then the gpu ConvOp
#in some case the ConvOp broadcast the last 2 dimensions differently then the gpu ConvOp
return
[
tensor
.
patternbroadcast
(
gpu_conv
(
gpu_from_host
(
img
),
gpu_from_host
(
kern
)),
return
[
tensor
.
patternbroadcast
(
gpu_conv
(
gpu_from_host
(
img
),
gpu_from_host
(
kern
)),
...
@@ -636,6 +646,8 @@ def local_gpu_conv(node):
...
@@ -636,6 +646,8 @@ def local_gpu_conv(node):
kern_on_gpu
=
(
kern
.
owner
and
kern
.
owner
.
op
==
host_from_gpu
)
kern_on_gpu
=
(
kern
.
owner
and
kern
.
owner
.
op
==
host_from_gpu
)
if
img_on_gpu
or
kern_on_gpu
:
if
img_on_gpu
or
kern_on_gpu
:
gpu_conv
=
GpuConvOp_from_ConvOp
(
node
.
op
)
gpu_conv
=
GpuConvOp_from_ConvOp
(
node
.
op
)
if
gpu_conv
is
None
:
return
#in some case the ConvOp broadcast the last 2 dimensions differently then the gpu ConvOp
#in some case the ConvOp broadcast the last 2 dimensions differently then the gpu ConvOp
return
[
tensor
.
patternbroadcast
(
host_from_gpu
(
gpu_conv
(
gpu_from_host
(
img
),
return
[
tensor
.
patternbroadcast
(
host_from_gpu
(
gpu_conv
(
gpu_from_host
(
img
),
gpu_from_host
(
kern
))),
gpu_from_host
(
kern
))),
...
...
theano/sandbox/rng_mrg.py
浏览文件 @
337609b2
...
@@ -161,8 +161,6 @@ class mrg_uniform_base(Op):
...
@@ -161,8 +161,6 @@ class mrg_uniform_base(Op):
def
grad
(
self
,
inputs
,
ograd
):
def
grad
(
self
,
inputs
,
ograd
):
return
[
None
for
i
in
inputs
]
return
[
None
for
i
in
inputs
]
def
c_code_cache_version
(
self
):
return
(
2
,)
class
mrg_uniform
(
mrg_uniform_base
):
class
mrg_uniform
(
mrg_uniform_base
):
#CPU VERSION
#CPU VERSION
...
@@ -354,6 +352,8 @@ class mrg_uniform(mrg_uniform_base):
...
@@ -354,6 +352,8 @@ class mrg_uniform(mrg_uniform_base):
}
}
//////// </ code generated by mrg_uniform>
//////// </ code generated by mrg_uniform>
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
class
GPU_mrg_uniform
(
mrg_uniform_base
):
class
GPU_mrg_uniform
(
mrg_uniform_base
):
#GPU VERSION
#GPU VERSION
...
@@ -564,6 +564,8 @@ class GPU_mrg_uniform(mrg_uniform_base):
...
@@ -564,6 +564,8 @@ class GPU_mrg_uniform(mrg_uniform_base):
//////// </ code generated by mrg_uniform>
//////// </ code generated by mrg_uniform>
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
3
,)
class
MRG_RandomStreams
(
object
):
class
MRG_RandomStreams
(
object
):
"""Module component with similar interface to numpy.random (numpy.random.RandomState)"""
"""Module component with similar interface to numpy.random (numpy.random.RandomState)"""
...
@@ -639,7 +641,8 @@ class MRG_RandomStreams(object):
...
@@ -639,7 +641,8 @@ class MRG_RandomStreams(object):
r
=
r
/
6
# chosen as fastest for rbm_benchmark
r
=
r
/
6
# chosen as fastest for rbm_benchmark
return
r
return
r
print
>>
sys
.
stderr
,
"MRG_RandomStreams Can't determine #streams from size (
%
s), guessing 30*256"
%
str
(
size
)
print
>>
sys
.
stderr
,
(
"MRG_RandomStreams Can't determine #streams from "
"size (
%
s), guessing 30*256"
)
%
str
(
size
)
return
30
*
256
return
30
*
256
def
pretty_return
(
self
,
node_rstate
,
new_rstate
,
sample
):
def
pretty_return
(
self
,
node_rstate
,
new_rstate
,
sample
):
...
@@ -658,12 +661,17 @@ class MRG_RandomStreams(object):
...
@@ -658,12 +661,17 @@ class MRG_RandomStreams(object):
ndim may be a plain integer to supplement the missing
ndim may be a plain integer to supplement the missing
information.
information.
:param: size: Can be a list of integer or Theano variable(ex: the shape of other Theano Variable)
:param: size: Can be a list of integer or Theano variable
(ex: the shape of other Theano Variable)
TODO: can size be None?
TODO: can size be None?
"""
"""
if
isinstance
(
size
,
tuple
):
if
isinstance
(
size
,
tuple
):
assert
all
([
isinstance
(
i
,
int
)
or
isinstance
(
i
,
Variable
)
for
i
in
size
]),
"size must be a tuple of int or a Theano variable"
msg
=
"size must be a tuple of int or a Theano variable"
else
:
assert
isinstance
(
size
,
Variable
)
and
size
.
ndim
==
1
,
"size must be a tuple of int or a Theano variable"
assert
all
([
isinstance
(
i
,
int
)
or
isinstance
(
i
,
Variable
)
for
i
in
size
]),
msg
else
:
msg
=
"size must be a tuple of int or a Theano variable"
assert
isinstance
(
size
,
Variable
)
and
size
.
ndim
==
1
,
msg
if
nstreams
is
None
:
if
nstreams
is
None
:
nstreams
=
self
.
n_streams
(
size
)
nstreams
=
self
.
n_streams
(
size
)
...
@@ -677,12 +685,15 @@ class MRG_RandomStreams(object):
...
@@ -677,12 +685,15 @@ class MRG_RandomStreams(object):
tmp_float_buf
=
numpy
.
frombuffer
(
rstates
.
data
,
dtype
=
'float32'
)
tmp_float_buf
=
numpy
.
frombuffer
(
rstates
.
data
,
dtype
=
'float32'
)
assert
tmp_float_buf
.
shape
==
rstates
.
shape
assert
tmp_float_buf
.
shape
==
rstates
.
shape
assert
tmp_float_buf
.
data
[:
24
]
==
rstates
.
data
[:
24
]
assert
tmp_float_buf
.
data
[:
24
]
==
rstates
.
data
[:
24
]
node_rstate
=
float32_shared_constructor
(
tmp_float_buf
)
# transfer to device
# transfer to device
node_rstate
=
float32_shared_constructor
(
tmp_float_buf
)
assert
isinstance
(
node_rstate
.
type
,
CudaNdarrayType
)
assert
isinstance
(
node_rstate
.
type
,
CudaNdarrayType
)
# we can't use the normal mrg_uniform constructor + later optimization
# we can't use the normal mrg_uniform constructor + later
# optimization
# because of the tmp_float_buf hack above. There is
# because of the tmp_float_buf hack above. There is
# currently no Theano node that will do a frombuffer reinterpretation.
# currently no Theano node that will do a frombuffer
# reinterpretation.
u
=
self
.
pretty_return
(
node_rstate
,
u
=
self
.
pretty_return
(
node_rstate
,
*
GPU_mrg_uniform
.
new
(
node_rstate
,
ndim
,
dtype
,
size
))
*
GPU_mrg_uniform
.
new
(
node_rstate
,
ndim
,
dtype
,
size
))
else
:
else
:
...
@@ -706,13 +717,15 @@ class MRG_RandomStreams(object):
...
@@ -706,13 +717,15 @@ class MRG_RandomStreams(object):
def
multinomial
(
self
,
size
=
None
,
n
=
1
,
pvals
=
None
,
ndim
=
None
,
dtype
=
'int64'
):
def
multinomial
(
self
,
size
=
None
,
n
=
1
,
pvals
=
None
,
ndim
=
None
,
dtype
=
'int64'
):
"""
"""
Sample `n` (currently `n` needs to be 1) times from a multinomial
distribution defined by
Sample `n` (currently `n` needs to be 1) times from a multinomial
probabilities pvals.
distribution defined by
probabilities pvals.
Example : pvals = [[.98,.01, .01], [.01, .98 .01]] will probably result in [[1,0,0],[0,1,0]].
Example : pvals = [[.98,.01, .01], [.01, .98 .01]] will probably result
in [[1,0,0],[0,1,0]].
.. note::
.. note::
`size` and `ndim` are only there keep the same signature as other uniform, binomial, normal, etc.
`size` and `ndim` are only there keep the same signature as other
uniform, binomial, normal, etc.
todo : adapt multinomial to take that into account
todo : adapt multinomial to take that into account
"""
"""
if
pvals
is
None
:
if
pvals
is
None
:
...
@@ -743,7 +756,8 @@ class MRG_RandomStreams(object):
...
@@ -743,7 +756,8 @@ class MRG_RandomStreams(object):
n_samples
+=
1
n_samples
+=
1
evened
=
True
evened
=
True
else
:
else
:
n_samples
=
prod
(
size
)
+
(
prod
(
size
)
%
2
)
#if even, don't change, if odd, +1
#if even, don't change, if odd, +1
n_samples
=
prod
(
size
)
+
(
prod
(
size
)
%
2
)
flattened
=
self
.
uniform
(
size
=
(
n_samples
,),
dtype
=
dtype
)
flattened
=
self
.
uniform
(
size
=
(
n_samples
,),
dtype
=
dtype
)
if
constant
:
if
constant
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论