Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a4e182df
提交
a4e182df
authored
5月 27, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2970 from carriepl/scan_memory_usage
[Bug] Revert dot22->gemm optimization back to dot22->dot22scalar
上级
fee78d8c
9080a7ad
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
25 行增加
和
31 行删除
+25
-31
opt.py
theano/sandbox/cuda/opt.py
+0
-2
blas.py
theano/tensor/blas.py
+13
-14
test_blas.py
theano/tensor/tests/test_blas.py
+12
-15
没有找到文件。
theano/sandbox/cuda/opt.py
浏览文件 @
a4e182df
...
@@ -570,8 +570,6 @@ def local_gpu_dot22(node):
...
@@ -570,8 +570,6 @@ def local_gpu_dot22(node):
@local_optimizer
([
gpu_from_host
,
tensor
.
blas
.
Dot22Scalar
])
@local_optimizer
([
gpu_from_host
,
tensor
.
blas
.
Dot22Scalar
])
def
local_gpu_dot22scalar
(
node
):
def
local_gpu_dot22scalar
(
node
):
"""
"""
Deprecated : _dot22scalar has been replace by gemm
see Dot22scalar for more details
gpu_from_host(dot22scalar) -> gpudot(gpu_from_host)
gpu_from_host(dot22scalar) -> gpudot(gpu_from_host)
dot(host_from_gpu) -> host_from_gpu(gpudot22scalar)
dot(host_from_gpu) -> host_from_gpu(gpudot22scalar)
...
...
theano/tensor/blas.py
浏览文件 @
a4e182df
...
@@ -1984,6 +1984,13 @@ _dot22scalar = Dot22Scalar()
...
@@ -1984,6 +1984,13 @@ _dot22scalar = Dot22Scalar()
@local_optimizer
([
T
.
mul
])
@local_optimizer
([
T
.
mul
])
def
local_dot22_to_dot22scalar
(
node
):
def
local_dot22_to_dot22scalar
(
node
):
"""
"""
:note: Previous attempts to alter this optimization to replace dot22 with
gemm instead of dot22scalar resulted in some Scan nodes being
duplicated and the ScanSaveMem optimization never running on them,
resulting in highly increased memory usage. Until this issue is
resolved, this optimization should keep using dot22scalar instead of
gemm.
:note: we upcast the scalar if after the multiplication with the
:note: we upcast the scalar if after the multiplication with the
dot this give the same type.
dot this give the same type.
...
@@ -2043,12 +2050,8 @@ def local_dot22_to_dot22scalar(node):
...
@@ -2043,12 +2050,8 @@ def local_dot22_to_dot22scalar(node):
a
=
T
.
cast
(
_as_scalar
(
m
.
owner
.
inputs
[
scalar_idx
],
a
=
T
.
cast
(
_as_scalar
(
m
.
owner
.
inputs
[
scalar_idx
],
dtype
=
d
.
dtype
),
d
.
type
.
dtype
)
dtype
=
d
.
dtype
),
d
.
type
.
dtype
)
assert
not
a
.
type
.
ndim
assert
not
a
.
type
.
ndim
dot
=
_dot22scalar
(
d
.
owner
.
inputs
[
0
],
d
.
owner
.
inputs
[
1
],
a
)
z
=
T
.
AllocEmpty
(
d
.
owner
.
inputs
[
0
]
.
dtype
)(
d
.
owner
.
inputs
[
0
]
.
shape
[
0
],
d
.
owner
.
inputs
[
1
]
.
shape
[
1
])
zero
=
T
.
as_tensor_variable
(
numpy
.
asarray
(
0
,
dtype
=
a
.
dtype
))
dot
=
gemm
(
z
,
a
,
d
.
owner
.
inputs
[
0
],
d
.
owner
.
inputs
[
1
],
zero
)
# The other inputs to the original node that were
# The other inputs to the original node that were
# neither part of the dot22 or this mul should be
# neither part of the dot22 or this mul should be
# factors in the returned "mul" node.
# factors in the returned "mul" node.
...
@@ -2083,16 +2086,12 @@ def local_dot22_to_dot22scalar(node):
...
@@ -2083,16 +2086,12 @@ def local_dot22_to_dot22scalar(node):
a
=
T
.
cast
(
i_scalar
[
scalar_idx
],
d
.
type
.
dtype
)
a
=
T
.
cast
(
i_scalar
[
scalar_idx
],
d
.
type
.
dtype
)
assert
not
a
.
type
.
ndim
assert
not
a
.
type
.
ndim
if
len
(
o
)
==
0
:
if
len
(
o
)
==
0
:
z
=
T
.
AllocEmpty
(
d
.
owner
.
inputs
[
0
]
.
dtype
)(
d
.
owner
.
inputs
[
0
]
.
shape
[
0
],
return
[
_dot22scalar
(
d
.
owner
.
inputs
[
0
],
d
.
owner
.
inputs
[
1
],
a
)]
d
.
owner
.
inputs
[
1
]
.
shape
[
1
])
zero
=
T
.
as_tensor_variable
(
numpy
.
asarray
(
0
,
dtype
=
a
.
dtype
))
return
[
gemm
(
z
,
a
,
d
.
owner
.
inputs
[
0
],
d
.
owner
.
inputs
[
1
],
zero
)]
else
:
else
:
z
=
T
.
AllocEmpty
(
d
.
owner
.
inputs
[
0
]
.
dtype
)(
d
.
owner
.
inputs
[
0
]
.
shape
[
0
],
return
[
T
.
mul
(
_dot22scalar
(
d
.
owner
.
inputs
[
0
],
d
.
owner
.
inputs
[
1
]
.
shape
[
1
])
d
.
owner
.
inputs
[
1
],
a
),
*
o
)]
zero
=
T
.
as_tensor_variable
(
numpy
.
asarray
(
0
,
dtype
=
a
.
dtype
))
return
[
T
.
mul
(
gemm
(
z
,
a
,
d
.
owner
.
inputs
[
0
],
d
.
owner
.
inputs
[
1
],
zero
),
*
o
)]
# must happen after gemm as the gemm optimizer don't understant
# must happen after gemm as the gemm optimizer don't understant
# dot22scalar and gemm give more speed up then dot22scalar
# dot22scalar and gemm give more speed up then dot22scalar
blas_optdb
.
register
(
'local_dot22_to_dot22scalar'
,
blas_optdb
.
register
(
'local_dot22_to_dot22scalar'
,
...
...
theano/tensor/tests/test_blas.py
浏览文件 @
a4e182df
...
@@ -875,7 +875,7 @@ def test_dot22scalar():
...
@@ -875,7 +875,7 @@ def test_dot22scalar():
cst
=
theano
.
tensor
.
basic
.
constant
(
.
2
,
dtype
=
dtype4
)
cst
=
theano
.
tensor
.
basic
.
constant
(
.
2
,
dtype
=
dtype4
)
cst2
=
theano
.
tensor
.
basic
.
constant
(
.
1
,
dtype
=
dtype4
)
cst2
=
theano
.
tensor
.
basic
.
constant
(
.
1
,
dtype
=
dtype4
)
def
check_dot22scalar
_gemm
(
func
,
len_topo_scalar
=-
1
):
def
check_dot22scalar
(
func
,
len_topo_scalar
=-
1
):
topo
=
func
.
maker
.
fgraph
.
toposort
()
topo
=
func
.
maker
.
fgraph
.
toposort
()
ops
=
[
x
.
op
for
x
in
topo
]
ops
=
[
x
.
op
for
x
in
topo
]
classes
=
[
type
(
x
.
op
)
for
x
in
topo
]
classes
=
[
type
(
x
.
op
)
for
x
in
topo
]
...
@@ -885,22 +885,20 @@ def test_dot22scalar():
...
@@ -885,22 +885,20 @@ def test_dot22scalar():
if
dtype1
==
dtype2
==
dtype3
==
dtype4_upcast
:
if
dtype1
==
dtype2
==
dtype3
==
dtype4_upcast
:
if
len_topo_scalar
>
0
:
if
len_topo_scalar
>
0
:
assert
len
(
topo
)
==
len_topo_scalar
assert
len
(
topo
)
==
len_topo_scalar
assert
gemm_inplace
in
ops
,
(
dtype1
,
dtype2
,
assert
_dot22scalar
in
ops
,
(
dtype1
,
dtype2
,
dtype3
,
dtype4
)
dtype3
,
dtype4
)
elif
dtype1
==
dtype2
==
dtype4_upcast
:
elif
dtype1
==
dtype2
==
dtype4_upcast
:
if
not
(
len_topo_scalar
>
0
):
if
not
(
len_topo_scalar
>
0
):
assert
len
(
topo
)
==
len_topo_scalar
assert
len
(
topo
)
==
len_topo_scalar
assert
gemm_inplace
in
ops
,
(
dtype1
,
dtype2
,
assert
_dot22scalar
in
ops
,
(
dtype1
,
dtype2
,
dtype3
,
dtype4
)
dtype3
,
dtype4
)
assert
not
T
.
Elemwise
in
classes
,
(
dtype1
,
dtype2
,
dtype3
,
dtype4
)
else
:
else
:
# Currently there is a problem of
# Currently there is a problem of
# optimization order The constant get
# optimization order The constant get
# upcasted to float64 before we try to
# upcasted to float64 before we try to
# merge it with the dot22 of
# merge it with the dot22 of
# float32. So this prevent the merge.
# float32. So this prevent the merge.
assert
gemm_inplace
in
ops
or
_dot22
in
ops
,
(
assert
_dot22scalar
in
ops
or
_dot22
in
ops
,
(
dtype1
,
dtype2
,
dtype3
,
dtype4
)
dtype1
,
dtype2
,
dtype3
,
dtype4
)
elif
dtype1
==
dtype2
:
elif
dtype1
==
dtype2
:
...
@@ -920,7 +918,7 @@ def test_dot22scalar():
...
@@ -920,7 +918,7 @@ def test_dot22scalar():
f
=
theano
.
function
([
a
,
b
],
cst
*
T
.
dot
(
a
,
b
),
f
=
theano
.
function
([
a
,
b
],
cst
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
mode
=
mode_blas_opt
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
check_dot22scalar
_gemm
(
f
,
1
)
check_dot22scalar
(
f
,
1
)
f
(
av
,
bv
)
f
(
av
,
bv
)
...
@@ -929,8 +927,7 @@ def test_dot22scalar():
...
@@ -929,8 +927,7 @@ def test_dot22scalar():
cst
*
c
*
T
.
dot
(
a
,
b
),
cst
*
c
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
mode
=
mode_blas_opt
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
check_dot22scalar_gemm
(
f
,
5
)
check_dot22scalar
(
f
,
2
)
#print (av.dtype, bv.dtype, cv.dtype)
f
(
av
,
bv
,
cv
)
f
(
av
,
bv
,
cv
)
...
@@ -938,7 +935,7 @@ def test_dot22scalar():
...
@@ -938,7 +935,7 @@ def test_dot22scalar():
c
*
cst
*
T
.
dot
(
a
,
b
),
c
*
cst
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
mode
=
mode_blas_opt
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
check_dot22scalar
_gemm
(
f
,
5
)
check_dot22scalar
(
f
,
2
)
f
(
av
,
bv
,
cv
)
f
(
av
,
bv
,
cv
)
# Here, canonicalize also seems needed
# Here, canonicalize also seems needed
...
@@ -948,7 +945,7 @@ def test_dot22scalar():
...
@@ -948,7 +945,7 @@ def test_dot22scalar():
cst2
*
c
*
cst
*
T
.
dot
(
a
,
b
),
cst2
*
c
*
cst
*
T
.
dot
(
a
,
b
),
mode
=
m2
)
mode
=
m2
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
check_dot22scalar
_gemm
(
f
,
5
)
check_dot22scalar
(
f
,
2
)
f
(
av
,
bv
,
cv
)
f
(
av
,
bv
,
cv
)
if
dtype1
==
dtype2
==
dtype3
:
if
dtype1
==
dtype2
==
dtype3
:
...
@@ -956,7 +953,7 @@ def test_dot22scalar():
...
@@ -956,7 +953,7 @@ def test_dot22scalar():
c
*
cst
*
a
*
T
.
dot
(
a
,
b
),
c
*
cst
*
a
*
T
.
dot
(
a
,
b
),
mode
=
m2
)
mode
=
m2
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
check_dot22scalar
_gemm
(
f
,
5
)
check_dot22scalar
(
f
,
2
)
f
(
sv
,
sv
,
sv
)
f
(
sv
,
sv
,
sv
)
f
=
theano
.
function
([
a
,
b
,
c
],
f
=
theano
.
function
([
a
,
b
,
c
],
...
@@ -979,7 +976,7 @@ def test_dot22scalar():
...
@@ -979,7 +976,7 @@ def test_dot22scalar():
c
*
a
*
cst
*
T
.
dot
(
a
,
b
),
c
*
a
*
cst
*
T
.
dot
(
a
,
b
),
mode
=
m2
)
mode
=
m2
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
check_dot22scalar
_gemm
(
f
,
5
)
check_dot22scalar
(
f
,
2
)
f
(
sv
,
sv
,
sv
)
f
(
sv
,
sv
,
sv
)
cmp
((
3
,
4
),
(
4
,
5
),
(
3
,
5
))
cmp
((
3
,
4
),
(
4
,
5
),
(
3
,
5
))
...
@@ -999,7 +996,7 @@ def test_dot22scalar_cast():
...
@@ -999,7 +996,7 @@ def test_dot22scalar_cast():
for
scalar_int_type
in
T
.
int_dtypes
:
for
scalar_int_type
in
T
.
int_dtypes
:
y
=
T
.
scalar
(
dtype
=
scalar_int_type
)
y
=
T
.
scalar
(
dtype
=
scalar_int_type
)
f
=
theano
.
function
([
A
,
y
],
T
.
dot
(
A
,
A
)
*
y
,
mode
=
mode_blas_opt
)
f
=
theano
.
function
([
A
,
y
],
T
.
dot
(
A
,
A
)
*
y
,
mode
=
mode_blas_opt
)
assert
gemm_inplace
in
[
x
.
op
for
x
in
f
.
maker
.
fgraph
.
toposort
()]
assert
_dot22scalar
in
[
x
.
op
for
x
in
f
.
maker
.
fgraph
.
toposort
()]
A
=
T
.
fmatrix
()
A
=
T
.
fmatrix
()
for
scalar_int_type
in
T
.
int_dtypes
:
for
scalar_int_type
in
T
.
int_dtypes
:
y
=
T
.
scalar
(
dtype
=
scalar_int_type
)
y
=
T
.
scalar
(
dtype
=
scalar_int_type
)
...
@@ -1007,7 +1004,7 @@ def test_dot22scalar_cast():
...
@@ -1007,7 +1004,7 @@ def test_dot22scalar_cast():
if
scalar_int_type
in
[
'int32'
,
'int64'
]:
if
scalar_int_type
in
[
'int32'
,
'int64'
]:
assert
_dot22
in
[
x
.
op
for
x
in
f
.
maker
.
fgraph
.
toposort
()]
assert
_dot22
in
[
x
.
op
for
x
in
f
.
maker
.
fgraph
.
toposort
()]
else
:
else
:
assert
gemm_inplace
in
[
x
.
op
for
x
in
f
.
maker
.
fgraph
.
toposort
()]
assert
_dot22scalar
in
[
x
.
op
for
x
in
f
.
maker
.
fgraph
.
toposort
()]
def
test_local_dot22_to_dot22scalar
():
def
test_local_dot22_to_dot22scalar
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论