Probability: Support for Tensorflow 2.0

Created on 8 Mar 2019  Â·  18Comments  Â·  Source: tensorflow/probability

Unfortunately, I could not find the right api in the docs. Is tfp supported with TF 2.0 alpha?

Versions

tensorflow==2.0.0-alpha0
tensorflow-probability==0.6.0

Code

import tensorflow as tf
import tensorflow_probability as tfp

Error Logs

AttributeError                            Traceback (most recent call last)
<ipython-input-3-6ad69c3a0ac3> in <module>
      1 import tensorflow as tf
----> 2 import tensorflow_probability as tfp

/usr/local/miniconda3/envs/hmc-tf2/lib/python3.6/site-packages/tensorflow_probability/__init__.py in <module>
     76 
     77 # from tensorflow_probability.google import staging  # DisableOnExport
---> 78 from tensorflow_probability.python import *  # pylint: disable=wildcard-import
     79 from tensorflow_probability.python.version import __version__
     80 # pylint: enable=g-import-not-at-top

/usr/local/miniconda3/envs/hmc-tf2/lib/python3.6/site-packages/tensorflow_probability/python/__init__.py in <module>
     19 from __future__ import print_function
     20 
---> 21 from tensorflow_probability.python import bijectors
     22 from tensorflow_probability.python import distributions
     23 from tensorflow_probability.python import edward2

/usr/local/miniconda3/envs/hmc-tf2/lib/python3.6/site-packages/tensorflow_probability/python/bijectors/__init__.py in <module>
     44 from tensorflow_probability.python.bijectors.masked_autoregressive import MaskedAutoregressiveFlow
     45 from tensorflow_probability.python.bijectors.matrix_inverse_tril import MatrixInverseTriL
---> 46 from tensorflow_probability.python.bijectors.matveclu import MatvecLU
     47 from tensorflow_probability.python.bijectors.normal_cdf import NormalCDF
     48 from tensorflow_probability.python.bijectors.ordered import Ordered

/usr/local/miniconda3/envs/hmc-tf2/lib/python3.6/site-packages/tensorflow_probability/python/bijectors/matveclu.py in <module>
     22 
     23 from tensorflow_probability.python.bijectors import bijector
---> 24 from tensorflow_probability.python.math.linalg import lu_reconstruct
     25 from tensorflow_probability.python.math.linalg import lu_solve
     26 

/usr/local/miniconda3/envs/hmc-tf2/lib/python3.6/site-packages/tensorflow_probability/python/math/__init__.py in <module>
     20 
     21 from tensorflow_probability.python.math.custom_gradient import custom_gradient
---> 22 from tensorflow_probability.python.math.diag_jacobian import diag_jacobian
     23 from tensorflow_probability.python.math.interpolation import batch_interp_regular_1d_grid
     24 from tensorflow_probability.python.math.interpolation import interp_regular_1d_grid

/usr/local/miniconda3/envs/hmc-tf2/lib/python3.6/site-packages/tensorflow_probability/python/math/diag_jacobian.py in <module>
     22 import tensorflow as tf
     23 
---> 24 tfe = tf.contrib.eager
     25 
     26 __all__ = [

AttributeError: module 'tensorflow' has no attribute 'contrib'

Most helpful comment

TFP is TF2 ready!

(We still need to update a few examples, but the core library is tested under TF2!)

Try this:
pip install --upgrade tf-nightly-gpu-2.0-preview tfp-nightly
(Drop the -gpu if you don't have one or want a smaller whl download.)

All 18 comments

TFP nightly should be compatible with TF2. Let us know if you encounter
issues. In particular we are still looking for performance regressions.

On Fri, Mar 8, 2019, 2:23 AM Sanyam Kapoor notifications@github.com wrote:

Unfortunately, I could not find the right api in the docs. Is tfp
supported with TF 2.0 alpha?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tensorflow/probability/issues/320, or mute the thread
https://github.com/notifications/unsubscribe-auth/AVJZI99sQ6r5m3BR1cjoleSzP3hCyB2qks5vUg_0gaJpZM4bkzPe
.

Great! Let me try that out.

I tried it and everything works fine, couldn't see performance regressions.

nightly works fine for this case

TFP nightly should be compatible with TF2. Let us know if you encounter issues. In particular we are still looking for performance regressions.
…
On Fri, Mar 8, 2019, 2:23 AM Sanyam Kapoor @.*> wrote: Unfortunately, I could not find the right api in the docs. Is tfp supported with TF 2.0 alpha? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#320>, or mute the thread https://github.com/notifications/unsubscribe-auth/AVJZI99sQ6r5m3BR1cjoleSzP3hCyB2qks5vUg_0gaJpZM4bkzPe .

Sorry but TFP does not work at all with TF 2 I still got the same error.

AttributeError: module 'tensorflow' has no attribute 'contrib'
MY TF version:

2.0.0-dev20190309

My TFP version:
tfp.__version__

'0.7.0-dev20190309'

TFP is TF2 ready!

(We still need to update a few examples, but the core library is tested under TF2!)

Try this:
pip install --upgrade tf-nightly-gpu-2.0-preview tfp-nightly
(Drop the -gpu if you don't have one or want a smaller whl download.)

Please reopen if the above procedure didnt work for you. In the coming days we'll also update the GH home page.

When trying to run
pip install --upgrade tf-nightly-2.0-preview tfp-nightly
I get the error
Collecting tf-nightly-2.0-preview
Could not find a version that satisfies the requirement tf-nightly-2.0-preview (from versions: ) No matching distribution found for tf-nightly-2.0-preview
I am using Python 3.7, Tensorflow 2.0.0a0 and Windows 10 build 17763

here is the list of available 2.0-preview packages: https://pypi.org/project/tf-nightly-2.0-preview/2.0.0.dev20190417/#files

looks like the only windows version only has py 3.6 support

(note this is a TF issue, not TFP)

here is the list of available 2.0-preview packages: https://pypi.org/project/tf-nightly-2.0-preview/2.0.0.dev20190417/#files

looks like the only windows version only has py 3.6 support

when should i put the file??

Is this (TFP nightly 2.0 preview) still the recommended way with TF2-beta latest version? It's not clear from the post because the original question was for TF2-alpha

Hi @kristofgiber -- the tensorflow-probability 0.7 release is tested against 2.0.0-beta and should be stable. tfp-nightly is tested against tf-nightly and tf-nightly-2.0-preview and should work with both. Please report any issues you encounter using either combination!

@csuter Thank you. As I understand one difference between tf2 preview and tf2 is that in tf2 preview eager execution is enabled by default but not in tf2. Do I still have to enable eager execution for tfp 0.7 to work when I use it with tf2?

We (and TF) recommend the following idiom for starting to adopt TF2

import tensorflow.compat.v2 as tf
tf.enable_v2_behavior()

This should ensure you are getting tf2-style APIs and that the various behavioral differences are enabled. At some point the above will become the default when you import tensorflow but I'm not exactly sure when.

@csuter Good to know! So by using compat.v2 I should be fine and enabling eager execution is not required for tfp+tf2 combo to work

Hello, is the nightly version still the only way to import distributions? I am getting the same error as above in TF 2

tfp-nightly is still the build I'd recommend using (with tf-nightly or tf-nightly-cpu).

If you want the stable version w/o latest bells & whistles, tensorflow-probability==0.8.0 and tensorflow==1.15.0 or tensorflow==2.0.0 should both work.

Was this page helpful?
0 / 5 - 0 ratings