提交 7e241005 authored 作者: Pierre Luc Carrier's avatar Pierre Luc Carrier 提交者: --global

Optimizer in progress. This commit is just to allow Fred to give some feedback.

上级 4c4b7cc4
...@@ -63,6 +63,7 @@ from theano.tensor import nlinalg ...@@ -63,6 +63,7 @@ from theano.tensor import nlinalg
from theano.tensor import slinalg from theano.tensor import slinalg
from theano.tensor.nnet.Conv3D import Conv3D from theano.tensor.nnet.Conv3D import Conv3D
from theano.tests.breakpoint import PdbBreakpoint
try: try:
# We need to be able to import this file even if cuda isn't avail. # We need to be able to import this file even if cuda isn't avail.
...@@ -1140,6 +1141,43 @@ def local_gpu_print_op(node): ...@@ -1140,6 +1141,43 @@ def local_gpu_print_op(node):
return [host_from_gpu(new_op(gpu_x))] return [host_from_gpu(new_op(gpu_x))]
return False return False
@register_opt()
@local_optimizer([PdbBreakpoint])
def local_gpu_pdbbreakpoint_op(node):
if isinstance(node.op, PdbBreakpoint):
old_inputs = node.inputs
# Obtain the inputs to the new op. The condition (first input) should
# be left on the host but the other inputs can be taken from the GPU.
new_inputs = old_inputs[:1]
for inp in old_inputs[1:]:
if inp.owner and isinstance(inp.owner.op, HostFromGpu):
# Take the input directly from the gpu
new_inputs.append(inp.owner.inputs[0])
else:
new_inputs.append(inp)
# Only proceed further if one of the outputs to the op was a
# HostFromGpu
if new_inputs[1:] == old_inputs[1:]:
return False
# Apply the op on the new inputs
new_outputs = node.op(*new_inputs)
# For every output of the new op for which we took the corresponding
# input from the GPU instead of the host, we need to transfer the
# output back to the host before returning it.
for i in range(len(new_outputs)):
inp = old_inputs[i + 1]
if (inp.owner and isinstance(inp.owner.op, HostFromGpu)):
new_outputs[i] = host_from_gpu(new_outputs[i])
return new_outputs
return False
def cast(x, dtype): def cast(x, dtype):
stype = scal.Scalar(dtype) stype = scal.Scalar(dtype)
......
...@@ -60,6 +60,21 @@ class TestPdbBreakpoint(utt.InferShapeTester): ...@@ -60,6 +60,21 @@ class TestPdbBreakpoint(utt.InferShapeTester):
for i in range(len(gradients)): for i in range(len(gradients)):
numpy.testing.assert_allclose(gradients[i], expected_gradients[i]) numpy.testing.assert_allclose(gradients[i], expected_gradients[i])
def test_fprop(self):
input1_value = numpy.arange(9).reshape(3,3).astype("float32")
input2_value = 10.0
fct = theano.function([self.input1, self.input2],
[self.monitored_input1, self.monitored_input2])
output = fct(input1_value, input2_value)[:-1]
import pdb
pdb.set_trace()
expected_output = [numpy.ones((3, 3), dtype="float32"),
numpy.array(1., dtype="float32")]
def test_connection_pattern(self): def test_connection_pattern(self):
node = self.monitored_output.owner node = self.monitored_output.owner
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论