Repository: Theano/Theano

Issue:
AttributeError: <float64> has no test value with [device = cuda] and [optimizer=fast_run]
I get this traceback with optimizer = fast_run and device = cuda, but not with fast_compile, or cpu. Theano from master 048d0c4
my .theanorc:

```
[global]
device = cuda
compute_test_value = off
exception_verbosity=high
optimizer=fast_run
[lib]
cnmem = 1
```
traceback:

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/op.py", line 625, in __call__
    storage_map[ins] = [self._get_test_value(ins)]
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/op.py", line 581, in _get_test_value
    raise AttributeError('%s has no test value %s' % (v, detailed_err_msg))
AttributeError: <float64> has no test value 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alex/fireml/fire.py", line 148, in <module>
    run_train(args.model, args.weights, args.caffemodel, args.solver, args.emulate_caffe)
  File "/home/alex/fireml/fire.py", line 120, in run_train
    display=solver.display, average_loss=solver.average_loss, solver=solver)
  File "/home/alex/fireml/example/models/fireml/train.py", line 14, in __init__
    self.train_model = train_builder.theano_function(solver)
  File "/home/alex/fireml/example/models/fireml/builder.py", line 608, in theano_function
    self._train_func = self.build_train(solver, **theano_kwargs)
  File "/home/alex/fireml/example/models/fireml/builder.py", line 656, in build_train
    updates=updates, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/theano/compile/function.py", line 326, in function
    output_keys=output_keys)
  File "/usr/local/lib/python3.5/dist-packages/theano/compile/pfunc.py", line 486, in pfunc
    output_keys=output_keys)
  File "/usr/local/lib/python3.5/dist-packages/theano/compile/function_module.py", line 1795, in orig_function
    defaults)
  File "/usr/local/lib/python3.5/dist-packages/theano/compile/function_module.py", line 1661, in create
    input_storage=input_storage_lists, storage_map=storage_map)
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/link.py", line 699, in make_thunk
    storage_map=storage_map)[:3]
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/vm.py", line 1047, in make_all
    impl=impl))
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/op.py", line 935, in make_thunk
    no_recycling)
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/op.py", line 839, in make_c_thunk
    output_storage=node_output_storage)
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/cc.py", line 1190, in make_thunk
    keep_lock=keep_lock)
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/cc.py", line 1131, in __compile__
    keep_lock=keep_lock)
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/cc.py", line 1586, in cthunk_factory
    key=key, lnk=self, keep_lock=keep_lock)
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/cmodule.py", line 1122, in module_from_key
    src_code = lnk.get_src_code()
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/cc.py", line 1462, in get_src_code
    mod = self.get_dynamic_module()
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/cc.py", line 1506, in get_dynamic_module
    self.code_gen()
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/cc.py", line 801, in code_gen
    struct_init = op.c_init_code_struct(node, name, sub_struct)
  File "/usr/local/lib/python3.5/dist-packages/theano/gpuarray/elemwise.py", line 209, in c_init_code_struct
    support_code, kop = self._generate_op_string(node)
  File "/usr/local/lib/python3.5/dist-packages/theano/gpuarray/elemwise.py", line 163, in _generate_op_string
    scalar_op = scalar_op.clone_float32()
  File "/usr/local/lib/python3.5/dist-packages/theano/scalar/basic.py", line 3893, in clone_float32
    new_ins, new_outs = composite_f32.apply(self.fgraph)
  File "/usr/local/lib/python3.5/dist-packages/theano/scalar/basic.py", line 4058, in apply
    self.special[type(node.op)](node, mapping)
  File "/usr/local/lib/python3.5/dist-packages/theano/scalar/basic.py", line 4106, in handle_composite
    new_outs = new_op(*[mapping[i] for i in node.inputs], return_list=True)
  File "/usr/local/lib/python3.5/dist-packages/theano/gof/op.py", line 639, in __call__
    (i, ins, node, detailed_err_msg))
ValueError: ('The following error happened while compiling the node', GpuElemwise{Composite{((i0 * Composite{(i0 + (i1 * EQ(i2, i3) * i4))}(i1, i2, i3, i4, i5)) + (i6 * Composite{(i0 + (i1 * EQ(i2, i3) * i4))}(i1, i2, i3, i4, i5) * sgn(i7)))}}[]<gpuarray>(GpuArrayConstant{[[[[ 0.5]]]]}, GpuElemwise{Composite{(((i0 / i1) + i2) * i3)}}[]<gpuarray>.0, GpuArrayConstant{[[[[-1.]]]]}, InplaceGpuDimShuffle{0,x,1,2}.0, GpuElemwise{Composite{(i0 * (i1 + Abs(i1)))}}[]<gpuarray>.0, InplaceGpuDimShuffle{0,x,1,2}.0, GpuArrayConstant{[[[[ 0.5]]]]}, GpuElemwise{add,no_inplace}.0), '\n', 'Cannot compute test value: input 0 (<float64>) of Op Composite{(i0 + (i1 * EQ(i2, i3) * i4))}(<float64>, <float64>, <float64>, <float64>, <float64>) missing default value. ')

```




Discussion:
Can you give us a bit more information on your version of Theano, and current flags?
Are you using float16 on GPU?

Resolving patch:
diff --git a/theano/scalar/basic.py b/theano/scalar/basic.py
--- a/theano/scalar/basic.py
+++ b/theano/scalar/basic.py
@@ -4078,6 +4078,8 @@ def apply(self, fgraph):
         for i in fgraph.inputs:
             if i.dtype == 'float16':
                 mapping[i] = get_scalar_type('float32')()
+                if hasattr(i.tag, 'test_value'):
+                    mapping[i].tag.test_value = i.tag.test_value
             else:
                 mapping[i] = i
         for node in topo:


Test patch: