Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
eace991b
提交
eace991b
authored
3月 23, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #562 from lamblin/test_preallocated_output_rebase
Checks for preallocated output memory, take 2
上级
1fcd0905
f94d63f4
全部展开
显示空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
82 行增加
和
40 行删除
+82
-40
config.txt
doc/library/config.txt
+3
-1
builders.py
theano/compile/builders.py
+6
-1
debugmode.py
theano/compile/debugmode.py
+0
-0
test_debugmode.py
theano/compile/tests/test_debugmode.py
+4
-1
__init__.py
theano/gof/__init__.py
+1
-1
op.py
theano/gof/op.py
+14
-0
test_blas.py
theano/sandbox/cuda/tests/test_blas.py
+0
-5
type.py
theano/sandbox/cuda/type.py
+5
-0
scan_op.py
theano/scan_module/scan_op.py
+7
-2
basic.py
theano/tensor/basic.py
+7
-0
elemwise.py
theano/tensor/elemwise.py
+34
-28
opt.py
theano/tensor/opt.py
+1
-1
没有找到文件。
doc/library/config.txt
浏览文件 @
eace991b
...
@@ -380,7 +380,7 @@ import theano and print the config variable, as in:
...
@@ -380,7 +380,7 @@ import theano and print the config variable, as in:
.. attribute:: config.DebugMode.check_preallocated_output
.. attribute:: config.DebugMode.check_preallocated_output
Default: ``'
ALL
'``
Default: ``''``
A list of kinds of preallocated memory to use as output buffers for
A list of kinds of preallocated memory to use as output buffers for
each Op's computations, separated by ``:``. Implemented modes are:
each Op's computations, separated by ``:``. Implemented modes are:
...
@@ -388,6 +388,8 @@ import theano and print the config variable, as in:
...
@@ -388,6 +388,8 @@ import theano and print the config variable, as in:
* ``"previous"``: reuse previously-returned memory,
* ``"previous"``: reuse previously-returned memory,
* ``"c_contiguous"``: newly-allocated C-contiguous memory,
* ``"c_contiguous"``: newly-allocated C-contiguous memory,
* ``"f_contiguous"``: newly-allocated Fortran-contiguous memory,
* ``"f_contiguous"``: newly-allocated Fortran-contiguous memory,
* ``"strided"``: non-contiguous memory with various stride patterns,
* ``"wrong_size"``: memory with bigger or smaller dimensions,
* ``"ALL"``: placeholder for all of the above.
* ``"ALL"``: placeholder for all of the above.
In order not to test with preallocated memory, use an empty string, ``""``.
In order not to test with preallocated memory, use an empty string, ``""``.
...
...
theano/compile/builders.py
浏览文件 @
eace991b
from
theano
import
gof
from
theano
import
gof
from
theano
import
gradient
as
G
from
theano
import
gradient
as
G
from
function_module
import
orig_function
from
theano.compile.function_module
import
orig_function
from
theano.gof
import
ops_with_inner_function
class
OpFromGraph
(
gof
.
Op
):
class
OpFromGraph
(
gof
.
Op
):
...
@@ -99,3 +100,7 @@ class OpFromGraph(gof.Op):
...
@@ -99,3 +100,7 @@ class OpFromGraph(gof.Op):
return
[
go
(
*
(
inputs
+
output_grads
))
for
go
in
self
.
grad_ops
]
return
[
go
(
*
(
inputs
+
output_grads
))
for
go
in
self
.
grad_ops
]
else
:
else
:
raise
NotImplementedError
raise
NotImplementedError
# Since OpFromGraph contains a Theano compiled function, we should let
# DebugMode know about it
ops_with_inner_function
[
OpFromGraph
]
=
'fn'
theano/compile/debugmode.py
浏览文件 @
eace991b
差异被折叠。
点击展开。
theano/compile/tests/test_debugmode.py
浏览文件 @
eace991b
...
@@ -264,7 +264,10 @@ def test_stochasticoptimization():
...
@@ -264,7 +264,10 @@ def test_stochasticoptimization():
try
:
try
:
theano
.
function
([
a
,
b
],
theano
.
function
([
a
,
b
],
theano
.
tensor
.
add
(
a
,
b
),
theano
.
tensor
.
add
(
a
,
b
),
mode
=
debugmode
.
DebugMode
(
optimizer
=
opt
,
check_c_code
=
True
))
mode
=
debugmode
.
DebugMode
(
optimizer
=
opt
,
check_c_code
=
True
,
stability_patience
=
max
(
2
,
config
.
DebugMode
.
patience
)))
except
debugmode
.
StochasticOrder
:
except
debugmode
.
StochasticOrder
:
return
# TEST PASS
return
# TEST PASS
assert
False
assert
False
...
...
theano/gof/__init__.py
浏览文件 @
eace991b
...
@@ -18,7 +18,7 @@ from link import \
...
@@ -18,7 +18,7 @@ from link import \
Container
,
Linker
,
LocalLinker
,
PerformLinker
,
WrapLinker
,
WrapLinkerMany
Container
,
Linker
,
LocalLinker
,
PerformLinker
,
WrapLinker
,
WrapLinkerMany
from
op
import
\
from
op
import
\
Op
,
PureOp
Op
,
PureOp
,
ops_with_inner_function
from
opt
import
(
Optimizer
,
optimizer
,
SeqOptimizer
,
from
opt
import
(
Optimizer
,
optimizer
,
SeqOptimizer
,
MergeOptimizer
,
MergeOptMerge
,
MergeOptimizer
,
MergeOptMerge
,
...
...
theano/gof/op.py
浏览文件 @
eace991b
...
@@ -717,3 +717,17 @@ def get_debug_values(*args):
...
@@ -717,3 +717,17 @@ def get_debug_values(*args):
return
rval
return
rval
return
[
tuple
(
rval
)]
return
[
tuple
(
rval
)]
ops_with_inner_function
=
{}
"""
Registry of Ops that have an inner compiled Theano function.
The keys are Op classes (not instances), and values are the name of the
attribute that contains the function. For instance, if the function is
self.fn, the value will be 'fn'.
We need that to be able not to run debug checks a number of times that is
exponential in the nesting level of those ops.
For instance, Scan will be registered here.
"""
theano/sandbox/cuda/tests/test_blas.py
浏览文件 @
eace991b
...
@@ -37,11 +37,6 @@ def my_rand(*shape):
...
@@ -37,11 +37,6 @@ def my_rand(*shape):
return
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
return
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
def
transpose
(
cuda_mat
):
# The easiest way to transpose a cuda matrix for now
return
tcn
.
dimshuffle
(
cuda_mat
,
[
1
,
0
])
def
test_dot22
():
def
test_dot22
():
def
cmp
(
a_shp
,
b_shp
):
def
cmp
(
a_shp
,
b_shp
):
a0
=
my_rand
(
*
a_shp
)
a0
=
my_rand
(
*
a_shp
)
...
...
theano/sandbox/cuda/type.py
浏览文件 @
eace991b
...
@@ -54,6 +54,11 @@ class CudaNdarrayType(Type):
...
@@ -54,6 +54,11 @@ class CudaNdarrayType(Type):
A cyclic dependency is avoided by not hardcoding this class.
A cyclic dependency is avoided by not hardcoding this class.
"""
"""
value_zeros
=
staticmethod
(
cuda
.
CudaNdarray
.
zeros
)
"""
Create an CudaNdarray full of 0 values
"""
def
__init__
(
self
,
broadcastable
,
name
=
None
,
dtype
=
None
):
def
__init__
(
self
,
broadcastable
,
name
=
None
,
dtype
=
None
):
if
dtype
!=
None
and
dtype
!=
'float32'
:
if
dtype
!=
None
and
dtype
!=
'float32'
:
raise
TypeError
(
'
%
s only supports dtype float32 for now. Tried '
raise
TypeError
(
'
%
s only supports dtype float32 for now. Tried '
...
...
theano/scan_module/scan_op.py
浏览文件 @
eace991b
...
@@ -278,8 +278,8 @@ class Scan(PureOp):
...
@@ -278,8 +278,8 @@ class Scan(PureOp):
str
(
outer_mitsot
),
str
(
outer_mitsot
),
argoffset
+
idx
,
argoffset
+
idx
,
outer_mitsot
.
type
.
dtype
,
outer_mitsot
.
type
.
dtype
,
o
tu
er_mitsot
.
type
.
ndim
,
o
ut
er_mitsot
.
type
.
ndim
,
str
(
inner_mitsot
[
ipos
+
k
]),
str
(
inner_mitsot
s
[
ipos
+
k
]),
inner_mitsots
[
ipos
+
k
]
.
type
.
dtype
,
inner_mitsots
[
ipos
+
k
]
.
type
.
dtype
,
inner_mitsots
[
ipos
+
k
]
.
type
.
ndim
))
inner_mitsots
[
ipos
+
k
]
.
type
.
ndim
))
ipos
+=
len
(
itaps
)
ipos
+=
len
(
itaps
)
...
@@ -1676,6 +1676,11 @@ class Scan(PureOp):
...
@@ -1676,6 +1676,11 @@ class Scan(PureOp):
return
final_outs
return
final_outs
# Since Scan is an op that contains a Theano compiled function, it is
# useful to let DebugMode know about it.
gof
.
ops_with_inner_function
[
Scan
]
=
'fn'
@theano.compile.profilemode.register_profiler_printer
@theano.compile.profilemode.register_profiler_printer
def
profile_printer
(
fct_name
,
compile_time
,
fct_call_time
,
fct_call
,
def
profile_printer
(
fct_name
,
compile_time
,
fct_call_time
,
fct_call
,
apply_time
,
apply_cimpl
,
message
,
outputs_size
,
apply_time
,
apply_cimpl
,
message
,
outputs_size
,
...
...
theano/tensor/basic.py
浏览文件 @
eace991b
...
@@ -1024,6 +1024,13 @@ class TensorType(Type):
...
@@ -1024,6 +1024,13 @@ class TensorType(Type):
else
:
else
:
return
()
return
()
def
value_zeros
(
self
,
shape
):
"""
Create an numpy ndarray full of 0 values.
"""
return
numpy
.
zeros
(
shape
,
dtype
=
self
.
dtype
)
# Register CudaNdarrayType to the OutputGuard list of known types
# Register CudaNdarrayType to the OutputGuard list of known types
# to have OutputGuard generate C code for this type.
# to have OutputGuard generate C code for this type.
theano
.
compile
.
mode
.
register_OutputGuard_c_code
(
TensorType
)
theano
.
compile
.
mode
.
register_OutputGuard_c_code
(
TensorType
)
...
...
theano/tensor/elemwise.py
浏览文件 @
eace991b
...
@@ -742,34 +742,45 @@ class Elemwise(Op):
...
@@ -742,34 +742,45 @@ class Elemwise(Op):
raise
ValueError
(
'
\n
'
.
join
(
msg_chunks
))
raise
ValueError
(
'
\n
'
.
join
(
msg_chunks
))
else
:
else
:
raise
ValueError
(
base_exc_str
)
raise
ValueError
(
base_exc_str
)
# Other mismatches will be caught by the ufunc
# Determine the shape of outputs
out_shape
=
[]
for
values
in
zip
(
*
[
input
.
shape
for
input
in
inputs
]):
if
numpy
.
prod
(
values
)
==
0
:
# All non-broadcasted dimensions should be zero
assert
max
(
values
)
<=
1
out_shape
.
append
(
0
)
else
:
out_shape
.
append
(
max
(
values
))
out_shape
=
tuple
(
out_shape
)
if
not
self
.
inplace_pattern
:
if
not
self
.
inplace_pattern
:
for
output
,
storage
in
zip
(
node
.
outputs
,
output_storage
):
for
output
,
storage
in
zip
(
node
.
outputs
,
output_storage
):
odat
=
storage
[
0
]
odat
=
storage
[
0
]
shape
=
[
max
(
values
)
for
values
in
zip
(
*
[
input
.
shape
for
input
in
inputs
])]
if
odat
is
not
None
:
if
odat
is
not
None
:
# reuse storage if we can
if
odat
.
shape
!=
out_shape
:
odat
.
resize
(
shape
,
refcheck
=
0
)
# It is unsafe to try to resize odat,
else
:
# we have to allocate output storage.
odat
=
numpy
.
ndarray
(
shape
,
dtype
=
output
.
type
.
dtype
)
odat
=
None
if
odat
is
None
:
odat
=
numpy
.
ndarray
(
out_shape
,
dtype
=
output
.
type
.
dtype
)
storage
[
0
]
=
odat
storage
[
0
]
=
odat
else
:
else
:
for
i
,
(
output
,
storage
)
in
enumerate
(
zip
(
node
.
outputs
,
for
i
,
(
output
,
storage
)
in
enumerate
(
output_storage
)):
zip
(
node
.
outputs
,
output_storage
)):
#i is an output idx
#i is an output idx
if
i
in
self
.
inplace_pattern
:
if
i
in
self
.
inplace_pattern
:
odat
=
inputs
[
self
.
inplace_pattern
[
i
]]
odat
=
inputs
[
self
.
inplace_pattern
[
i
]]
else
:
else
:
odat
=
storage
[
0
]
odat
=
storage
[
0
]
shape
=
[
max
(
values
)
for
values
in
zip
(
*
[
input
.
shape
for
input
in
inputs
])]
if
odat
is
not
None
:
if
odat
is
not
None
:
odat
.
resize
(
shape
,
refcheck
=
0
)
if
odat
.
shape
!=
out_shape
:
else
:
# It is unsafe to try to resize odat,
odat
=
numpy
.
ndarray
(
shape
,
dtype
=
output
.
type
.
dtype
)
# we have to allocate output storage.
odat
=
None
if
odat
is
None
:
odat
=
numpy
.
ndarray
(
out_shape
,
dtype
=
output
.
type
.
dtype
)
storage
[
0
]
=
odat
storage
[
0
]
=
odat
ufunc_args
=
inputs
# + output_storage
ufunc_args
=
inputs
# + output_storage
...
@@ -825,21 +836,16 @@ class Elemwise(Op):
...
@@ -825,21 +836,16 @@ class Elemwise(Op):
# always return an ndarray with dtype object
# always return an ndarray with dtype object
variable
=
numpy
.
asarray
(
variable
,
dtype
=
nout
.
dtype
)
variable
=
numpy
.
asarray
(
variable
,
dtype
=
nout
.
dtype
)
if
(
hasattr
(
variable
,
'shape'
)
# The storage has been resized earlier.
and
storage
[
0
]
.
shape
!=
variable
.
shape
):
if
hasattr
(
variable
,
'shape'
):
if
numpy
.
prod
(
variable
.
shape
)
==
0
:
assert
storage
[
0
]
.
shape
==
variable
.
shape
# numpy don't resize from a shape (1,5) to (0,5)
# This bypass the inplace...
# But I it is important in this case.
storage
[
0
]
=
variable
continue
storage
[
0
]
.
resize
(
variable
.
shape
)
if
storage
[
0
]
.
shape
:
storage
[
0
][:]
=
variable
else
:
else
:
storage
[
0
]
.
itemset
(
variable
)
# If variable has not shape, then it is a scalar.
assert
numpy
.
prod
(
storage
[
0
]
.
shape
)
==
1
storage
[
0
][
...
]
=
variable
assert
str
(
storage
[
0
]
.
dtype
)
!=
'object'
assert
str
(
storage
[
0
]
.
dtype
)
!=
'object'
# the following should be used instead of the previous loop,
# the following should be used instead of the previous loop,
# unfortunately it tends to segfault
# unfortunately it tends to segfault
# self.ufunc(*(ufunc_args+[s[0] for s in output_storage]))
# self.ufunc(*(ufunc_args+[s[0] for s in output_storage]))
...
...
theano/tensor/opt.py
浏览文件 @
eace991b
...
@@ -521,7 +521,7 @@ class MakeVector(T.Op):
...
@@ -521,7 +521,7 @@ class MakeVector(T.Op):
def
perform
(
self
,
node
,
inputs
,
out_
):
def
perform
(
self
,
node
,
inputs
,
out_
):
out
,
=
out_
out
,
=
out_
# not calling theano._asarray as optimization
# not calling theano._asarray as optimization
if
out
[
0
]
is
None
:
if
(
out
[
0
]
is
None
)
or
(
out
[
0
]
.
size
!=
len
(
inputs
))
:
out
[
0
]
=
theano
.
_asarray
(
inputs
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
out
[
0
]
=
theano
.
_asarray
(
inputs
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
else
:
else
:
# assume that out has correct dtype. there is no cheap way to check
# assume that out has correct dtype. there is no cheap way to check
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论