提交 aef67878 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #2297 from f0k/metaopt-again

conv2d meta-optimizer missing commits
......@@ -46,6 +46,16 @@
into Theano, and an implementation by Alex Krizhevsky available via
Pylearn2. See the documentation below on how to use them.
As of November 24th, 2014, you can also use a meta-optimizer to
automatically choose the fastest implementation for each specific
convolution in your graph. For each instance, it will compile and benchmark
each applicable implementation of the ones listed below and choose the
fastest one. As performance is dependent on input and filter shapes, this
only works for operations introduced via nnet.conv2d with fully specified
shape information.
Enable it via the Theano flag ``optimizer_including=conv_meta``, and
optionally set it to verbose mode via the flag `metaopt.verbose=1`.
TODO: Give examples on how to use these things! They are pretty complicated.
......
......@@ -823,6 +823,10 @@ class LocalOptimizer(object):
(' ' * level), self.__class__.__name__, id(self))
theano.configparser.AddConfigVar('metaopt.verbose',
"Enable verbose output for meta optimizers",
theano.configparser.BoolParam(False), in_c_key=False)
class LocalMetaOptimizer(LocalOptimizer):
"""Base class for meta-optimizers that try a set of LocalOptimizers
to replace a node and choose the one that executes the fastest"""
......@@ -830,7 +834,7 @@ class LocalMetaOptimizer(LocalOptimizer):
def __init__(self, tracks=None, optimizers=()):
self._tracks = tracks
self.optimizers = list(optimizers)
self.verbose = False
self.verbose = config.metaopt.verbose
def register(self, optimizer):
self.optimizers.append(optimizer)
......@@ -876,10 +880,7 @@ class LocalMetaOptimizer(LocalOptimizer):
outputs = opt.transform(node)
if outputs:
try:
fn = theano.function([],
[theano.Out(output, borrow=True)
for output in outputs],
givens=givens)
fn = theano.function([], outputs, givens=givens)
timing = min(self.time_call(fn) for _ in range(3))
except Exception as e:
if self.verbose:
......
......@@ -1361,14 +1361,9 @@ class LocalCudaMetaOptimizer(LocalMetaOptimizer):
# Convolution Meta-optimizer
theano.configparser.AddConfigVar('conv_meta.verbose',
"Enable verbose output for conv_meta optimizer",
theano.configparser.BoolParam(False), in_c_key=False)
class ConvMetaOptimizer(LocalCudaMetaOptimizer):
def __init__(self, optimizers):
super(ConvMetaOptimizer, self).__init__([GpuConv], optimizers)
self.verbose = config.conv_meta.verbose
def provide_inputs(self, node, inputs):
# We need to provide dummy data for the given inputs.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论