Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ce29622c
提交
ce29622c
authored
5月 29, 2015
作者:
ChienliMa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add some docs to FunctionGraph and minor changes of function_module.copy()
上级
c6c3d454
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
47 行增加
和
36 行删除
+47
-36
function_module.py
theano/compile/function_module.py
+26
-30
test_function_module.py
theano/compile/tests/test_function_module.py
+2
-4
fg.py
theano/gof/fg.py
+19
-2
没有找到文件。
theano/compile/function_module.py
浏览文件 @
ce29622c
...
...
@@ -571,27 +571,13 @@ class Function(object):
# copy SymbolocKits
ins
,
outs
=
copy
.
deepcopy
([
self
.
maker
.
inputs
,
self
.
maker
.
outputs
])
# get copied input, output variables
in_vars
=
[
i
.
variable
for
i
in
ins
]
out_vars
=
[
o
.
variable
for
o
in
outs
]
# contruct memo that map old variables to new variables
memo
=
{}
for
old_i
,
new_i
in
zip
([
i
.
variable
for
i
in
self
.
maker
.
inputs
],
in_vars
):
memo
[
old_i
]
=
new_i
for
old_o
,
new_o
in
zip
([
o
.
variable
for
o
in
self
.
maker
.
outputs
],
out_vars
):
memo
[
old_o
]
=
new_o
# contruct new fgraph with new vars and complete the memo
memo
=
clone_get_equiv
(
in_vars
,
out_vars
,
memo
)
new_fgraph
=
FunctionGraph
(
in_vars
,
out_vars
)
# re-initialize new FunctionMaker
# copy fgraph and get memo
maker
=
self
.
maker
fg_cpy
,
memo
=
maker
.
fgraph
.
clone_get_equiv
(
attach_feature
=
False
)
# use copied ins, outs and fgraph to init a maker
new_maker
=
FunctionMaker
(
inputs
=
ins
,
outputs
=
outs
,
mode
=
maker
.
mode
,
fgraph
=
new_fgraph
,
profile
=
maker
.
profile
,
fgraph
=
fg_cpy
,
profile
=
maker
.
profile
,
accept_inplace
=
maker
.
accept_inplace
,
function_builder
=
maker
.
function_builder
,
on_unused_input
=
maker
.
on_unused_input
)
...
...
@@ -602,20 +588,30 @@ class Function(object):
storage_map
=
self
.
fn
.
storage_map
for
key
in
storage_map
.
keys
():
# output_storages should not be shared
if
key
not
in
self
.
maker
.
fgraph
.
outputs
and
\
memo
.
has_key
(
key
):
new_storage_map
[
memo
[
key
]]
=
storage_map
[
key
]
# if key not in self.maker.fgraph.outputs and \
# memo.has_key(key):
new_storage_map
[
memo
[
key
]]
=
storage_map
[
key
]
# copy input storages if it's mutable
input_storage
=
[]
for
i
in
self
.
maker
.
inputs
:
storage
=
getattr
(
i
,
'value'
,
None
)
if
isinstance
(
i
.
variable
,
theano
.
tensor
.
Constant
)
or
\
not
i
.
mutable
:
input_storage
.
append
(
storage
)
else
:
input_storage
.
append
(
copy
.
deepcopy
[
storage
])
# copy input storages and link function with new storage_map
input_storage
=
copy
.
copy
([
getattr
(
i
,
'value'
,
None
)
for
i
in
ins
])
new_func
=
new_maker
.
create
(
input_storage
,
storage_map
=
new_storage_map
)
new_func
=
new_maker
.
create
(
input_storage
,
\
storage_map
=
new_storage_map
)
# share immutable SharedVariable's storage
for
(
input
,
_1
,
_2
),
here
,
there
in
zip
(
self
.
indices
,
self
.
input_storage
,
new_func
.
input_storage
):
if
not
input
.
mutable
:
there
.
data
=
here
.
data
# for (input, _1, _2), here, there in zip(self.indices,
# self.input_storage,
# new_func.input_storage):
# if isinstance(i.variable, theano.tensor.Constant) or \
# not input.mutable:
# there.data = here.data
return
new_func
...
...
theano/compile/tests/test_function_module.py
浏览文件 @
ce29622c
...
...
@@ -243,7 +243,7 @@ class T_function(unittest.TestCase):
def
test_copy_share_memory
(
self
):
x
=
T
.
fscalar
(
'x'
)
y
=
T
.
tanh
((
x
+
2
)
/
(
x
+
0.2
)
**
2
)
y
=
T
.
tanh
((
x
+
2
)
/
(
x
-
0.2
)
**
2
)
# test for PerformaLinker, will cover VM_linker later
ori
=
theano
.
function
([
x
],
[
y
],
mode
=
"FAST_COMPILE"
)
...
...
@@ -256,13 +256,11 @@ class T_function(unittest.TestCase):
fgraph_cpy
=
cpy
.
maker
.
fgraph
# assert intermediate and Constants storages are shared
i_o_variables
=
fgraph_cpy
.
inputs
i_o_variables
=
fgraph_cpy
.
inputs
+
fgraph_cpy
.
outputs
ori_storages
=
storage_map_ori
.
values
()
for
key
in
storage_map_cpy
.
keys
():
if
key
not
in
i_o_variables
or
isinstance
(
key
,
theano
.
tensor
.
Constant
):
print
key
storage
=
storage_map_cpy
[
key
]
print
[
storage
is
s
for
s
in
ori_storages
]
self
.
assertTrue
(
any
([
storage
is
s
for
s
in
ori_storages
]))
# assert storages of SharedVariable without updates are shared
...
...
theano/gof/fg.py
浏览文件 @
ce29622c
...
...
@@ -276,8 +276,19 @@ class FunctionGraph(utils.object2):
return
True
return
False
# import #
def
__import_r__
(
self
,
variable
,
reason
):
### import ###
def
__import_r__
(
self
,
variables
,
reason
):
"""
Import variables to this FunctionGraph and also their apply_node,
if those nodes are not in this graph.
----------------------
Parameters;
variables -- Iterable if variables needed to import
reason -- String. Reason.
----------------------
Returns:
None
"""
global
NullType
if
NullType
is
None
:
from
.null_type
import
NullType
...
...
@@ -296,6 +307,12 @@ class FunctionGraph(utils.object2):
self
.
variables
.
add
(
variable
)
def
__import__
(
self
,
apply_node
,
check
=
True
,
reason
=
None
):
"""
Given an apply_node, recursively search from this node to know graph,
and then add all unknown variables and apply_nodes to this graph.
"""
node
=
apply_node
# We import the nodes in topological order. We only are interested
# in new nodes, so we use all variables we know of as if they were the input set.
# (the functions in the graph module only use the input set to
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论