Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2dc51295
提交
2dc51295
authored
5月 06, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix pickling of FunctionGraph
上级
2a5c64c4
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
73 行增加
和
21 行删除
+73
-21
fg.py
theano/gof/fg.py
+16
-0
test_fg.py
theano/gof/tests/test_fg.py
+9
-0
toolbox.py
theano/gof/toolbox.py
+48
-21
没有找到文件。
theano/gof/fg.py
浏览文件 @
2dc51295
...
...
@@ -743,3 +743,19 @@ class FunctionGraph(utils.object2):
for
feature
in
self
.
_features
:
e
.
attach_feature
(
feature
)
return
e
,
equiv
def
__getstate__
(
self
):
"""This is needed as some feature introduce instancemethod and
this is not pickable.
"""
d
=
self
.
__dict__
.
copy
()
for
feature
in
self
.
_features
:
for
attr
in
getattr
(
feature
,
"pickle_rm_attr"
,
[]):
del
d
[
attr
]
return
d
def
__setstate__
(
self
,
dct
):
self
.
__dict__
.
update
(
dct
)
for
feature
in
self
.
_features
:
if
hasattr
(
feature
,
"unpickle"
):
feature
.
unpickle
(
self
)
theano/gof/tests/test_fg.py
浏览文件 @
2dc51295
import
pickle
import
unittest
import
theano
from
theano.gof
import
CachedConstantError
,
FunctionGraph
from
theano
import
tensor
as
tt
class
TFunctionGraph
(
unittest
.
TestCase
):
...
...
@@ -15,3 +17,10 @@ class TFunctionGraph(unittest.TestCase):
v
=
theano
.
tensor
.
constant
(
1
)
assert
v
.
cached
FunctionGraph
([],
[
v
+
1
])
def
test_pickle
(
self
):
v
=
tt
.
vector
()
func
=
theano
.
gof
.
FunctionGraph
([
v
],
[
v
+
1
])
s
=
pickle
.
dumps
(
func
)
func2
=
pickle
.
loads
(
s
)
theano/gof/toolbox.py
浏览文件 @
2dc51295
...
...
@@ -105,6 +105,7 @@ class Bookkeeper(Feature):
class
History
(
Feature
):
pickle_rm_attr
=
[
"checkpoint"
,
"revert"
]
def
__init__
(
self
):
self
.
history
=
{}
...
...
@@ -114,6 +115,13 @@ class History(Feature):
raise
AlreadyThere
(
"History feature is already present or in"
" conflict with another plugin."
)
self
.
history
[
fgraph
]
=
[]
# Don't call unpickle here, as ReplaceValidate.on_attach()
# call to History.on_attach() will call the
# ReplaceValidate.unpickle and not History.unpickle
fgraph
.
checkpoint
=
lambda
:
len
(
self
.
history
[
fgraph
])
fgraph
.
revert
=
partial
(
self
.
revert
,
fgraph
)
def
unpickle
(
self
,
fgraph
):
fgraph
.
checkpoint
=
lambda
:
len
(
self
.
history
[
fgraph
])
fgraph
.
revert
=
partial
(
self
.
revert
,
fgraph
)
...
...
@@ -144,47 +152,66 @@ class History(Feature):
class
Validator
(
Feature
):
pickle_rm_attr
=
[
"validate"
,
"consistent"
]
def
on_attach
(
self
,
fgraph
):
for
attr
in
(
'validate'
,
'validate_time'
):
if
hasattr
(
fgraph
,
attr
):
raise
AlreadyThere
(
"Validator feature is already present or in"
" conflict with another plugin."
)
# Don't call unpickle here, as ReplaceValidate.on_attach()
# call to History.on_attach() will call the
# ReplaceValidate.unpickle and not History.unpickle
fgraph
.
validate
=
partial
(
self
.
validate
,
fgraph
)
fgraph
.
consistent
=
partial
(
self
.
consistent
,
fgraph
)
def
validate
():
t0
=
time
.
time
()
ret
=
fgraph
.
execute_callbacks
(
'validate'
)
t1
=
time
.
time
()
if
fgraph
.
profile
:
fgraph
.
profile
.
validate_time
+=
t1
-
t0
return
ret
fgraph
.
validate
=
validate
def
consistent
():
try
:
fgraph
.
validate
()
return
True
except
Exception
:
return
False
fgraph
.
consistent
=
consistent
def
unpickle
(
self
,
fgraph
):
fgraph
.
validate
=
partial
(
self
.
validate
,
fgraph
)
fgraph
.
consistent
=
partial
(
self
.
consistent
,
fgraph
)
def
on_detach
(
self
,
fgraph
):
del
fgraph
.
validate
del
fgraph
.
consistent
def
validate
(
self
,
fgraph
):
t0
=
time
.
time
()
ret
=
fgraph
.
execute_callbacks
(
'validate'
)
t1
=
time
.
time
()
if
fgraph
.
profile
:
fgraph
.
profile
.
validate_time
+=
t1
-
t0
return
ret
def
consistent
(
self
,
fgraph
):
try
:
fgraph
.
validate
()
return
True
except
Exception
:
return
False
class
ReplaceValidate
(
History
,
Validator
):
pickle_rm_attr
=
[
"replace_validate"
,
"replace_all_validate"
,
"replace_all_validate_remove"
,
#Parent pickle_rm_attr
"consistent"
,
"validate"
,
"checkpoint"
,
"revert"
]
def
on_attach
(
self
,
fgraph
):
History
.
on_attach
(
self
,
fgraph
)
Validator
.
on_attach
(
self
,
fgraph
)
for
attr
in
(
'replace_validate'
,
'replace_all_validate'
):
for
attr
in
(
'replace_validate'
,
'replace_all_validate'
,
'replace_all_validate_remove'
):
if
hasattr
(
fgraph
,
attr
):
raise
AlreadyThere
(
"ReplaceValidate feature is already present"
" or in conflict with another plugin."
)
History
.
on_attach
(
self
,
fgraph
)
Validator
.
on_attach
(
self
,
fgraph
)
self
.
unpickle
(
fgraph
)
def
unpickle
(
self
,
fgraph
):
History
.
unpickle
(
self
,
fgraph
)
Validator
.
unpickle
(
self
,
fgraph
)
fgraph
.
replace_validate
=
partial
(
self
.
replace_validate
,
fgraph
)
fgraph
.
replace_all_validate
=
partial
(
self
.
replace_all_validate
,
fgraph
)
fgraph
.
replace_all_validate
=
partial
(
self
.
replace_all_validate
,
fgraph
)
fgraph
.
replace_all_validate_remove
=
partial
(
self
.
replace_all_validate_remove
,
fgraph
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论