Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9a289b81
提交
9a289b81
authored
10月 20, 2014
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2173 from RoyXue/theano_function_free
Issue 2169 a_theano_function.free() to free the temp memory
上级
647921d7
845ae44f
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
93 行增加
和
2 行删除
+93
-2
function_module.py
theano/compile/function_module.py
+23
-1
test_function_module.py
theano/compile/tests/test_function_module.py
+20
-0
lazylinker_c.c
theano/gof/lazylinker_c.c
+29
-1
test_vm.py
theano/gof/tests/test_vm.py
+19
-0
vm.py
theano/gof/vm.py
+2
-0
没有找到文件。
theano/compile/function_module.py
浏览文件 @
9a289b81
...
...
@@ -19,6 +19,9 @@ import theano.compile.mode
from
theano.compile.io
import
(
In
,
SymbolicInput
,
SymbolicInputKit
,
SymbolicOutput
)
from
theano.compile.ops
import
deep_copy_op
,
view_op
from
theano.gof.op
import
ops_with_inner_function
import
logging
_logger
=
logging
.
getLogger
(
'theano.compile.function_module'
)
...
...
@@ -295,6 +298,7 @@ class Function(object):
self
.
profile
=
None
# reassigned in FunctionMaker.create
self
.
trust_input
=
False
# If True, we don't check the input parameter
self
.
name
=
None
self
.
node_op_list
=
[]
# We will be popping stuff off this `containers` object. It is a copy.
containers
=
list
(
self
.
input_storage
)
...
...
@@ -451,6 +455,10 @@ class Function(object):
if
input
.
update
is
not
None
:
self
.
n_returned_outputs
-=
1
for
node
in
self
.
maker
.
fgraph
.
apply_nodes
:
if
node
.
op
in
ops_with_inner_function
.
keys
():
self
.
node_op_list
.
append
(
node
.
op
)
def
__contains__
(
self
,
item
):
return
self
.
value
.
__contains__
(
item
)
...
...
@@ -678,8 +686,22 @@ class Function(object):
None
,
# this property itself is not settable
doc
=
"""dictionary-like access to the containers associated with Variables"""
)
# pickling/deepcopy support for Function
def
free
(
self
):
"""
When allow_gc = False, clear the Variables in storage_map
"""
# 1.no allow_gc return False 2.has allow_gc, if allow_gc is False, return True
if
not
getattr
(
self
.
fn
,
'allow_gc'
,
True
):
for
key
in
self
.
fn
.
storage_map
.
keys
():
if
not
isinstance
(
key
,
theano
.
gof
.
Constant
):
self
.
fn
.
storage_map
[
key
][
0
]
=
None
for
node
in
self
.
node_op_list
:
ops_with_inner_function
[
node
.
op
]
.
free
()
# pickling/deepcopy support for Function
def
_pickle_Function
(
f
):
#copy of the input storage list
...
...
theano/compile/tests/test_function_module.py
浏览文件 @
9a289b81
...
...
@@ -399,6 +399,26 @@ class T_function(unittest.TestCase):
y
=
x
*
2
self
.
assertRaises
(
RuntimeError
,
function
,
[
x
],
y
,
givens
=
{
x
:
x
+
1
})
def
test_free
(
self
):
"""
Make test on free() function
"""
x
=
T
.
vector
(
'x'
)
func
=
function
([
x
],
x
+
1
)
func
.
fn
.
allow_gc
=
False
func
([
1
])
check_list
=
[]
for
key
,
val
in
func
.
fn
.
storage_map
.
iteritems
():
if
not
isinstance
(
key
,
theano
.
gof
.
Constant
):
check_list
.
append
(
val
)
assert
any
([
val
[
0
]
for
val
in
check_list
])
func
.
free
()
for
key
,
val
in
func
.
fn
.
storage_map
.
iteritems
():
if
not
isinstance
(
key
,
theano
.
gof
.
Constant
):
assert
(
val
[
0
]
==
None
)
class
T_picklefunction
(
unittest
.
TestCase
):
...
...
theano/gof/lazylinker_c.c
浏览文件 @
9a289b81
...
...
@@ -930,6 +930,34 @@ static PyMethodDef CLazyLinker_methods[] = {
};
#endif
static
PyObject
*
CLazyLinker_get_allow_gc
(
CLazyLinker
*
self
,
void
*
closure
)
{
return
PyBool_FromLong
(
self
->
allow_gc
);
}
static
int
CLazyLinker_set_allow_gc
(
CLazyLinker
*
self
,
PyObject
*
value
,
void
*
closure
)
{
if
(
!
PyBool_Check
(
value
))
return
-
1
;
if
(
value
==
Py_True
)
self
->
allow_gc
=
true
;
else
self
->
allow_gc
=
false
;
return
0
;
}
static
PyGetSetDef
CLazyLinker_getset
[]
=
{
{
"allow_gc"
,
(
getter
)
CLazyLinker_get_allow_gc
,
(
setter
)
CLazyLinker_set_allow_gc
,
"do this function support allow_gc"
,
NULL
},
{
NULL
,
NULL
,
NULL
,
NULL
}
/* Sentinel */
};
static
PyMemberDef
CLazyLinker_members
[]
=
{
{(
char
*
)
"nodes"
,
T_OBJECT_EX
,
offsetof
(
CLazyLinker
,
nodes
),
0
,
(
char
*
)
"list of nodes"
},
...
...
@@ -983,7 +1011,7 @@ static PyTypeObject lazylinker_ext_CLazyLinkerType = {
0
,
/* tp_iternext */
0
,
//CLazyLinker_methods, /* tp_methods */
CLazyLinker_members
,
/* tp_members */
0
,
/* tp_getset */
CLazyLinker_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
...
...
theano/gof/tests/test_vm.py
浏览文件 @
9a289b81
...
...
@@ -184,6 +184,25 @@ def test_speed_lazy():
time_linker
(
'vmLinker_C'
,
lambda
:
vm
.
VM_Linker
(
allow_gc
=
False
,
use_cloop
=
True
))
def
test_allow_gc_cvm
():
v
=
theano
.
tensor
.
vector
()
f
=
theano
.
function
([
v
],
v
+
1
)
f
([
1
])
n
=
list
(
f
.
maker
.
fgraph
.
apply_nodes
)[
0
]
.
outputs
[
0
]
assert
f
.
fn
.
storage_map
[
n
][
0
]
is
None
assert
f
.
fn
.
allow_gc
is
True
f
.
fn
.
allow_gc
=
False
assert
f
.
fn
.
allow_gc
is
False
f
([
1
])
assert
f
.
fn
.
storage_map
[
n
][
0
]
is
not
None
f
.
fn
.
allow_gc
=
True
assert
f
.
fn
.
allow_gc
is
True
f
([
1
])
assert
f
.
fn
.
storage_map
[
n
][
0
]
is
None
run_memory_usage_tests
=
False
if
run_memory_usage_tests
:
# these are not normal unit tests, do not run them as part of standard
...
...
theano/gof/vm.py
浏览文件 @
9a289b81
...
...
@@ -924,6 +924,8 @@ class VM_Linker(link.LocalLinker):
self
.
updated_vars
)
vm
.
storage_map
=
storage_map
return
(
vm
,
[
link
.
Container
(
input
,
storage
)
for
input
,
storage
in
zip
(
fgraph
.
inputs
,
input_storage
)],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论