Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8deed652
提交
8deed652
authored
12月 02, 2014
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2314 from nouiz/mixed
Fix test, compile less, doc, add tests.
上级
dce45cf8
96a7b3cb
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
84 行增加
和
3 行删除
+84
-3
cop.txt
doc/extending/cop.txt
+14
-0
function.txt
doc/library/compile/function.txt
+2
-0
index.txt
doc/library/index.txt
+5
-0
basic.txt
doc/library/tensor/basic.txt
+1
-0
conv.txt
doc/library/tensor/nnet/conv.txt
+1
-1
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+16
-0
test_conv_cuda_ndarray.py
theano/sandbox/cuda/tests/test_conv_cuda_ndarray.py
+14
-1
elemwise.py
theano/tensor/elemwise.py
+7
-0
opt.py
theano/tensor/opt.py
+13
-1
test_opt.py
theano/tensor/tests/test_opt.py
+11
-0
没有找到文件。
doc/extending/cop.txt
浏览文件 @
8deed652
...
@@ -184,6 +184,20 @@ There are less methods to define for an Op than for a Type:
...
@@ -184,6 +184,20 @@ There are less methods to define for an Op than for a Type:
Overrides :meth:`c_code_cache_version` if defined, but
Overrides :meth:`c_code_cache_version` if defined, but
otherwise has the same contract.
otherwise has the same contract.
.. method:: python_constant_folding(node)
Optional. If present this method will be called before doing
constant folding of a node, with that node as a parameter. If
it return True, we will not generate c code when doing constant
folding of this node. This is useful when the compilation of
the c code will be longer then the computation in python
(e.g. Elemwise of scalars).
In addition, this allow to lower the number of compiled module
and disk access. Particularly useful when the file system load
is high or when theano compilation directory is shared by many
process (like on a network file server on a cluster).
The ``name`` argument is currently given an invalid value, so steer
The ``name`` argument is currently given an invalid value, so steer
away from it. As was the case with Type, ``sub['fail']`` provides
away from it. As was the case with Type, ``sub['fail']`` provides
failure code that you *must* use if you want to raise an exception,
failure code that you *must* use if you want to raise an exception,
...
...
doc/library/compile/function.txt
浏览文件 @
8deed652
...
@@ -187,3 +187,5 @@ Reference
...
@@ -187,3 +187,5 @@ Reference
Replacements specified with
Replacements specified with
givens are different from optimizations in that Var2 is not expected to be
givens are different from optimizations in that Var2 is not expected to be
equivalent to Var1.
equivalent to Var1.
.. autofunction:: theano.compile.function.function_dump
doc/library/index.txt
浏览文件 @
8deed652
...
@@ -36,6 +36,11 @@ There are also some top-level imports that you might find more convenient:
...
@@ -36,6 +36,11 @@ There are also some top-level imports that you might find more convenient:
Alias for :func:`function.function`
Alias for :func:`function.function`
.. function:: function_dump(...)
Alias for :func:`theano.compile.function.function_dump`
.. function:: shared(...)
.. function:: shared(...)
Alias for :func:`shared.shared`
Alias for :func:`shared.shared`
...
...
doc/library/tensor/basic.txt
浏览文件 @
8deed652
...
@@ -474,6 +474,7 @@ TensorVariable
...
@@ -474,6 +474,7 @@ TensorVariable
* (2, 0, 1) -> AxBxC to CxAxB
* (2, 0, 1) -> AxBxC to CxAxB
* (0, 'x', 1) -> AxB to Ax1xB
* (0, 'x', 1) -> AxB to Ax1xB
* (1, 'x', 0) -> AxB to Bx1xA
* (1, 'x', 0) -> AxB to Bx1xA
* (1,) -> This remove dimensions 0. It must be a broadcastable dimension (1xA to A)
.. method:: flatten(ndim=1)
.. method:: flatten(ndim=1)
...
...
doc/library/tensor/nnet/conv.txt
浏览文件 @
8deed652
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
.. note::
.. note::
As of October 21st, 2014, the default GPU image convolution
As of October 21st, 2014, the default GPU image convolution
changed: By default, if :ref:`cuDNN <
_
libdoc_cuda_dnn>`
changed: By default, if :ref:`cuDNN <libdoc_cuda_dnn>`
is available, we will use it, otherwise we will fall back to using the
is available, we will use it, otherwise we will fall back to using the
gemm version (slower then cuDNN in most cases, uses more memory, but
gemm version (slower then cuDNN in most cases, uses more memory, but
faster than the legacy version we used before).
faster than the legacy version we used before).
...
...
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
8deed652
...
@@ -129,6 +129,22 @@ def test_careduce():
...
@@ -129,6 +129,22 @@ def test_careduce():
((
4100
,
4
,
3
,
2
),[
1
]),((
4
,
4100
,
3
,
2
),[
1
]),((
4
,
3
,
4100
,
2
),[
1
]),((
4
,
3
,
2
,
4100
),[
1
]),
#0100
((
4100
,
4
,
3
,
2
),[
1
]),((
4
,
4100
,
3
,
2
),[
1
]),((
4
,
3
,
4100
,
2
),[
1
]),((
4
,
3
,
2
,
4100
),[
1
]),
#0100
((
4100
,
4
,
3
,
2
),[
2
]),((
4
,
4100
,
3
,
2
),[
2
]),((
4
,
3
,
4100
,
2
),[
2
]),((
4
,
3
,
2
,
4100
),[
2
]),
#0010
((
4100
,
4
,
3
,
2
),[
2
]),((
4
,
4100
,
3
,
2
),[
2
]),((
4
,
3
,
4100
,
2
),[
2
]),((
4
,
3
,
2
,
4100
),[
2
]),
#0010
((
4100
,
4
,
3
,
2
),[
3
]),((
4
,
4100
,
3
,
2
),[
3
]),((
4
,
3
,
4100
,
2
),[
3
]),((
4
,
3
,
2
,
4100
),[
3
]),
#0001
((
4100
,
4
,
3
,
2
),[
3
]),((
4
,
4100
,
3
,
2
),[
3
]),((
4
,
3
,
4100
,
2
),[
3
]),((
4
,
3
,
2
,
4100
),[
3
]),
#0001
# reduce over 2d
((
4100
,
4
,
3
,
2
),[
1
,
2
]),((
4
,
4100
,
3
,
2
),[
1
,
2
]),((
4
,
3
,
4100
,
2
),[
1
,
2
]),((
4
,
3
,
2
,
4100
),[
1
,
2
]),
#0110
# ((4100,4,3,2),[0,3]),((4,4100,3,2),[0,3]),((4,3,4100,2),[0,3]),((4,3,2,4100),[0,3]),#1001 need 101
# ((4100,4,3,2),[0,2]),((4,4100,3,2),[0,2]),((4,3,4100,2),[0,2]),((4,3,2,4100),[0,2]),#1010 not implemented
((
4100
,
4
,
3
,
2
),[
0
,
1
]),((
4
,
4100
,
3
,
2
),[
0
,
1
]),((
4
,
3
,
4100
,
2
),[
0
,
1
]),((
4
,
3
,
2
,
4100
),[
0
,
1
]),
#1100
# reduce over 3d
# 3d not tested: 1101, 1110, 1111
# ((4100,4,3,2),[0,1,3]),((4,4100,3,2),[0,1,3]),((4,3,4100,2),[0,1,3]),((4,3,2,4100),[0,1,3]),#1101 need 101
((
4100
,
4
,
3
,
2
),[
0
,
1
,
2
]),((
4
,
4100
,
3
,
2
),[
0
,
1
,
2
]),((
4
,
3
,
4100
,
2
),[
0
,
1
,
2
]),((
4
,
3
,
2
,
4100
),[
0
,
1
,
2
]),
#1110
# reduce over 4d
((
4100
,
4
,
3
,
2
),[
0
]),((
4
,
4100
,
3
,
2
),[
0
]),((
4
,
3
,
4100
,
2
),[
0
]),((
4
,
3
,
2
,
4100
),[
0
]),
#1111
# reduce over 5d
((
1100
,
2
,
3
,
4
,
5
),[
0
,
1
,
2
,
3
,
4
]),((
2
,
1100
,
3
,
4
,
5
),[
0
,
1
,
2
,
3
,
4
]),((
2
,
3
,
1100
,
4
,
5
),[
0
,
1
,
2
,
3
,
4
]),((
2
,
3
,
4
,
1100
,
5
),[
0
,
1
,
2
,
3
,
4
]),((
2
,
3
,
4
,
5
,
1100
),[
0
,
1
,
2
,
3
,
4
]),
#11111
((
1100
,
2
,
3
,
4
,
5
),[
0
,
1
,
2
,
3
,
4
]),((
2
,
1100
,
3
,
4
,
5
),[
0
,
1
,
2
,
3
,
4
]),((
2
,
3
,
1100
,
4
,
5
),[
0
,
1
,
2
,
3
,
4
]),((
2
,
3
,
4
,
1100
,
5
),[
0
,
1
,
2
,
3
,
4
]),((
2
,
3
,
4
,
5
,
1100
),[
0
,
1
,
2
,
3
,
4
]),
#11111
]:
]:
...
...
theano/sandbox/cuda/tests/test_conv_cuda_ndarray.py
浏览文件 @
8deed652
...
@@ -907,24 +907,37 @@ def gemm_directly(bs, ch, nf, rImg1, rImg2, rFlt1, rFlt2, subsx, subsy,
...
@@ -907,24 +907,37 @@ def gemm_directly(bs, ch, nf, rImg1, rImg2, rFlt1, rFlt2, subsx, subsy,
npy_img
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
ishape
),
dtype
=
'float32'
)
npy_img
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
ishape
),
dtype
=
'float32'
)
npy_kern
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
kshape
),
dtype
=
'float32'
)
npy_kern
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
kshape
),
dtype
=
'float32'
)
if
direction
==
'fprop'
:
i
=
cuda
.
CudaNdarrayType
(
i
=
cuda
.
CudaNdarrayType
(
broadcastable
=
[
sh
==
1
for
sh
in
npy_img
.
shape
])()
broadcastable
=
[
sh
==
1
for
sh
in
npy_img
.
shape
])()
k
=
cuda
.
CudaNdarrayType
(
k
=
cuda
.
CudaNdarrayType
(
broadcastable
=
[
sh
==
1
for
sh
in
npy_kern
.
shape
])()
broadcastable
=
[
sh
==
1
for
sh
in
npy_kern
.
shape
])()
if
direction
==
'fprop'
:
cpuval
=
py_conv
(
npy_img
,
npy_kern
,
'valid'
,
subsample
)
cpuval
=
py_conv
(
npy_img
,
npy_kern
,
'valid'
,
subsample
)
op
=
theano
.
sandbox
.
cuda
.
blas
.
GpuCorrMM
(
border_mode
=
'valid'
,
op
=
theano
.
sandbox
.
cuda
.
blas
.
GpuCorrMM
(
border_mode
=
'valid'
,
subsample
=
subsample
)(
i
,
k
)
subsample
=
subsample
)(
i
,
k
)
f
=
theano
.
function
([
i
,
k
],
op
,
mode
=
theano_mode
)
f
=
theano
.
function
([
i
,
k
],
op
,
mode
=
theano_mode
)
gpuval
=
f
(
npy_img
,
npy_kern
[:,:,::
-
1
,::
-
1
])
gpuval
=
f
(
npy_img
,
npy_kern
[:,:,::
-
1
,::
-
1
])
elif
direction
==
'bprop img'
:
elif
direction
==
'bprop img'
:
i
=
cuda
.
CudaNdarrayType
(
broadcastable
=
[
sh
==
1
for
sh
in
npy_kern
.
transpose
(
1
,
0
,
2
,
3
)
.
shape
])()
k
=
cuda
.
CudaNdarrayType
(
broadcastable
=
[
sh
==
1
for
sh
in
npy_img
.
shape
])()
cpuval
=
py_conv
(
npy_img
,
npy_kern
,
'full'
,
subsample
)
cpuval
=
py_conv
(
npy_img
,
npy_kern
,
'full'
,
subsample
)
op
=
theano
.
sandbox
.
cuda
.
blas
.
GpuCorrMM_gradInputs
(
op
=
theano
.
sandbox
.
cuda
.
blas
.
GpuCorrMM_gradInputs
(
border_mode
=
'valid'
,
subsample
=
subsample
)(
i
,
k
)
border_mode
=
'valid'
,
subsample
=
subsample
)(
i
,
k
)
f
=
theano
.
function
([
i
,
k
],
op
,
mode
=
theano_mode
)
f
=
theano
.
function
([
i
,
k
],
op
,
mode
=
theano_mode
)
gpuval
=
f
(
npy_kern
.
transpose
(
1
,
0
,
2
,
3
),
npy_img
)
gpuval
=
f
(
npy_kern
.
transpose
(
1
,
0
,
2
,
3
),
npy_img
)
elif
direction
==
'bprop kern'
:
elif
direction
==
'bprop kern'
:
i
=
cuda
.
CudaNdarrayType
(
broadcastable
=
[
sh
==
1
for
sh
in
npy_img
.
transpose
(
1
,
0
,
2
,
3
)
.
shape
])()
k
=
cuda
.
CudaNdarrayType
(
broadcastable
=
[
sh
==
1
for
sh
in
npy_kern
.
transpose
(
1
,
0
,
2
,
3
)
.
shape
])()
cpuval
=
py_conv
(
npy_img
,
npy_kern
,
'valid'
,
subsample
)
cpuval
=
py_conv
(
npy_img
,
npy_kern
,
'valid'
,
subsample
)
op
=
theano
.
sandbox
.
cuda
.
blas
.
GpuCorrMM_gradWeights
(
op
=
theano
.
sandbox
.
cuda
.
blas
.
GpuCorrMM_gradWeights
(
border_mode
=
'valid'
,
subsample
=
subsample
)(
i
,
k
)
border_mode
=
'valid'
,
subsample
=
subsample
)(
i
,
k
)
...
...
theano/tensor/elemwise.py
浏览文件 @
8deed652
...
@@ -1193,6 +1193,13 @@ class Elemwise(OpenMPOp):
...
@@ -1193,6 +1193,13 @@ class Elemwise(OpenMPOp):
else
:
else
:
return
()
return
()
def
python_constant_folding
(
self
,
node
):
"""
Return True if we do not want to compile c code
when doing constant folding of this node.
"""
return
node
.
outputs
[
0
]
.
ndim
==
0
# def elemwise_to_scal(fgraph):
# def elemwise_to_scal(fgraph):
# TODO: why is this commented out? should it be removed?
# TODO: why is this commented out? should it be removed?
# it has needed maintenance despite being commented
# it has needed maintenance despite being commented
...
...
theano/tensor/opt.py
浏览文件 @
8deed652
...
@@ -1605,7 +1605,7 @@ compile.optdb['specialize'].register('local_remove_all_assert',
...
@@ -1605,7 +1605,7 @@ compile.optdb['specialize'].register('local_remove_all_assert',
local_remove_all_assert
,
local_remove_all_assert
,
use_db_name_as_tag
=
False
)
use_db_name_as_tag
=
False
)
@register_specialize
@register_specialize
(
"local_alloc_elemwise"
)
@gof.local_optimizer
([
T
.
Elemwise
])
@gof.local_optimizer
([
T
.
Elemwise
])
def
local_elemwise_alloc
(
node
):
def
local_elemwise_alloc
(
node
):
"""
"""
...
@@ -4508,7 +4508,19 @@ def constant_folding(node):
...
@@ -4508,7 +4508,19 @@ def constant_folding(node):
for
o
in
node
.
outputs
:
for
o
in
node
.
outputs
:
storage_map
[
o
]
=
[
None
]
storage_map
[
o
]
=
[
None
]
compute_map
[
o
]
=
[
False
]
compute_map
[
o
]
=
[
False
]
if
(
hasattr
(
node
.
op
,
'python_constant_folding'
)
and
node
.
op
.
python_constant_folding
(
node
)):
old_value
=
getattr
(
node
.
op
,
'_op_use_c_code'
,
False
)
try
:
node
.
op
.
_op_use_c_code
=
False
thunk
=
node
.
op
.
make_thunk
(
node
,
storage_map
,
compute_map
,
[])
finally
:
node
.
op
.
_op_use_c_code
=
old_value
else
:
thunk
=
node
.
op
.
make_thunk
(
node
,
storage_map
,
compute_map
,
thunk
=
node
.
op
.
make_thunk
(
node
,
storage_map
,
compute_map
,
no_recycling
=
[])
no_recycling
=
[])
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
8deed652
...
@@ -3671,6 +3671,17 @@ def test_constant_folding():
...
@@ -3671,6 +3671,17 @@ def test_constant_folding():
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
assert
len
(
topo
)
==
2
# Test that we do not crash when constant folding elemwise scalar
# as they should not generate c code.
x
=
tensor
.
constant
(
3
)
assert
x
.
ndim
==
0
mode
=
theano
.
compile
.
get_mode
(
"FAST_COMPILE"
)
.
excluding
(
"fusion"
)
f
=
theano
.
function
([],
[
x
*
2
,
x
+
x
],
mode
=
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
2
assert
all
([
isinstance
(
n
.
op
,
DeepCopyOp
)
for
n
in
topo
])
def
test_constant_get_stabilized
():
def
test_constant_get_stabilized
():
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论