Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8df7d385
提交
8df7d385
authored
3月 17, 2014
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1770 from nouiz/fast_compile
Bug and crash fix in fast_compile
上级
1783f4e9
de9cd253
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
48 行增加
和
19 行删除
+48
-19
__init__.py
theano/gof/__init__.py
+4
-1
opt.py
theano/gof/opt.py
+31
-7
opt.py
theano/sandbox/cuda/opt.py
+3
-3
opt.py
theano/sandbox/gpuarray/opt.py
+4
-1
blas.py
theano/tensor/blas.py
+3
-4
opt.py
theano/tensor/opt.py
+3
-3
没有找到文件。
theano/gof/__init__.py
浏览文件 @
8df7d385
...
...
@@ -57,7 +57,10 @@ from theano.gof.link import \
from
theano.gof.op
import
\
Op
,
OpenMPOp
,
PureOp
,
ops_with_inner_function
from
theano.gof.opt
import
(
Optimizer
,
optimizer
,
SeqOptimizer
,
from
theano.gof.opt
import
(
Optimizer
,
optimizer
,
inplace_optimizer
,
SeqOptimizer
,
MergeOptimizer
,
MergeOptMerge
,
LocalOptimizer
,
local_optimizer
,
LocalOptGroup
,
OpSub
,
OpRemove
,
PatternSub
,
...
...
theano/gof/opt.py
浏览文件 @
8df7d385
...
...
@@ -114,13 +114,13 @@ class Optimizer(object):
class
FromFunctionOptimizer
(
Optimizer
):
"""WRITEME"""
def
__init__
(
self
,
fn
):
def
__init__
(
self
,
fn
,
requirements
=
()
):
self
.
apply
=
fn
self
.
requirements
=
requirements
def
add_requirements
(
self
,
fgraph
):
# Added by default
#fgraph.attach_feature(toolbox.ReplaceValidate())
pass
for
req
in
self
.
requirements
:
req
(
fgraph
)
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
print
>>
stream
,
"
%
s
%
s id=
%
i"
%
(
...
...
@@ -142,6 +142,16 @@ def optimizer(f):
return
rval
def
inplace_optimizer
(
f
):
"""decorator for FromFunctionOptimizer"""
dh_handler
=
dh
.
DestroyHandler
requirements
=
(
lambda
fgraph
:
fgraph
.
attach_feature
(
dh_handler
()),)
rval
=
FromFunctionOptimizer
(
f
,
requirements
)
rval
.
__name__
=
f
.
__name__
return
rval
class
SeqOptimizer
(
Optimizer
,
list
):
#inherit from Optimizer first to get Optimizer.__hash__
"""WRITEME
...
...
@@ -790,9 +800,14 @@ class LocalOptimizer(object):
class
FromFunctionLocalOptimizer
(
LocalOptimizer
):
"""WRITEME"""
def
__init__
(
self
,
fn
,
tracks
=
None
):
def
__init__
(
self
,
fn
,
tracks
=
None
,
requirements
=
()
):
self
.
transform
=
fn
self
.
_tracks
=
tracks
self
.
requirements
=
requirements
def
add_requirements
(
self
,
fgraph
):
for
req
in
self
.
requirements
:
req
(
fgraph
)
def
tracks
(
self
):
return
self
.
_tracks
...
...
@@ -808,7 +823,7 @@ class FromFunctionLocalOptimizer(LocalOptimizer):
id
(
self
))
def
local_optimizer
(
tracks
):
def
local_optimizer
(
tracks
,
inplace
=
False
):
def
decorator
(
f
):
"""WRITEME"""
if
tracks
is
not
None
:
...
...
@@ -817,7 +832,12 @@ def local_optimizer(tracks):
for
t
in
tracks
:
if
not
(
isinstance
(
t
,
op
.
Op
)
or
issubclass
(
t
,
op
.
PureOp
)):
raise
ValueError
,
(
"Tracks are op classes or instances"
,
f
.
__module__
,
f
.
__name__
)
rval
=
FromFunctionLocalOptimizer
(
f
,
tracks
)
requirements
=
()
if
inplace
:
dh_handler
=
dh
.
DestroyHandler
requirements
=
(
lambda
fgraph
:
fgraph
.
attach_feature
(
dh_handler
()),)
rval
=
FromFunctionLocalOptimizer
(
f
,
tracks
,
requirements
)
rval
.
__name__
=
f
.
__name__
return
rval
return
decorator
...
...
@@ -852,6 +872,10 @@ class LocalOptGroup(LocalOptimizer):
for
lopt
in
self
.
opts
:
lopt
.
print_summary
(
stream
,
level
=
(
level
+
2
),
depth
=
depth
)
def
add_requirements
(
self
,
fgraph
):
for
opt
in
self
.
opts
:
opt
.
add_requirements
(
fgraph
)
class
_LocalOpKeyOptGroup
(
LocalOptGroup
):
"""WRITEME"""
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
8df7d385
...
...
@@ -1214,19 +1214,19 @@ def local_gpujoin_1(node):
# shared = dimshuffle(gemm_inplace(dimshuffle(shared)))
# which causes memory leaks (long term fix is to make the above not leak
# memory)
@local_optimizer
([
gpu_gemm_no_inplace
])
@local_optimizer
([
gpu_gemm_no_inplace
]
,
inplace
=
True
)
def
local_inplace_gemm
(
node
):
if
node
.
op
==
gpu_gemm_no_inplace
:
return
[
gpu_gemm_inplace
(
*
node
.
inputs
)]
@local_optimizer
([
gpu_gemv_no_inplace
])
@local_optimizer
([
gpu_gemv_no_inplace
]
,
inplace
=
True
)
def
local_inplace_gemv
(
node
):
if
node
.
op
==
gpu_gemv_no_inplace
:
return
[
gpu_gemv_inplace
(
*
node
.
inputs
)]
@local_optimizer
([
gpu_ger_no_inplace
])
@local_optimizer
([
gpu_ger_no_inplace
]
,
inplace
=
True
)
def
local_inplace_ger
(
node
):
if
node
.
op
==
gpu_ger_no_inplace
:
return
[
gpu_ger_inplace
(
*
node
.
inputs
)]
...
...
theano/sandbox/gpuarray/opt.py
浏览文件 @
8df7d385
...
...
@@ -341,17 +341,20 @@ def local_gpua_crossentropysoftmaxargmax1hotwithbias(node):
@op_lifter
([
tensor
.
nnet
.
CrossentropySoftmax1HotWithBiasDx
])
def
local_gpua_crossentropysoftmax1hotwithbiasdx
(
node
):
return
GpuCrossentropySoftmax1HotWithBiasDx
()
@register_opt
()
@op_lifter
([
tensor
.
nnet
.
Softmax
])
def
local_gpua_softmax
(
node
):
return
GpuSoftmax
()
@register_opt
()
@op_lifter
([
tensor
.
nnet
.
SoftmaxWithBias
])
def
local_gpua_softmaxwithbias
(
node
):
return
GpuSoftmaxWithBias
()
@register_opt
()
@op_lifter
([
gpu_from_host
,
ConvOp
])
def
local_gpu_conv
(
node
):
...
...
theano/tensor/blas.py
浏览文件 @
8df7d385
...
...
@@ -1715,20 +1715,19 @@ def local_dot_to_dot22(node):
_logger
.
info
(
'Not optimizing dot with inputs
%
s
%
s
%
s
%
s'
,
x
,
y
,
x
.
type
,
y
.
type
)
@local_optimizer
([
gemm_no_inplace
])
@local_optimizer
([
gemm_no_inplace
],
inplace
=
True
)
def
local_inplace_gemm
(
node
):
if
node
.
op
==
gemm_no_inplace
:
return
[
gemm_inplace
(
*
node
.
inputs
)]
@local_optimizer
([
gemv_no_inplace
])
@local_optimizer
([
gemv_no_inplace
]
,
inplace
=
True
)
def
local_inplace_gemv
(
node
):
if
node
.
op
==
gemv_no_inplace
:
return
[
gemv_inplace
(
*
node
.
inputs
)]
@local_optimizer
([
ger
])
@local_optimizer
([
ger
]
,
inplace
=
True
)
def
local_inplace_ger
(
node
):
if
node
.
op
==
ger
:
return
[
ger_destructive
(
*
node
.
inputs
)]
...
...
theano/tensor/opt.py
浏览文件 @
8df7d385
...
...
@@ -174,7 +174,7 @@ def inplace_elemwise_optimizer_op(OP):
"""
We parametrise it to make it work for Elemwise and GpuElemwise op.
"""
@gof.optimizer
@gof.
inplace_
optimizer
def
inplace_elemwise_optimizer
(
fgraph
):
"""
Usage: inplace_elemwise_optimizer.optimize(fgraph)
...
...
@@ -2110,7 +2110,7 @@ compile.optdb.register('pre_local_IncSubtensor_serialize',
#after priority 50 Destructive inplace operations
#gemm is the first one now, at priority 70
@gof.local_optimizer
([
IncSubtensor
]
)
# XXX: GPU
@gof.local_optimizer
([
IncSubtensor
]
,
inplace
=
True
)
def
local_inplace_setsubtensor
(
node
):
"""
Also work for GpuIncSubtensor
...
...
@@ -2129,7 +2129,7 @@ compile.optdb.register('local_inplace_setsubtensor',
'fast_run'
,
'inplace'
)
# DEBUG
@gof.local_optimizer
([
AdvancedIncSubtensor1
]
)
# XXX: GPU
@gof.local_optimizer
([
AdvancedIncSubtensor1
]
,
inplace
=
True
)
def
local_inplace_incsubtensor1
(
node
):
""" also work for GpuAdvancedIncSubtensor1 """
if
isinstance
(
node
.
op
,
AdvancedIncSubtensor1
)
and
not
node
.
op
.
inplace
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论