Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
db2bd471
提交
db2bd471
authored
7月 11, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #754 from jaberg/ipam2012
Misc for IPAM GSS 2012
上级
44e57b3c
adb7ffd3
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
99 行增加
和
11 行删除
+99
-11
rng_mrg.py
theano/sandbox/rng_mrg.py
+12
-4
basic.py
theano/scalar/basic.py
+4
-4
blas.py
theano/tensor/blas.py
+1
-1
elemwise.py
theano/tensor/elemwise.py
+3
-2
opt.py
theano/tensor/opt.py
+33
-0
test_opt.py
theano/tensor/tests/test_opt.py
+46
-0
没有找到文件。
theano/sandbox/rng_mrg.py
浏览文件 @
db2bd471
...
...
@@ -605,7 +605,7 @@ def guess_n_streams(size, warn=True):
Return a guess at a good number of streams.
:param warn: If True, warn when a guess cannot be made (in which case
we return
3
0 * 256).
we return
6
0 * 256).
"""
# TODO: a smart way of choosing the number of streams, see #612.
# Note that this code was moved out of `MRG_RandomStreams` so that it can
...
...
@@ -618,14 +618,22 @@ def guess_n_streams(size, warn=True):
r
*=
s
if
r
>
6
:
r
=
r
/
6
# chosen as fastest for rbm_benchmark
return
r
# The purpose of sampling from many streams is to be able to use
# the GPU to its full capacity. It just wastes RAM and stream-initialization time to
# allocate more streams than necessary for the GPU.
# XXX: This number is chosen to be good for 280 and 480 architectures,
# Better would be to use pycuda to query the number of
# processors on the GPU device,
# rather than guessing 60.
return
min
(
r
,
60
*
256
)
else
:
if
warn
:
warnings
.
warn
((
"MRG_RandomStreams Can't determine #streams from "
"size (
%
s), guessing
3
0*256"
)
%
str
(
size
),
"size (
%
s), guessing
6
0*256"
)
%
str
(
size
),
stacklevel
=
3
)
return
3
0
*
256
return
6
0
*
256
class
MRG_RandomStreams
(
object
):
...
...
theano/scalar/basic.py
浏览文件 @
db2bd471
...
...
@@ -1085,9 +1085,9 @@ class Maximum(BinaryScalarOp):
# max is not defined for complex_types
gx
,
gy
=
None
,
None
if
x
.
type
in
float_types
:
gx
=
eq
(
maximum
(
x
,
y
),
x
)
*
gz
gx
=
cast
(
eq
(
maximum
(
x
,
y
),
x
)
*
gz
,
x
.
type
.
dtype
)
if
y
.
type
in
float_types
:
gy
=
eq
(
maximum
(
x
,
y
),
y
)
*
gz
gy
=
cast
(
eq
(
maximum
(
x
,
y
),
y
)
*
gz
,
y
.
type
.
dtype
)
return
(
gx
,
gy
)
maximum
=
Maximum
(
upcast_out
,
name
=
'maximum'
)
...
...
@@ -1110,9 +1110,9 @@ class Minimum(BinaryScalarOp):
# max is not defined for complex_types
gx
,
gy
=
None
,
None
if
x
.
type
in
float_types
:
gx
=
eq
(
minimum
(
x
,
y
),
x
)
*
gz
gx
=
cast
(
eq
(
minimum
(
x
,
y
),
x
)
*
gz
,
x
.
type
.
dtype
)
if
y
.
type
in
float_types
:
gy
=
eq
(
minimum
(
x
,
y
),
y
)
*
gz
gy
=
cast
(
eq
(
minimum
(
x
,
y
),
y
)
*
gz
,
y
.
type
.
dtype
)
return
(
gx
,
gy
)
minimum
=
Minimum
(
upcast_out
,
name
=
'minimum'
)
...
...
theano/tensor/blas.py
浏览文件 @
db2bd471
...
...
@@ -375,7 +375,7 @@ def default_blas_ldflags():
# options part.
[
'-L
%
s'
%
l
for
l
in
blas_info
[
'library_dirs'
]]
+
[
'-l
%
s'
%
l
for
l
in
blas_info
[
'libraries'
]]
+
extra
)
[]
)
# ['-I%s' % l for l in blas_info['include_dirs']])
except
KeyError
:
return
"-lblas"
...
...
theano/tensor/elemwise.py
浏览文件 @
db2bd471
...
...
@@ -1594,8 +1594,9 @@ class Sum(CAReduceDtype):
else
:
new_dims
.
append
(
i
)
i
+=
1
return
Elemwise
(
scalar
.
second
)(
x
,
DimShuffle
(
gz
.
type
.
broadcastable
,
new_dims
)(
gz
)),
ds_op
=
DimShuffle
(
gz
.
type
.
broadcastable
,
new_dims
)
gx
=
Elemwise
(
scalar
.
second
)(
x
,
ds_op
(
gz
)
.
astype
(
x
.
dtype
))
return
[
gx
]
def
R_op
(
self
,
inputs
,
eval_points
):
# There is just one element in inputs and eval_points, the axis are
...
...
theano/tensor/opt.py
浏览文件 @
db2bd471
...
...
@@ -3136,6 +3136,39 @@ def local_cut_useless_reduce(node):
return
[
summed
]
@register_canonicalize
@gof.local_optimizer
([])
def
local_sum_broadcastable
(
node
):
"""Remove reduction over broadcastable dimensions"""
if
isinstance
(
node
.
op
,
T
.
CAReduce
):
reduced
,
=
node
.
inputs
odtype
=
node
.
outputs
[
0
]
.
dtype
if
node
.
op
.
axis
is
None
:
if
all
(
reduced
.
broadcastable
):
return
[
reduced
.
dimshuffle
()
.
astype
(
odtype
)]
else
:
axis
=
list
(
node
.
op
.
axis
)
cuttable
=
[
a
for
a
in
axis
if
reduced
.
broadcastable
[
a
]]
if
cuttable
:
# -- we can remove some axes of summation,
# which simplifies the codegen for sum, especially on GPU
new_axis
=
[]
pattern
=
[]
ii
=
0
for
p
in
range
(
reduced
.
ndim
):
if
p
not
in
cuttable
:
if
p
in
axis
:
new_axis
.
append
(
ii
)
pattern
.
append
(
p
)
ii
+=
1
new_reduced
=
reduced
.
dimshuffle
(
*
pattern
)
if
new_axis
:
new_op
=
node
.
op
.
__class__
(
axis
=
new_axis
)
return
[
new_op
(
new_reduced
)]
else
:
# -- in this case we can remove the reduction completely
return
[
new_reduced
.
astype
(
odtype
)]
@register_specialize
@gof.local_optimizer
([])
def
local_sum_alloc
(
node
):
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
db2bd471
...
...
@@ -46,6 +46,7 @@ from theano.tensor import (
)
from
theano.tensor.elemwise
import
DimShuffle
from
theano.tests
import
unittest_tools
as
utt
from
theano.compile.mode
import
optdb
mode_opt
=
theano
.
config
.
mode
if
mode_opt
==
'FAST_COMPILE'
:
...
...
@@ -3288,6 +3289,51 @@ class T_local_sum(unittest.TestCase):
finally
:
config
.
on_opt_error
=
backup
def
test_local_sum_broadcast_all_0
(
self
):
optimizer
=
optdb
.
query
(
self
.
mode
.
_optimizer
)
x
=
T
.
TensorType
(
'int64'
,
(
True
,
True
,
True
))()
env
=
Env
([
x
],
[
x
.
sum
()])
optimizer
.
optimize
(
env
)
assert
not
any
([
isinstance
(
node
.
op
,
T
.
CAReduce
)
for
node
in
env
.
toposort
()])
def
test_local_sum_broadcast_all_1
(
self
):
optimizer
=
optdb
.
query
(
self
.
mode
.
_optimizer
)
x
=
T
.
TensorType
(
'int64'
,
(
True
,
True
))()
env
=
Env
([
x
],
[
x
.
sum
(
axis
=
[
0
,
1
])])
optimizer
.
optimize
(
env
)
assert
not
any
([
isinstance
(
node
.
op
,
T
.
CAReduce
)
for
node
in
env
.
toposort
()])
def
test_local_sum_broadcast_some_0
(
self
):
optimizer
=
optdb
.
query
(
self
.
mode
.
_optimizer
)
x
=
T
.
TensorType
(
'int64'
,
(
True
,
False
,
True
))()
env
=
Env
([
x
],
[
x
.
sum
(
axis
=
[
0
,
1
])])
optimizer
.
optimize
(
env
)
order
=
env
.
toposort
()
assert
1
==
sum
([
isinstance
(
node
.
op
,
T
.
CAReduce
)
for
node
in
order
])
op
=
order
[
-
2
]
.
op
assert
isinstance
(
op
,
T
.
CAReduce
)
# -- the leading broadcastable dimension has been dropped
# by the local_sum_broadcastable optimization
# now summation is over the original x's dimension 1.
assert
order
[
-
2
]
.
inputs
[
0
]
.
ndim
==
2
,
order
[
-
2
]
assert
op
.
axis
==
(
0
,),
op
.
axis
def
test_local_sum_broadcast_some_1
(
self
):
optimizer
=
optdb
.
query
(
self
.
mode
.
_optimizer
)
x
=
T
.
TensorType
(
'int64'
,
(
True
,
False
,
True
))()
env
=
Env
([
x
],
[
x
.
sum
(
axis
=
[
0
,
2
])])
optimizer
.
optimize
(
env
)
order
=
env
.
toposort
()
assert
0
==
sum
([
isinstance
(
node
.
op
,
T
.
CAReduce
)
for
node
in
order
])
class
T_local_sum_dimshuffle
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论