Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1d5236be
提交
1d5236be
authored
12月 19, 2020
作者:
Michael Osthege
提交者:
Brandon T. Willard
12月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Outsource exceptions to reduce dependency on cmodule
上级
0e3a8128
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
32 行增加
和
29 行删除
+32
-29
cmodule.py
theano/link/c/cmodule.py
+1
-8
exceptions.py
theano/link/c/exceptions.py
+6
-0
vm.py
theano/link/c/vm.py
+22
-19
op.py
theano/scan/op.py
+3
-2
没有找到文件。
theano/link/c/cmodule.py
浏览文件 @
1d5236be
...
@@ -28,6 +28,7 @@ from theano.configdefaults import gcc_version_str, local_bitwidth
...
@@ -28,6 +28,7 @@ from theano.configdefaults import gcc_version_str, local_bitwidth
# we will abuse the lockfile mechanism when reading and writing the registry
# we will abuse the lockfile mechanism when reading and writing the registry
from
theano.gof
import
compilelock
from
theano.gof
import
compilelock
from
theano.gof.utils
import
flatten
,
hash_from_code
from
theano.gof.utils
import
flatten
,
hash_from_code
from
theano.link.c.exceptions
import
MissingGXX
from
theano.utils
import
output_subprocess_Popen
,
subprocess_Popen
from
theano.utils
import
output_subprocess_Popen
,
subprocess_Popen
...
@@ -45,14 +46,6 @@ METH_NOARGS = "METH_NOARGS"
...
@@ -45,14 +46,6 @@ METH_NOARGS = "METH_NOARGS"
import_time
=
0
import_time
=
0
class
MissingGXX
(
Exception
):
"""
This error is raised when we try to generate c code,
but g++ is not available.
"""
def
debug_counter
(
name
,
every
=
1
):
def
debug_counter
(
name
,
every
=
1
):
"""
"""
Debug counter to know how often we go through some piece of code.
Debug counter to know how often we go through some piece of code.
...
...
theano/link/c/exceptions.py
0 → 100644
浏览文件 @
1d5236be
class
MissingGXX
(
Exception
):
"""
This error is raised when we try to generate c code,
but g++ is not available.
"""
theano/link/c/vm.py
浏览文件 @
1d5236be
...
@@ -12,8 +12,11 @@ import time
...
@@ -12,8 +12,11 @@ import time
import
warnings
import
warnings
from
collections
import
defaultdict
from
collections
import
defaultdict
import
theano.link.c.cmodule
from
theano
import
config
from
theano
import
config
,
link
from
theano.gof
import
Constant
,
Variable
from
theano.link.basic
import
Container
,
LocalLinker
from
theano.link.c.exceptions
import
MissingGXX
from
theano.link.utils
import
gc_helper
,
map_storage
,
raise_with_op
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -55,7 +58,7 @@ def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, depend
...
@@ -55,7 +58,7 @@ def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, depend
)
)
ins
=
node
.
inputs
[
idx_v
[
0
]]
ins
=
node
.
inputs
[
idx_v
[
0
]]
if
ins
is
not
None
:
if
ins
is
not
None
:
assert
isinstance
(
ins
,
theano
.
Variable
)
assert
isinstance
(
ins
,
Variable
)
origin
=
view_of
.
get
(
ins
,
ins
)
origin
=
view_of
.
get
(
ins
,
ins
)
view_of
[
out
]
=
origin
view_of
[
out
]
=
origin
viewed_by
[
origin
]
.
append
(
out
)
viewed_by
[
origin
]
.
append
(
out
)
...
@@ -96,7 +99,7 @@ def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, depend
...
@@ -96,7 +99,7 @@ def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, depend
if
(
if
(
not
viewed_by
[
origin
]
not
viewed_by
[
origin
]
and
origin
not
in
fgraph
.
inputs
and
origin
not
in
fgraph
.
inputs
and
not
isinstance
(
origin
,
theano
.
Constant
)
and
not
isinstance
(
origin
,
Constant
)
):
):
# where gc
# where gc
for
i
in
range
(
idx
+
1
,
len
(
order
)):
for
i
in
range
(
idx
+
1
,
len
(
order
)):
...
@@ -255,7 +258,7 @@ class Loop(VM):
...
@@ -255,7 +258,7 @@ class Loop(VM):
self
.
call_counts
[
i
]
+=
1
self
.
call_counts
[
i
]
+=
1
self
.
call_times
[
i
]
+=
t1
-
t0
self
.
call_times
[
i
]
+=
t1
-
t0
except
Exception
:
except
Exception
:
link
.
raise_with_op
(
self
.
fgraph
,
node
,
thunk
)
raise_with_op
(
self
.
fgraph
,
node
,
thunk
)
else
:
else
:
for
cont
in
self
.
pre_call_clear
:
for
cont
in
self
.
pre_call_clear
:
cont
[
0
]
=
None
cont
[
0
]
=
None
...
@@ -263,7 +266,7 @@ class Loop(VM):
...
@@ -263,7 +266,7 @@ class Loop(VM):
for
thunk
,
node
in
zip
(
self
.
thunks
,
self
.
nodes
):
for
thunk
,
node
in
zip
(
self
.
thunks
,
self
.
nodes
):
thunk
()
thunk
()
except
Exception
:
except
Exception
:
link
.
raise_with_op
(
self
.
fgraph
,
node
,
thunk
)
raise_with_op
(
self
.
fgraph
,
node
,
thunk
)
class
LoopGC
(
VM
):
class
LoopGC
(
VM
):
...
@@ -299,7 +302,7 @@ class LoopGC(VM):
...
@@ -299,7 +302,7 @@ class LoopGC(VM):
old_s
[
0
]
=
None
old_s
[
0
]
=
None
i
+=
1
i
+=
1
except
Exception
:
except
Exception
:
link
.
raise_with_op
(
self
.
fgraph
,
node
,
thunk
)
raise_with_op
(
self
.
fgraph
,
node
,
thunk
)
else
:
else
:
for
cont
in
self
.
pre_call_clear
:
for
cont
in
self
.
pre_call_clear
:
cont
[
0
]
=
None
cont
[
0
]
=
None
...
@@ -311,7 +314,7 @@ class LoopGC(VM):
...
@@ -311,7 +314,7 @@ class LoopGC(VM):
for
old_s
in
old_storage
:
for
old_s
in
old_storage
:
old_s
[
0
]
=
None
old_s
[
0
]
=
None
except
Exception
:
except
Exception
:
link
.
raise_with_op
(
self
.
fgraph
,
node
,
thunk
)
raise_with_op
(
self
.
fgraph
,
node
,
thunk
)
class
Stack
(
VM
):
class
Stack
(
VM
):
...
@@ -539,7 +542,7 @@ class Stack(VM):
...
@@ -539,7 +542,7 @@ class Stack(VM):
off
=
getattr
(
o
[
0
],
"offset"
,
""
)
off
=
getattr
(
o
[
0
],
"offset"
,
""
)
self
.
variable_offset
[
var
]
=
off
self
.
variable_offset
[
var
]
=
off
except
Exception
:
except
Exception
:
link
.
raise_with_op
(
raise_with_op
(
self
.
fgraph
,
self
.
fgraph
,
current_apply
,
current_apply
,
self
.
thunks
[
self
.
node_idx
[
current_apply
]],
self
.
thunks
[
self
.
node_idx
[
current_apply
]],
...
@@ -611,7 +614,7 @@ class Stack(VM):
...
@@ -611,7 +614,7 @@ class Stack(VM):
self
.
call_times
[
current_idx
]
+=
dt
self
.
call_times
[
current_idx
]
+=
dt
except
Exception
:
except
Exception
:
link
.
raise_with_op
(
raise_with_op
(
self
.
fgraph
,
self
.
fgraph
,
current_apply
,
current_apply
,
self
.
thunks
[
self
.
node_idx
[
current_apply
]],
self
.
thunks
[
self
.
node_idx
[
current_apply
]],
...
@@ -693,8 +696,8 @@ class Stack(VM):
...
@@ -693,8 +696,8 @@ class Stack(VM):
try
:
try
:
# If cxx is explicitely set to an empty string, we do not want to import neither lazylinker C code
# If cxx is explicitely set to an empty string, we do not want to import neither lazylinker C code
# nor lazylinker compiled C code from cache.
# nor lazylinker compiled C code from cache.
if
not
theano
.
config
.
cxx
:
if
not
config
.
cxx
:
raise
theano
.
link
.
c
.
cmodule
.
MissingGXX
(
raise
MissingGXX
(
"lazylinker will not be imported if theano.config.cxx is not set."
"lazylinker will not be imported if theano.config.cxx is not set."
)
)
from
theano.link.c
import
lazylinker_c
from
theano.link.c
import
lazylinker_c
...
@@ -708,7 +711,7 @@ try:
...
@@ -708,7 +711,7 @@ try:
except
ImportError
:
except
ImportError
:
pass
pass
except
(
OSError
,
theano
.
link
.
c
.
cmodule
.
MissingGXX
)
as
e
:
except
(
OSError
,
MissingGXX
)
as
e
:
# OSError happens when g++ is not installed. In that case, we
# OSError happens when g++ is not installed. In that case, we
# already changed the default linker to something else then CVM.
# already changed the default linker to something else then CVM.
# Currently this is the py linker.
# Currently this is the py linker.
...
@@ -716,7 +719,7 @@ except (OSError, theano.link.c.cmodule.MissingGXX) as e:
...
@@ -716,7 +719,7 @@ except (OSError, theano.link.c.cmodule.MissingGXX) as e:
assert
not
config
.
_config_var_dict
[
"linker"
]
.
default
.
startswith
(
"cvm"
),
e
assert
not
config
.
_config_var_dict
[
"linker"
]
.
default
.
startswith
(
"cvm"
),
e
class
VM_Linker
(
link
.
LocalLinker
):
class
VM_Linker
(
LocalLinker
):
"""
"""
Class that satisfies the Linker interface by acting as a VM factory.
Class that satisfies the Linker interface by acting as a VM factory.
...
@@ -774,7 +777,7 @@ class VM_Linker(link.LocalLinker):
...
@@ -774,7 +777,7 @@ class VM_Linker(link.LocalLinker):
self
.
callback_input
=
callback_input
self
.
callback_input
=
callback_input
self
.
lazy
=
lazy
self
.
lazy
=
lazy
if
c_thunks
is
None
:
if
c_thunks
is
None
:
c_thunks
=
bool
(
theano
.
config
.
cxx
)
c_thunks
=
bool
(
config
.
cxx
)
self
.
c_thunks
=
c_thunks
self
.
c_thunks
=
c_thunks
self
.
allow_partial_eval
=
allow_partial_eval
self
.
allow_partial_eval
=
allow_partial_eval
self
.
updated_vars
=
{}
self
.
updated_vars
=
{}
...
@@ -1111,7 +1114,7 @@ class VM_Linker(link.LocalLinker):
...
@@ -1111,7 +1114,7 @@ class VM_Linker(link.LocalLinker):
fgraph
=
self
.
fgraph
fgraph
=
self
.
fgraph
order
=
self
.
schedule
(
fgraph
)
order
=
self
.
schedule
(
fgraph
)
input_storage
,
output_storage
,
storage_map
=
link
.
map_storage
(
input_storage
,
output_storage
,
storage_map
=
map_storage
(
fgraph
,
order
,
input_storage
,
output_storage
,
storage_map
fgraph
,
order
,
input_storage
,
output_storage
,
storage_map
)
)
compute_map
=
{}
compute_map
=
{}
...
@@ -1185,7 +1188,7 @@ class VM_Linker(link.LocalLinker):
...
@@ -1185,7 +1188,7 @@ class VM_Linker(link.LocalLinker):
for
pair
in
reallocated_info
.
values
():
for
pair
in
reallocated_info
.
values
():
storage_map
[
pair
[
1
]]
=
storage_map
[
pair
[
0
]]
storage_map
[
pair
[
1
]]
=
storage_map
[
pair
[
0
]]
computed
,
last_user
=
link
.
gc_helper
(
order
)
computed
,
last_user
=
gc_helper
(
order
)
if
self
.
allow_gc
:
if
self
.
allow_gc
:
post_thunk_clear
=
[]
post_thunk_clear
=
[]
for
node
in
order
:
for
node
in
order
:
...
@@ -1220,11 +1223,11 @@ class VM_Linker(link.LocalLinker):
...
@@ -1220,11 +1223,11 @@ class VM_Linker(link.LocalLinker):
return
(
return
(
vm
,
vm
,
[
[
link
.
Container
(
input
,
storage
)
Container
(
input
,
storage
)
for
input
,
storage
in
zip
(
fgraph
.
inputs
,
input_storage
)
for
input
,
storage
in
zip
(
fgraph
.
inputs
,
input_storage
)
],
],
[
[
link
.
Container
(
output
,
storage
,
readonly
=
True
)
Container
(
output
,
storage
,
readonly
=
True
)
for
output
,
storage
in
zip
(
fgraph
.
outputs
,
output_storage
)
for
output
,
storage
in
zip
(
fgraph
.
outputs
,
output_storage
)
],
],
thunks
,
thunks
,
...
...
theano/scan/op.py
浏览文件 @
1d5236be
...
@@ -64,6 +64,7 @@ from theano.gof.graph import equal_computations, io_connection_pattern
...
@@ -64,6 +64,7 @@ from theano.gof.graph import equal_computations, io_connection_pattern
from
theano.gof.toolbox
import
NoOutputFromInplace
from
theano.gof.toolbox
import
NoOutputFromInplace
from
theano.gradient
import
DisconnectedType
,
NullType
,
grad_undefined
from
theano.gradient
import
DisconnectedType
,
NullType
,
grad_undefined
from
theano.link.c.cc
import
CLinker
from
theano.link.c.cc
import
CLinker
from
theano.link.c.exceptions
import
MissingGXX
from
theano.link.utils
import
raise_with_op
from
theano.link.utils
import
raise_with_op
from
theano.scan.utils
import
Validator
,
forced_replace
,
hash_listsDictsTuples
,
safe_new
from
theano.scan.utils
import
Validator
,
forced_replace
,
hash_listsDictsTuples
,
safe_new
from
theano.tensor
import
TensorType
,
as_tensor_variable
from
theano.tensor
import
TensorType
,
as_tensor_variable
...
@@ -974,7 +975,7 @@ class Scan(PureOp):
...
@@ -974,7 +975,7 @@ class Scan(PureOp):
try
:
try
:
if
impl
==
"py"
:
if
impl
==
"py"
:
raise
theano
.
link
.
c
.
cmodule
.
MissingGXX
raise
MissingGXX
cython_mintaps
=
np
.
asarray
(
self
.
mintaps
,
dtype
=
"int32"
)
cython_mintaps
=
np
.
asarray
(
self
.
mintaps
,
dtype
=
"int32"
)
cython_tap_array_len
=
np
.
asarray
(
cython_tap_array_len
=
np
.
asarray
(
[
len
(
x
)
for
x
in
self
.
tap_array
],
dtype
=
"int32"
[
len
(
x
)
for
x
in
self
.
tap_array
],
dtype
=
"int32"
...
@@ -1051,7 +1052,7 @@ class Scan(PureOp):
...
@@ -1051,7 +1052,7 @@ class Scan(PureOp):
node
,
node
,
)
)
except
(
ImportError
,
theano
.
link
.
c
.
cmodule
.
MissingGXX
):
except
(
ImportError
,
MissingGXX
):
p
=
self
.
execute
p
=
self
.
execute
# default arguments are stored in the closure of `rval`
# default arguments are stored in the closure of `rval`
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论