tensorflow: TF 2.0.0-rc0 + TFP 0.7 broken combo: Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key

Error occurs: tf-gpu 2.0.0-rc0 with tfp 0.7

Code to reproduce:

import tensorflow_probability as tfp
tfp.distributions.MultivariateNormalDiag([0.], [1.]).sample()

Error returned:

Traceback (most recent call last): File “/home/pycharm_project/VAE/save_issue_reproduction.py”, line 3, in <module> tfp.distributions.MultivariateNormalDiag([0.], [1.]).sample() File “/usr/local/lib/python3.5/dist-packages/tensorflow_probability/python/distributions/distribution.py”, line 840, in sample return self._call_sample_n(sample_shape, seed, name, **kwargs) File “/usr/local/lib/python3.5/dist-packages/tensorflow_probability/python/distributions/transformed_distribution.py”, line 391, in _call_sample_n y = self.bijector.forward(x, **bijector_kwargs) File “/usr/local/lib/python3.5/dist-packages/tensorflow_probability/python/bijectors/bijector.py”, line 933, in forward return self._call_forward(x, name, **kwargs) File “/usr/local/lib/python3.5/dist-packages/tensorflow_probability/python/bijectors/bijector.py”, line 904, in _call_forward mapping = self._lookup(x=x, kwargs=kwargs) File “/usr/local/lib/python3.5/dist-packages/tensorflow_probability/python/bijectors/bijector.py”, line 1343, in _lookup mapping = self._from_x[x].get(subkey, mapping).merge(x=x) File “/usr/local/lib/python3.5/dist-packages/tensorflow_probability/python/bijectors/bijector.py”, line 151, in getitem return super(WeakKeyDefaultDict, self).getitem(weak_key) File “/usr/local/lib/python3.5/dist-packages/tensorflow_probability/python/bijectors/bijector.py”, line 181, in hash return hash(x) File “/usr/local/lib/python3.5/dist-packages/tensorflow_core/python/framework/ops.py”, line 713, in hash raise TypeError("Tensor is unhashable if Tensor equality is enabled. " TypeError: Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (2 by maintainers)

Most upvoted comments

After upgrade

pip install tensorflow_probability==0.8.0rc0 --user --upgrade

Error still happens

File "/Users/techmaster/LearnAI/venv/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 713, in __hash__
    raise TypeError("Tensor is unhashable if Tensor equality is enabled. "
TypeError: Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key.

My environment:

  • MacOSX High Sierra
  • TensorFlow version 2.0.0-rc1
  • tf-estimator-nightly 1.14.0.dev2019080601
  • Keras 2.2.5
  • Keras-Applications 1.0.8
  • Keras-Preprocessing 1.1.0

Piece of code causes error

intermediate_layer_model = Model(inputs=self.model.input, outputs=self.model.get_layer("embedding").output)
intermediate_output = intermediate_layer_model.predict(encoded_texts)
return intermediate_output

pip install tf-hub-nightly it works

Thanks for the report! This is due to a change in TF’s Tensor equality semantics that occurred between the TFP 0.7 release and the TF 2.0.0-rc0 prerelease. You can fix it by installing TFP 0.8-rc0 (pip install tensorflow_probability==0.8.0rc0 --user --upgrade), which should include the necessary updates.