-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Full batch models fail to save with "If specifying TensorSpec names for nested structures, either zero or all names have to be specified" #1251
Comments
https://community.stellargraph.io/t/valueerror-if-specifying-tensorspec-names-for-nested-structures-either-zero-or-all-names-have-to-be-specified/97/3?u=huon notes that |
Hi, Still the same error as you described above. |
I'm investigating this now. Main finding so far: this seems to be specifically associated with sparse |
This seems to be some problem with layers that take sparse tensors as input, even if they're not being used, e.g.: Reduced form (via creduce and manual editing): import tensorflow as tf
class SqueezedSparseConversion(tf.keras.layers.Layer):
def call(self, inputs):
return tf.SparseTensor([(0, 1)], [0.1], (3, 3))
class GraphConvolution(tf.keras.layers.Layer):
def call(self, inputs):
return inputs[0]
x_t = tf.keras.Input(0)
sp = SqueezedSparseConversion()(x_t)
out = GraphConvolution()([x_t, sp])
m = tf.keras.Model([x_t], out)
m.summary()
m.save("") Full output
Package versions
|
I filed tensorflow/tensorflow#40373. I think we can work around this by not doing the
|
This PR tests saving and loading of a `tf.keras.Model` instance for every model in StellarGraph. It does so by adding a `test_utils.model_save_load` helper function that serialises and deserialisers a given model using various APIs provided by TensorFlow: - saving: - `tf.keras.Model.save` https://www.tensorflow.org/api_docs/python/tf/keras/Model#save - `tf.keras.models.save_model` https://www.tensorflow.org/api_docs/python/tf/keras/models/save_model - `tf.saved_model.save` https://www.tensorflow.org/api_docs/python/tf/saved_model/save - loading: `tf.keras.models.load_model` https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model (not `tf.saved_model.load` https://www.tensorflow.org/api_docs/python/tf/saved_model/load, because it doesn't create a Keras `Model` object) Several of these new tests fail (they're included but marked as xfail), due to: - #1251 - #1252 - #1680 (found in this PR) - #1681 (found in this PR) As those issues are fixed, the xfailing can be removed.
A Keras Layer with weights without names cannot be saved (tensorflow/tensorflow#36962), because an exception is thrown: ``` AttributeError: 'NoneType' object has no attribute 'replace' ``` This PR adds names to the `add_weight` calls within `RelationalGraphConvolution`, which were the only ones within all of StellarGraph missing the `name=...` parameter. This allows non-sparse RGCN models to be saved, but sparse ones still hit #1251. See: #1252
That issue was closed as a duplicate of tensorflow/tensorflow#38465. It seems that this is now fixed in As such, I think I'll put this on the back burner for now because we have other high priority tasks; but, please let me know if it's particularly important to you (and upgrading to |
TensorFlow released 2.3.0-rc0 recently, which includes the fix for this issue. #1742 validates that (the equivalent of) |
Description
As reported in https://community.stellargraph.io/t/valueerror-if-specifying-tensorspec-names-for-nested-structures-either-zero-or-all-names-have-to-be-specified/97, saving some models in sparse mode fails with
ValueError('If specifying TensorSpec names for nested structures, either zero or all names have to be specified.',)
. This is due to a bug in Tensorflow tensorflow/tensorflow#38465 related to sparse tensors being passed between Keras layers. This bug is fixed in TensorFlow nightly (tf-nightly
package) and the 2.3.0-rc0 release candidate.Affected models (with
sparse=True
in their generators):Work-around
2.3.0-rc0
(recommended): replacetensorflow
with the next release candidate:pip install tensorflow==2.3.0-rc0
.tensorflow
withtf-nightly
, with justpip install tf-nightly
.Once the 2.3 release is out, either of these should be able to be replaced with
pip install tensorflow==2.3.0
(the nightly version may need an explicitpip uninstall tf-nightly tf-estimator-nightly tb-nightly
).Original bug:
Describe the bug
As reported in https://community.stellargraph.io/t/valueerror-if-specifying-tensorspec-names-for-nested-structures-either-zero-or-all-names-have-to-be-specified/97, saving GAT or any other full batch model seems to fail.
To Reproduce
Observed behavior
The full batch methods (
GAT
,GCN
,PPNP
,APPNP
andDeepGraphInfomax
using any of these) fails with:(RGCN fails too, but that's a separate issue: #1252.)
Full stack trace
Full output
GAT
GCN
PPNP
APPNP
GraphSAGE
HinSAGE
Number of clusters 1
0 cluster has size 2708
ClusterGCN
Attri2Vec
RGCN
ComplEx
DistMult
GCNSupervisedGraphClassification
DeepGraphInfomax
DeepGraphInfomax
Expected behavior
Every model should support saving.
Environment
Operating system:
Darwin-18.6.0-x86_64-i386-64bit
Python version:
Package versions:
Additional context
N/A
The text was updated successfully, but these errors were encountered: