Closed benja8151 closed 2 years ago
I was using the latest version of tensorflow
(2.4.1). Reverting to version 2.0.0 - same as in the example gives a different error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-20-c064f7512961> in <module>
27 atom_state = nfp.NodeUpdate()([atom_state, bond_state, connectivity, global_state])
28 global_state = nfp.GlobalUpdate(units=8, num_heads=1)(
---> 29 [atom_state, bond_state, connectivity, global_state])
30
31 # Since the final prediction is a single, molecule-level property (YSI), we
~\anaconda3\envs\Python 37\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py in __call__(self, inputs, *args, **kwargs)
840 not base_layer_utils.is_in_eager_or_tf_function()):
841 with auto_control_deps.AutomaticControlDependencies() as acd:
--> 842 outputs = call_fn(cast_inputs, *args, **kwargs)
843 # Wrap Tensors in `outputs` in `tf.identity` to avoid
844 # circular dependencies.
~\anaconda3\envs\Python 37\lib\site-packages\tensorflow_core\python\autograph\impl\api.py in wrapper(*args, **kwargs)
235 except Exception as e: # pylint:disable=broad-except
236 if hasattr(e, 'ag_error_metadata'):
--> 237 raise e.ag_error_metadata.to_exception(e)
238 else:
239 raise
TypeError: in converted code:
relative to C:\Users\Benjamin\anaconda3\envs\Python 37\lib\site-packages:
nfp\layers\graph_layers.py:157 call *
graph_element_mask = tf.concat([mask[0], mask[1]], axis=1)
tensorflow_core\python\util\dispatch.py:180 wrapper
return target(*args, **kwargs)
tensorflow_core\python\ops\array_ops.py:1431 concat
return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
tensorflow_core\python\ops\gen_array_ops.py:1256 concat_v2
"ConcatV2", values=values, axis=axis, name=name)
tensorflow_core\python\framework\op_def_library.py:499 _apply_op_helper
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have types [<NOT CONVERTIBLE TO TENSOR>, bool] that don't all match.
Thanks for the issue! This was a change from me that didn't get updated into the example notebook, although i'll look into making that error a bit more intuitive.
For various reasons I ended up changing out the masking was done in the GraphLayers, and now the typical way to stack the message layers is to put in the residual connections manually, i.e.,
for _ in range(3): # Do the message passing
new_bond_state = nfp.EdgeUpdate()([atom_state, bond_state, connectivity, global_state])
bond_state = layers.Add()([bond_state, new_bond_state])
new_atom_state = nfp.NodeUpdate()([atom_state, bond_state, connectivity, global_state])
atom_state = layers.Add()([atom_state, new_atom_state])
new_global_state = nfp.GlobalUpdate(units=8, num_heads=1)(
[atom_state, bond_state, connectivity, global_state])
global_state = layers.Add()([global_state, new_global_state])
That way the keras_mask gets passed via the Add() layer, and we're not relying on masking from our own custom layers (which doesn't get saved if you use the tf.SavedModel format). Give the new example notebook a try, I'm hoping that solves the problem.
Thanks!
OK, I made a couple changes in 0.2.1 where you hopefully wouldn't see that error, even with the original code. But the residual connections are still removed from those GraphLayers to play nicer with the tf.SavedModel format, so the updated example is the better code to follow
I've been trying to run the example code, but running cell #10 ("Define the keras model") gives me
ValueError: Tried to convert 'input' to a tensor and failed. Error: None values not supported.
.