Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
56eb0c95
提交
56eb0c95
authored
5月 03, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable memory profiling for sparse variable.
上级
0cbdf291
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
90 行增加
和
11 行删除
+90
-11
type.txt
doc/extending/type.txt
+32
-0
profiling.py
theano/compile/profiling.py
+2
-7
vm.py
theano/gof/vm.py
+13
-3
type.py
theano/sandbox/cuda/type.py
+3
-0
type.py
theano/sparse/type.py
+9
-0
basic.py
theano/tensor/basic.py
+28
-1
raw_random.py
theano/tensor/raw_random.py
+3
-0
没有找到文件。
doc/extending/type.txt
浏览文件 @
56eb0c95
...
@@ -106,6 +106,38 @@ default values.
...
@@ -106,6 +106,38 @@ default values.
*Default:* ``id(self)``
*Default:* ``id(self)``
.. method:: get_shape_info(obj)
Optional. Only needed to profile the memory of this Type of object
Return the information needed to compute the memory size of obj.
The memory size is only the data, so this exclude the container.
For an ndarray, this is the data, but not the ndarray object and
others data structures as shape and strides.
get_shape_info() and get_size() work in tendem for the memory profiler.
get_shape_info() is called during the execution of the function.
So it is better that it is not too slow.
get_size() will be called with the output of this function
when printing the memory profile.
:param obj: The object that this Type represent during execution
:return: Python object that self.get_size() understand
.. method:: get_size(shape_info)
Number of bytes taken by the object represented by shape_info
Optional. Only needed to profile the memory of this Type of object
:param shape_info: the output of the call to get_shape_info()
:return: the number of bytes taken by the object described in
shape_info.
"""
For each method, the *default* is what ``Type`` defines
For each method, the *default* is what ``Type`` defines
for you. So, if you create an instance of ``Type`` or an
for you. So, if you create an instance of ``Type`` or an
instance of a subclass of ``Type``, you
instance of a subclass of ``Type``, you
...
...
theano/compile/profiling.py
浏览文件 @
56eb0c95
...
@@ -601,9 +601,7 @@ class ProfileStats(object):
...
@@ -601,9 +601,7 @@ class ProfileStats(object):
sum_dense
=
0
sum_dense
=
0
for
out
in
node
.
outputs
:
for
out
in
node
.
outputs
:
sh
=
self
.
variable_shape
[
out
]
sh
=
self
.
variable_shape
[
out
]
if
isinstance
(
out
.
type
,
theano
.
sparse
.
SparseType
):
if
hasattr
(
out
.
type
,
'get_size'
):
v
=
"Sparse"
elif
hasattr
(
out
.
type
,
'get_size'
):
v
=
out
.
type
.
get_size
(
sh
)
v
=
out
.
type
.
get_size
(
sh
)
sum_dense
+=
v
sum_dense
+=
v
else
:
else
:
...
@@ -739,10 +737,7 @@ class ProfileStats(object):
...
@@ -739,10 +737,7 @@ class ProfileStats(object):
code
[
out
]
=
"v"
code
[
out
]
=
"v"
shapes
=
str
(
fct_shapes
[
node
.
fgraph
][
node
])
shapes
=
str
(
fct_shapes
[
node
.
fgraph
][
node
])
if
any
([
isinstance
(
out
.
type
,
theano
.
sparse
.
SparseType
)
if
all
([
hasattr
(
out
.
type
,
'get_size'
)
for
out
in
node
.
outputs
]):
size
=
"
%10
s"
%
"Sparse"
elif
all
([
hasattr
(
out
.
type
,
'get_size'
)
for
out
in
node
.
outputs
]):
for
out
in
node
.
outputs
]):
size
=
"
%9
dB"
%
node_outputs_size
size
=
"
%9
dB"
%
node_outputs_size
else
:
else
:
...
...
theano/gof/vm.py
浏览文件 @
56eb0c95
...
@@ -327,7 +327,10 @@ class Stack(VM):
...
@@ -327,7 +327,10 @@ class Stack(VM):
for
var
,
data
in
self
.
storage_map
.
iteritems
():
for
var
,
data
in
self
.
storage_map
.
iteritems
():
if
data
[
0
]
is
None
:
if
data
[
0
]
is
None
:
continue
continue
sh
=
getattr
(
data
[
0
],
'shape'
,
'input no shape'
)
if
hasattr
(
var
.
type
,
'get_shape_info'
):
sh
=
var
.
type
.
get_shape_info
(
data
[
0
])
else
:
sh
=
'input no shape'
self
.
variable_shape
[
var
]
=
sh
self
.
variable_shape
[
var
]
=
sh
st
=
getattr
(
data
[
0
],
'strides'
,
'input no strides'
)
st
=
getattr
(
data
[
0
],
'strides'
,
'input no strides'
)
if
getattr
(
data
[
0
],
'flags'
,
False
)
and
data
[
0
]
.
flags
.
c_contiguous
:
if
getattr
(
data
[
0
],
'flags'
,
False
)
and
data
[
0
]
.
flags
.
c_contiguous
:
...
@@ -383,7 +386,10 @@ class Stack(VM):
...
@@ -383,7 +386,10 @@ class Stack(VM):
thunks
[
self
.
node_idx
[
thunks
[
self
.
node_idx
[
current_apply
]]
.
outputs
):
current_apply
]]
.
outputs
):
var
=
self
.
nodes
[
current_idx
]
.
outputs
[
idx
]
var
=
self
.
nodes
[
current_idx
]
.
outputs
[
idx
]
sh
=
getattr
(
o
[
0
],
'shape'
,
'input no shape'
)
if
hasattr
(
var
.
type
,
'get_shape_info'
):
sh
=
var
.
type
.
get_shape_info
(
o
[
0
])
else
:
sh
=
'input no shape'
self
.
variable_shape
[
var
]
=
sh
self
.
variable_shape
[
var
]
=
sh
st
=
getattr
(
o
[
0
],
'strides'
,
st
=
getattr
(
o
[
0
],
'strides'
,
'input no strides'
)
'input no strides'
)
...
@@ -466,7 +472,11 @@ class Stack(VM):
...
@@ -466,7 +472,11 @@ class Stack(VM):
self
.
node_idx
[
current_apply
]]
.
outputs
):
self
.
node_idx
[
current_apply
]]
.
outputs
):
var
=
self
.
nodes
[
var
=
self
.
nodes
[
self
.
node_idx
[
current_apply
]]
.
outputs
[
idx
]
self
.
node_idx
[
current_apply
]]
.
outputs
[
idx
]
sh
=
getattr
(
o
[
0
],
'shape'
,
'input no shape'
)
if
hasattr
(
var
.
type
,
'get_shape_info'
):
sh
=
var
.
type
.
get_shape_info
(
o
[
0
])
else
:
sh
=
'input no shape'
self
.
variable_shape
[
var
]
=
sh
self
.
variable_shape
[
var
]
=
sh
st
=
getattr
(
o
[
0
],
'strides'
,
'input no strides'
)
st
=
getattr
(
o
[
0
],
'strides'
,
'input no strides'
)
if
(
getattr
(
o
[
0
],
'flags'
,
False
)
and
if
(
getattr
(
o
[
0
],
'flags'
,
False
)
and
...
...
theano/sandbox/cuda/type.py
浏览文件 @
56eb0c95
...
@@ -417,6 +417,9 @@ class CudaNdarrayType(Type):
...
@@ -417,6 +417,9 @@ class CudaNdarrayType(Type):
def
c_compile_args
(
self
):
def
c_compile_args
(
self
):
return
[]
return
[]
def
get_shape_info
(
self
,
obj
):
return
obj
.
shape
def
get_size
(
self
,
shape_info
):
def
get_size
(
self
,
shape_info
):
return
numpy
.
prod
(
shape_info
,
dtype
=
int
)
*
numpy
.
dtype
(
self
.
dtype
)
.
itemsize
return
numpy
.
prod
(
shape_info
,
dtype
=
int
)
*
numpy
.
dtype
(
self
.
dtype
)
.
itemsize
...
...
theano/sparse/type.py
浏览文件 @
56eb0c95
...
@@ -147,6 +147,15 @@ class SparseType(gof.Type):
...
@@ -147,6 +147,15 @@ class SparseType(gof.Type):
def
is_valid_value
(
self
,
a
):
def
is_valid_value
(
self
,
a
):
return
scipy
.
sparse
.
issparse
(
a
)
and
(
a
.
format
==
self
.
format
)
return
scipy
.
sparse
.
issparse
(
a
)
and
(
a
.
format
==
self
.
format
)
def
get_shape_info
(
self
,
obj
):
obj
=
self
.
filter
(
obj
)
return
(
obj
.
shape
,
obj
.
data
.
size
,
obj
.
indices
.
size
,
obj
.
indptr
.
size
,
obj
.
nnz
)
def
get_size
(
self
,
shape_info
):
return
(
shape_info
[
1
]
*
numpy
.
dtype
(
self
.
dtype
)
.
itemsize
+
(
shape_info
[
2
]
+
shape_info
[
3
])
*
numpy
.
dtype
(
'int32'
)
.
itemsize
)
# Register SparseType's C code for ViewOp.
# Register SparseType's C code for ViewOp.
theano
.
compile
.
register_view_op_c_code
(
theano
.
compile
.
register_view_op_c_code
(
SparseType
,
SparseType
,
...
...
theano/tensor/basic.py
浏览文件 @
56eb0c95
...
@@ -1181,9 +1181,36 @@ class TensorType(Type):
...
@@ -1181,9 +1181,36 @@ class TensorType(Type):
"""
"""
return
numpy
.
zeros
(
shape
,
dtype
=
self
.
dtype
)
return
numpy
.
zeros
(
shape
,
dtype
=
self
.
dtype
)
def
get_shape_info
(
self
,
obj
):
"""Return the information needed to compute the memory size of obj.
The memory size is only the data, so this exclude the container.
For an ndarray, this is the data, but not the ndarray object and
others data structures as shape and strides.
get_shape_info() and get_size() work in tendem for the memory profiler.
get_shape_info() is called during the execution of the function.
So it is better that it is not too slow.
get_size() will be called with the output of this function
when printing the memory profile.
:param obj: The object that this Type represent during execution
:return: Python object that self.get_size() understand
"""
return
obj
.
shape
def
get_size
(
self
,
shape_info
):
def
get_size
(
self
,
shape_info
):
return
numpy
.
prod
(
shape_info
,
dtype
=
int
)
*
numpy
.
dtype
(
self
.
dtype
)
.
itemsize
""" Number of bytes taken by the object represented by shape_info
:param shape_info: the output of the call to get_shape_info()
:return: the number of bytes taken by the object described in
shape_info.
"""
return
numpy
.
prod
(
shape_info
,
dtype
=
int
)
*
numpy
.
dtype
(
self
.
dtype
)
.
itemsize
theano
.
compile
.
ops
.
expandable_types
+=
(
TensorType
,)
theano
.
compile
.
ops
.
expandable_types
+=
(
TensorType
,)
# Register TensorType C code for ViewOp.
# Register TensorType C code for ViewOp.
...
...
theano/tensor/raw_random.py
浏览文件 @
56eb0c95
...
@@ -56,6 +56,9 @@ class RandomStateType(gof.Type):
...
@@ -56,6 +56,9 @@ class RandomStateType(gof.Type):
return
False
return
False
return
True
return
True
def
get_shape_info
(
self
,
obj
):
return
None
def
get_size
(
self
,
shape_info
):
def
get_size
(
self
,
shape_info
):
# The size is the data, that have constant size.
# The size is the data, that have constant size.
state
=
numpy
.
random
.
RandomState
()
.
get_state
()
state
=
numpy
.
random
.
RandomState
()
.
get_state
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论