提交 ea0d37ec authored 作者: sentient07's avatar sentient07

Reduced unwanted code

上级 d7688cea
...@@ -342,7 +342,8 @@ class GraphToGPU(NavigatorOptimizer): ...@@ -342,7 +342,8 @@ class GraphToGPU(NavigatorOptimizer):
break break
if (not move_to_GPU and if (not move_to_GPU and
isinstance(node.op, (theano.tensor.Alloc, isinstance(node.op, (theano.tensor.Alloc,
theano.tensor.AllocEmpty))): theano.tensor.AllocEmpty,
theano.tensor.basic.Eye))):
# If the Alloc[Empty] have a client that will be moved # If the Alloc[Empty] have a client that will be moved
# to the GPU, we should move the Alloc* on the GPU. # to the GPU, we should move the Alloc* on the GPU.
...@@ -762,9 +763,7 @@ def local_gpua_dimshuffle(op, context_name, inputs, outputs): ...@@ -762,9 +763,7 @@ def local_gpua_dimshuffle(op, context_name, inputs, outputs):
def local_gpua_specifyShape(op, context_name, inputs, outputs): def local_gpua_specifyShape(op, context_name, inputs, outputs):
if isinstance(inputs[0].type, GpuArrayType): if isinstance(inputs[0].type, GpuArrayType):
return return
inp = [as_gpuarray_variable(inputs[0], context_name)] return local_gpua_specifyShape_graph(op, context_name, inputs, outputs)
inp += inputs[1:]
return tensor.specify_shape(*inp)
@register_opt2([tensor.SpecifyShape], 'fast_compile') @register_opt2([tensor.SpecifyShape], 'fast_compile')
...@@ -781,13 +780,11 @@ def local_gpua_shape(op, context_name, inputs, outputs): ...@@ -781,13 +780,11 @@ def local_gpua_shape(op, context_name, inputs, outputs):
# always on the CPU. # always on the CPU.
if isinstance(inputs[0].type, GpuArrayType): if isinstance(inputs[0].type, GpuArrayType):
return return
return [as_gpuarray_variable(inputs[0], context_name).shape] return local_gpua_shape_graph(op, context_name, inputs, outputs)
@register_opt2([tensor.compile.ops.Shape], 'fast_compile') @register_opt2([tensor.compile.ops.Shape], 'fast_compile')
def local_gpua_shape_graph(op, context_name, inputs, outputs): def local_gpua_shape_graph(op, context_name, inputs, outputs):
# op_lifter will call this opt too frequently as the output is
# always on the CPU.
return [as_gpuarray_variable(inputs[0], context_name).shape] return [as_gpuarray_variable(inputs[0], context_name).shape]
...@@ -1209,7 +1206,7 @@ def local_gpua_dot22scalar(op, context_name, inputs, outputs): ...@@ -1209,7 +1206,7 @@ def local_gpua_dot22scalar(op, context_name, inputs, outputs):
@op_lifter([tensor.basic.Eye]) @op_lifter([tensor.basic.Eye])
@register_opt2([tensor.basic.Eye], 'fast_compile') @register_opt2([tensor.basic.Eye], 'fast_compile')
def local_gpua_eye(op, context_name, inputs, outputs): def local_gpua_eye(op, context_name, inputs, outputs):
return GpuEye(dtype=op.dtype, context_name=context_name) return [GpuEye(dtype=op.dtype, context_name=context_name)(*inputs)]
@register_opt('fast_compile') @register_opt('fast_compile')
...@@ -1245,8 +1242,7 @@ def local_gpua_softmaxwithbias(op, context_name, inputs, outputs): ...@@ -1245,8 +1242,7 @@ def local_gpua_softmaxwithbias(op, context_name, inputs, outputs):
def local_assert(op, context_name, inputs, outputs): def local_assert(op, context_name, inputs, outputs):
if isinstance(inputs[0].type, GpuArrayType): if isinstance(inputs[0].type, GpuArrayType):
return return
return [op(as_gpuarray_variable(inputs[0], context_name), return local_assert_graph(op, context_name, inputs, outputs)
*inputs[1:])]
@register_opt2([theano.tensor.opt.Assert], 'fast_compile') @register_opt2([theano.tensor.opt.Assert], 'fast_compile')
...@@ -1310,12 +1306,7 @@ def local_lift_abstractconv2d(op, context_name, inputs, outputs): ...@@ -1310,12 +1306,7 @@ def local_lift_abstractconv2d(op, context_name, inputs, outputs):
if isinstance(outputs[0].type, GpuArrayType): if isinstance(outputs[0].type, GpuArrayType):
# Don't handle this node here, it's already on the GPU. # Don't handle this node here, it's already on the GPU.
return return
inps = list(inputs) local_lift_abstractconv2d_graph(op, context_name, inputs, outputs)
inps[0] = as_gpuarray_variable(inputs[0],
context_name=context_name)
inps[1] = as_gpuarray_variable(inputs[1],
context_name=context_name)
return [op(*inps)]
@register_opt2([AbstractConv2d, @register_opt2([AbstractConv2d,
......
...@@ -396,7 +396,7 @@ def test_gpueye(): ...@@ -396,7 +396,7 @@ def test_gpueye():
k_symb = numpy.asarray(0) k_symb = numpy.asarray(0)
out = T.eye(N_symb, M_symb, k_symb, dtype=dtype) out = T.eye(N_symb, M_symb, k_symb, dtype=dtype)
f = theano.function([N_symb, M_symb], f = theano.function([N_symb, M_symb],
out, T.stack(out),
mode=mode_with_gpu) mode=mode_with_gpu)
result = numpy.asarray(f(N, M)) result = numpy.asarray(f(N, M))
assert numpy.allclose(result, numpy.eye(N, M_, dtype=dtype)) assert numpy.allclose(result, numpy.eye(N, M_, dtype=dtype))
......
...@@ -1477,8 +1477,6 @@ class UnShapeOptimizer(Optimizer): ...@@ -1477,8 +1477,6 @@ class UnShapeOptimizer(Optimizer):
# Register it after merge1 optimization at 0. We don't want to track # Register it after merge1 optimization at 0. We don't want to track
# the shape of merged node. # the shape of merged node.
# As local_shape_to_shape_i is not in fast_compile,
# dont register this opt in fast_compile.
theano.compile.mode.optdb.register('ShapeOpt', ShapeOptimizer(), theano.compile.mode.optdb.register('ShapeOpt', ShapeOptimizer(),
0.1, 'fast_run', 'fast_compile') 0.1, 'fast_run', 'fast_compile')
# Not enabled by default for now. Some crossentropy opt use the # Not enabled by default for now. Some crossentropy opt use the
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论