Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cdac0c69
提交
cdac0c69
authored
11月 29, 2016
作者:
Frédéric Bastien
提交者:
GitHub
11月 29, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5265 from nouiz/fix_reload_pickle
Fix reload pickle
上级
b933c37a
574108ec
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
28 行增加
和
47 行删除
+28
-47
cmodule.py
theano/gof/cmodule.py
+1
-1
op.py
theano/gof/op.py
+10
-8
type.py
theano/gof/type.py
+9
-0
dnn.py
theano/sandbox/cuda/dnn.py
+6
-38
basic.py
theano/scalar/basic.py
+2
-0
没有找到文件。
theano/gof/cmodule.py
浏览文件 @
cdac0c69
...
@@ -189,7 +189,7 @@ static struct PyModuleDef moduledef = {{
...
@@ -189,7 +189,7 @@ static struct PyModuleDef moduledef = {{
def
add_support_code
(
self
,
code
):
def
add_support_code
(
self
,
code
):
assert
not
self
.
finalized
assert
not
self
.
finalized
if
code
not
in
self
.
support_code
:
# TODO: KLUDGE
if
code
and
code
not
in
self
.
support_code
:
# TODO: KLUDGE
self
.
support_code
.
append
(
code
)
self
.
support_code
.
append
(
code
)
def
add_function
(
self
,
fn
):
def
add_function
(
self
,
fn
):
...
...
theano/gof/op.py
浏览文件 @
cdac0c69
...
@@ -1270,10 +1270,11 @@ class COp(Op):
...
@@ -1270,10 +1270,11 @@ class COp(Op):
if
not
isinstance
(
func_files
,
list
):
if
not
isinstance
(
func_files
,
list
):
func_files
=
[
func_files
]
func_files
=
[
func_files
]
self
.
func_files
=
[
self
.
get_path
(
f
)
for
f
in
func_files
]
self
.
func_name
=
func_name
self
.
func_name
=
func_name
# Keep the original name. If we reload old pickle, we want to
self
.
load_c_code
()
# find the new path and new version of the file in Theano.
self
.
func_files
=
func_files
self
.
load_c_code
(
func_files
)
if
len
(
self
.
code_sections
)
==
0
:
if
len
(
self
.
code_sections
)
==
0
:
raise
ValueError
(
"No sections where defined in C files"
)
raise
ValueError
(
"No sections where defined in C files"
)
...
@@ -1288,12 +1289,13 @@ class COp(Op):
...
@@ -1288,12 +1289,13 @@ class COp(Op):
raise
ValueError
(
'Cannot have an "op_code_cleanup" section '
raise
ValueError
(
'Cannot have an "op_code_cleanup" section '
'and specify the func_name'
)
'and specify the func_name'
)
def
load_c_code
(
self
):
def
load_c_code
(
self
,
func_files
):
"""
"""
Loads the c code to perform the Op
Loads the c code to perform the Op
"""
"""
func_files
=
[
self
.
get_path
(
f
)
for
f
in
func_files
]
self
.
func_codes
=
[]
self
.
func_codes
=
[]
for
func_file
in
self
.
func_files
:
for
func_file
in
func_files
:
with
open
(
func_file
,
'r'
)
as
f
:
with
open
(
func_file
,
'r'
)
as
f
:
self
.
func_codes
.
append
(
f
.
read
())
self
.
func_codes
.
append
(
f
.
read
())
...
@@ -1336,7 +1338,7 @@ class COp(Op):
...
@@ -1336,7 +1338,7 @@ class COp(Op):
if
split
[
0
]
.
strip
()
!=
''
:
if
split
[
0
]
.
strip
()
!=
''
:
raise
ValueError
(
'Stray code before first #section '
raise
ValueError
(
'Stray code before first #section '
'statement (in file
%
s):
%
s'
%
'statement (in file
%
s):
%
s'
%
(
self
.
func_files
[
i
],
split
[
0
]))
(
func_files
[
i
],
split
[
0
]))
# Separate the code into the proper sections
# Separate the code into the proper sections
n
=
1
n
=
1
...
@@ -1344,7 +1346,7 @@ class COp(Op):
...
@@ -1344,7 +1346,7 @@ class COp(Op):
if
split
[
n
]
not
in
self
.
SECTIONS
:
if
split
[
n
]
not
in
self
.
SECTIONS
:
raise
ValueError
(
raise
ValueError
(
"Unknown section type (in file
%
s):
%
s"
%
"Unknown section type (in file
%
s):
%
s"
%
(
self
.
func_files
[
i
],
split
[
n
]))
(
func_files
[
i
],
split
[
n
]))
if
split
[
n
]
not
in
self
.
code_sections
:
if
split
[
n
]
not
in
self
.
code_sections
:
self
.
code_sections
[
split
[
n
]]
=
""
self
.
code_sections
[
split
[
n
]]
=
""
self
.
code_sections
[
split
[
n
]]
+=
split
[
n
+
1
]
self
.
code_sections
[
split
[
n
]]
+=
split
[
n
+
1
]
...
@@ -1352,7 +1354,7 @@ class COp(Op):
...
@@ -1352,7 +1354,7 @@ class COp(Op):
else
:
else
:
raise
ValueError
(
"No valid section marker was found in file "
raise
ValueError
(
"No valid section marker was found in file "
"
%
s"
%
self
.
func_files
[
i
])
"
%
s"
%
func_files
[
i
])
def
get_op_params
(
self
):
def
get_op_params
(
self
):
"""
"""
...
...
theano/gof/type.py
浏览文件 @
cdac0c69
...
@@ -772,6 +772,15 @@ if (py_%(name)s == NULL) { %(freefunc)s(%(name)s); }
...
@@ -772,6 +772,15 @@ if (py_%(name)s == NULL) { %(freefunc)s(%(name)s); }
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
self
.
ctype
)
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
self
.
ctype
)
def
__setstate__
(
self
,
dct
):
self
.
__dict__
.
update
(
dct
)
if
not
hasattr
(
self
,
'headers'
):
self
.
headers
=
()
self
.
header_dirs
=
()
self
.
libraries
=
()
self
.
lib_dirs
=
()
self
.
extra_support_code
=
""
class
CDataTypeConstant
(
graph
.
Constant
):
class
CDataTypeConstant
(
graph
.
Constant
):
def
merge_signature
(
self
):
def
merge_signature
(
self
):
...
...
theano/sandbox/cuda/dnn.py
浏览文件 @
cdac0c69
...
@@ -354,26 +354,6 @@ class GpuDnnConv(DnnBase, COp):
...
@@ -354,26 +354,6 @@ class GpuDnnConv(DnnBase, COp):
if
self
.
inplace
:
if
self
.
inplace
:
self
.
destroy_map
=
{
0
:
[
2
]}
self
.
destroy_map
=
{
0
:
[
2
]}
# In cuDNN version older than V3, the FFT implementation and the
# option to time the different implementations to get the fastest
# are both unavailable.
if
version
()
<
(
3000
,
3000
):
if
self
.
algo
==
'fft'
:
raise
RuntimeError
(
"cuDNN FFT convolution requires cuDNN v3"
)
elif
self
.
algo
in
[
'guess_once'
,
'guess_on_shape_change'
]:
raise
RuntimeError
(
"cuDNN selection of convolution "
"implementation based on heuristics "
"requires cuDNN v3"
)
elif
self
.
algo
in
[
'time_once'
,
'time_on_shape_change'
]:
raise
RuntimeError
(
"cuDNN convolution timing requires cuDNN "
"v3"
)
# The fft_tiling implementation is only available from cuDNN V4 onward
if
version
()
<
(
4000
,
4000
):
if
self
.
algo
==
'fft_tiling'
:
raise
RuntimeError
(
"cuDNN tiled-FFT convolution requires "
"cuDNN v4 or more recent"
)
if
version
()
<
(
5000
,
5000
):
if
version
()
<
(
5000
,
5000
):
if
self
.
algo
==
'winograd'
:
if
self
.
algo
==
'winograd'
:
raise
RuntimeError
(
"cuDNN winograd convolution requires "
raise
RuntimeError
(
"cuDNN winograd convolution requires "
...
@@ -392,6 +372,9 @@ class GpuDnnConv(DnnBase, COp):
...
@@ -392,6 +372,9 @@ class GpuDnnConv(DnnBase, COp):
self
.
algo
=
config
.
dnn
.
conv
.
algo_fwd
self
.
algo
=
config
.
dnn
.
conv
.
algo_fwd
if
not
hasattr
(
self
,
'inplace'
):
if
not
hasattr
(
self
,
'inplace'
):
self
.
inplace
=
False
self
.
inplace
=
False
# Work around to reload old pickle.
# We need to find the new file name and reload c code.
self
.
load_c_code
([
"dnn_base.c"
,
"dnn_conv_base.c"
,
"dnn_fwd.c"
])
def
get_op_params
(
self
):
def
get_op_params
(
self
):
if
self
.
inplace
:
if
self
.
inplace
:
...
@@ -656,6 +639,7 @@ class GpuDnnConvGradW(DnnBase, COp):
...
@@ -656,6 +639,7 @@ class GpuDnnConvGradW(DnnBase, COp):
self
.
algo
=
config
.
dnn
.
conv
.
algo_bwd_filter
self
.
algo
=
config
.
dnn
.
conv
.
algo_bwd_filter
if
not
hasattr
(
self
,
'inplace'
):
if
not
hasattr
(
self
,
'inplace'
):
self
.
inplace
=
False
self
.
inplace
=
False
self
.
load_c_code
([
"dnn_base.c"
,
"dnn_conv_base.c"
,
"dnn_gw.c"
])
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
img
,
top
,
output
,
desc
,
alpha
,
beta
=
inp
img
,
top
,
output
,
desc
,
alpha
,
beta
=
inp
...
@@ -865,13 +849,6 @@ class GpuDnnConvGradI(DnnBase, COp):
...
@@ -865,13 +849,6 @@ class GpuDnnConvGradI(DnnBase, COp):
if
self
.
inplace
:
if
self
.
inplace
:
self
.
destroy_map
=
{
0
:
[
2
]}
self
.
destroy_map
=
{
0
:
[
2
]}
# The small-workspace implementation is only available from cuDNN V4
# onward.
if
version
()
<
(
4000
,
4000
):
if
self
.
algo
==
'fft_tiling'
:
raise
RuntimeError
(
"cuDNN's tiled-FFT convolution requires "
"cuDNN v4 or more recent"
)
if
version
()
<
(
5000
,
5000
):
if
version
()
<
(
5000
,
5000
):
if
self
.
algo
==
'winograd'
:
if
self
.
algo
==
'winograd'
:
raise
RuntimeError
(
"cuDNN's winograd convolution requires "
raise
RuntimeError
(
"cuDNN's winograd convolution requires "
...
@@ -890,6 +867,7 @@ class GpuDnnConvGradI(DnnBase, COp):
...
@@ -890,6 +867,7 @@ class GpuDnnConvGradI(DnnBase, COp):
self
.
algo
=
config
.
dnn
.
conv
.
algo_bwd_data
self
.
algo
=
config
.
dnn
.
conv
.
algo_bwd_data
if
not
hasattr
(
self
,
'inplace'
):
if
not
hasattr
(
self
,
'inplace'
):
self
.
inplace
=
False
self
.
inplace
=
False
self
.
load_c_code
([
"dnn_base.c"
,
"dnn_conv_base.c"
,
"dnn_gi.c"
])
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
kerns
,
top
,
output
,
desc
,
alpha
,
beta
=
inp
kerns
,
top
,
output
,
desc
,
alpha
,
beta
=
inp
...
@@ -1465,13 +1443,6 @@ class GpuDnnPoolDesc(GpuOp):
...
@@ -1465,13 +1443,6 @@ class GpuDnnPoolDesc(GpuOp):
self
.
stride
=
stride
self
.
stride
=
stride
self
.
pad
=
pad
self
.
pad
=
pad
if
self
.
get_ndim
()
==
3
and
version
()
<
(
3000
,
3000
):
raise
RuntimeError
(
"cuDNN 3d pooling requires cuDNN v3"
)
if
(
mode
==
'average_exc_pad'
and
max
(
pad
)
>
0
and
version
()
<
(
4004
,
4004
)):
raise
RuntimeError
(
"cuDNN pooling mode 'average_exc_pad' requires at least v4"
)
def
get_ndim
(
self
):
def
get_ndim
(
self
):
return
len
(
self
.
ws
)
return
len
(
self
.
ws
)
...
@@ -2110,9 +2081,6 @@ class GpuDnnSoftmaxBase(DnnBase):
...
@@ -2110,9 +2081,6 @@ class GpuDnnSoftmaxBase(DnnBase):
DnnBase
.
__init__
(
self
)
DnnBase
.
__init__
(
self
)
self
.
tensor_format
=
tensor_format
self
.
tensor_format
=
tensor_format
if
algo
==
'log'
and
version
()
<
(
3000
,
3000
):
raise
RuntimeError
(
"cuDNN log-softmax requires cuDNN v3"
)
assert
(
algo
in
(
'fast'
,
'accurate'
,
'log'
))
assert
(
algo
in
(
'fast'
,
'accurate'
,
'log'
))
self
.
algo
=
algo
self
.
algo
=
algo
...
@@ -3179,7 +3147,7 @@ if True:
...
@@ -3179,7 +3147,7 @@ if True:
@local_optimizer
([
GpuElemwise
,
LogSoftmax
])
@local_optimizer
([
GpuElemwise
,
LogSoftmax
])
def
local_log_softmax_dnn
(
node
):
def
local_log_softmax_dnn
(
node
):
# The log-softmax implementation is only available starting at cuDNN V3
# The log-softmax implementation is only available starting at cuDNN V3
if
not
dnn_available
()
or
version
()
<
(
3000
,
3000
)
:
if
not
dnn_available
():
return
return
if
(
isinstance
(
node
.
op
,
GpuElemwise
)
and
if
(
isinstance
(
node
.
op
,
GpuElemwise
)
and
...
...
theano/scalar/basic.py
浏览文件 @
cdac0c69
...
@@ -3996,6 +3996,7 @@ class Composite(ScalarOp):
...
@@ -3996,6 +3996,7 @@ class Composite(ScalarOp):
def
__getstate__
(
self
):
def
__getstate__
(
self
):
rval
=
dict
(
self
.
__dict__
)
rval
=
dict
(
self
.
__dict__
)
rval
.
pop
(
'_impls'
,
None
)
rval
.
pop
(
'_impls'
,
None
)
rval
.
pop
(
'prepare_node_called'
,
None
)
del
rval
[
'fgraph'
]
del
rval
[
'fgraph'
]
return
rval
return
rval
...
@@ -4003,6 +4004,7 @@ class Composite(ScalarOp):
...
@@ -4003,6 +4004,7 @@ class Composite(ScalarOp):
self
.
__dict__
.
update
(
d
)
self
.
__dict__
.
update
(
d
)
# We must call init to set fgraph and _impls again, as otherwise
# We must call init to set fgraph and _impls again, as otherwise
# self.perform will not work.
# self.perform will not work.
self
.
prepare_node_called
=
set
()
self
.
init_fgraph
()
self
.
init_fgraph
()
self
.
init_py_impls
()
self
.
init_py_impls
()
assert
self
.
_c_code
assert
self
.
_c_code
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论