Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ef48ace3
提交
ef48ace3
authored
7月 06, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove FunctionMaker pickling hack - it makes test_gc hard to write and seems useless
上级
cd2b4a31
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
55 行增加
和
26 行删除
+55
-26
function_module.py
theano/compile/function_module.py
+14
-16
test_gc.py
theano/tensor/tests/test_gc.py
+41
-10
没有找到文件。
theano/compile/function_module.py
浏览文件 @
ef48ace3
...
@@ -934,6 +934,7 @@ class FunctionMaker(object):
...
@@ -934,6 +934,7 @@ class FunctionMaker(object):
self
.
profile
=
profile
=
profile
or
mode_profile
self
.
profile
=
profile
=
profile
or
mode_profile
# Handle the case where inputs and/or outputs is a single Variable (not in a list)
# Handle the case where inputs and/or outputs is a single Variable (not in a list)
self
.
orig_outputs
=
outputs
unpack_single
=
False
unpack_single
=
False
return_none
=
False
return_none
=
False
if
outputs
is
None
:
if
outputs
is
None
:
...
@@ -1060,27 +1061,24 @@ class FunctionMaker(object):
...
@@ -1060,27 +1061,24 @@ class FunctionMaker(object):
fn
=
self
.
function_builder
(
_fn
,
_i
,
_o
,
self
.
indices
,
self
.
outputs
,
defaults
,
self
.
unpack_single
,
self
.
return_none
,
self
)
fn
=
self
.
function_builder
(
_fn
,
_i
,
_o
,
self
.
indices
,
self
.
outputs
,
defaults
,
self
.
unpack_single
,
self
.
return_none
,
self
)
return
fn
return
fn
def
_pickle_FunctionMaker
(
self
):
kwargs
=
dict
(
inputs
=
self
.
inputs
,
outputs
=
self
.
orig_outputs
,
mode
=
self
.
mode
,
accept_inplace
=
self
.
accept_inplace
,
function_builder
=
self
.
function_builder
,
profile
=
self
.
profile
,
)
return
(
_constructor_FunctionMaker
,
(
kwargs
,))
def
_pickle_FunctionMaker
(
fm
):
def
_constructor_FunctionMaker
(
kwargs
):
if
fm
.
return_none
:
return
FunctionMaker
(
**
kwargs
)
outputs
=
None
else
:
if
fm
.
unpack_single
:
outputs
=
fm
.
outputs
[
0
]
else
:
outputs
=
fm
.
outputs
#backport
#outputs = None if fm.return_none else (fm.outputs[0] if fm.unpack_single else fm.outputs)
rval
=
(
_constructor_FunctionMaker
,
(
fm
.
inputs
,
outputs
,
fm
.
mode
,
fm
.
accept_inplace
))
return
rval
def
_constructor_FunctionMaker
(
*
args
):
return
FunctionMaker
(
*
args
)
copy_reg
.
pickle
(
FunctionMaker
,
_pickle_FunctionMaker
)
copy_reg
.
pickle
(
FunctionMaker
,
_pickle_FunctionMaker
)
def
_pickle_slice
(
s
):
def
_pickle_slice
(
s
):
return
(
slice
,
(
s
.
start
,
s
.
stop
,
s
.
step
))
return
(
slice
,
(
s
.
start
,
s
.
stop
,
s
.
step
))
...
...
theano/tensor/tests/test_gc.py
浏览文件 @
ef48ace3
...
@@ -20,7 +20,7 @@ def test_no_reuse():
...
@@ -20,7 +20,7 @@ def test_no_reuse():
return
return
assert
not
'should not get here'
assert
not
'should not get here'
def
test_gc
():
def
test_gc
_never_pickles_temporaries
():
x
=
T
.
dvector
()
x
=
T
.
dvector
()
#print >> sys.stderr, 'BUILDING GRAPH'
#print >> sys.stderr, 'BUILDING GRAPH'
...
@@ -32,31 +32,62 @@ def test_gc():
...
@@ -32,31 +32,62 @@ def test_gc():
optimizer
=
None
optimizer
=
None
optimizer
=
'fast_run'
optimizer
=
'fast_run'
for
f_linker
,
g_linker
in
[
for
f_linker
,
g_linker
in
[
(
theano
.
PerformLinker
(
allow_gc
=
True
),
theano
.
PerformLinker
(
allow_gc
=
False
)),
(
theano
.
PerformLinker
(
allow_gc
=
True
),
theano
.
PerformLinker
(
allow_gc
=
False
)),
(
theano
.
OpWiseCLinker
(
allow_gc
=
True
),
theano
.
OpWiseCLinker
(
allow_gc
=
False
))]:
(
theano
.
OpWiseCLinker
(
allow_gc
=
True
),
theano
.
OpWiseCLinker
(
allow_gc
=
False
))]:
#f_linker has garbage collection
#g_linker has no garbage collection
#print >> sys.stderr, 'COMPILING'
#print >> sys.stderr, 'COMPILING'
f
=
theano
.
function
([
x
],
r
,
mode
=
theano
.
Mode
(
optimizer
=
optimizer
,
linker
=
f_linker
))
f
=
theano
.
function
([
x
],
r
,
mode
=
theano
.
Mode
(
optimizer
=
optimizer
,
linker
=
f_linker
))
g
=
theano
.
function
([
x
],
r
,
mode
=
theano
.
Mode
(
optimizer
=
optimizer
,
linker
=
g_linker
))
len_pre_f
=
len
(
cPickle
.
dumps
(
f
))
len_pre_g
=
len
(
cPickle
.
dumps
(
g
))
# should be no difference at first
# In future, FunctionMaker might pickle linker-dependent stuff and make
# this assertion fail.
assert
len_pre_f
==
len_pre_g
def
a
(
fn
):
return
len
(
cPickle
.
dumps
(
fn
.
maker
))
assert
a
(
f
)
==
a
(
f
)
# some sanity checks on the pickling mechanism
assert
a
(
g
)
==
a
(
g
)
# some sanity checks on the pickling mechanism
g
=
theano
.
function
([
x
],
r
,
mode
=
theano
.
Mode
(
optimizer
=
optimizer
,
linker
=
f_linker
))
def
b
(
fn
):
return
len
(
cPickle
.
dumps
(
theano
.
compile
.
function_module
.
_pickle_Function
(
fn
)))
assert
b
(
f
)
==
b
(
f
)
# some sanity checks on the pickling mechanism
pre_f
=
cPickle
.
dumps
(
f
)
def
c
(
fn
):
pre_g
=
cPickle
.
dumps
(
g
)
return
len
(
cPickle
.
dumps
(
fn
))
assert
c
(
f
)
==
c
(
f
)
# some sanity checks on the pickling mechanism
assert
c
(
g
)
==
c
(
g
)
# some sanity checks on the pickling mechanism
#print >> sys.stderr, 'RUNNING'
# now run the function once to create temporaries within the no-gc
# linker
f
(
numpy
.
ones
(
100
,
dtype
=
'float64'
))
f
(
numpy
.
ones
(
100
,
dtype
=
'float64'
))
g
(
numpy
.
ones
(
100
,
dtype
=
'float64'
))
g
(
numpy
.
ones
(
100
,
dtype
=
'float64'
))
# serialize the functions again
post_f
=
cPickle
.
dumps
(
f
)
post_f
=
cPickle
.
dumps
(
f
)
post_g
=
cPickle
.
dumps
(
g
)
post_g
=
cPickle
.
dumps
(
g
)
#because allow_gc should leave the function un-changed by calling
assert
len
(
pre_f
)
==
len
(
post_f
)
#because temporaries that weren't collected shouldn't be pickled anyway
len_post_f
=
len
(
post_f
)
len_post_f
=
len
(
post_f
)
len_post_g
=
len
(
post_g
)
len_post_g
=
len
(
post_g
)
#assert that f() didn't cause the function to grow
# allow_gc should leave the function un-changed by calling
assert
len_pre_f
==
len_post_f
#assert that g() didn't cause g to grow
# because temporaries that weren't collected shouldn't be pickled anyway
assert
len_post_f
==
len_post_g
,
(
f_linker
,
len_post_f
,
len_post_g
)
assert
len_post_f
==
len_post_g
,
(
f_linker
,
len_post_f
,
len_post_g
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论