blei-lab / edward

A probabilistic programming language in TensorFlow. Deep generative models, variational inference.
http://edwardlib.org
Other
4.83k stars 759 forks source link

TypeError: First parent class declared for Empirical must be Distribution, but saw 'RandomVariable' #315

Closed MahdiNazemi closed 7 years ago

MahdiNazemi commented 8 years ago

Hi,

I just installed edward from source using the command python setup.py install. When I open python's interactive shell and enter import edward I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/edward/__init__.py", line 5, in <module>
  File "build/bdist.linux-x86_64/egg/edward/criticisms/__init__.py", line 5, in <module>
  File "build/bdist.linux-x86_64/egg/edward/criticisms/evaluate.py", line 9, in <module>
  File "build/bdist.linux-x86_64/egg/edward/models/__init__.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/edward/models/random_variables.py", line 14, in <module>
  File "path_to_tensorflow/tensorflow/contrib/distributions/python/ops/distribution.py", line 138, in __new__
    "Distribution, but saw '%s'" % (classname, base.__name__))
TypeError: First parent class declared for Empirical must be Distribution, but saw 'RandomVariable'

(I have installed tensorflow 0.11rc1 from source.)

Can you please help me solve the issue?

dustinvtran commented 8 years ago

Looks like the distributions library in tensorflow.contrib broke compatibility with the Edward code base. (The type error is basically forcing parent classes of any distribution to be Distribution first; it wasn't there before.)

The most immediate fix would be to downgrade to TensorFlow 0.11.0. Meanwhile I'll see if I can come up with a solution (or contact them). Thanks for raising the issue!

MahdiNazemi commented 8 years ago

Thanks a lot for your prompt reply. I'll post here in case I can find another solution.

fredcallaway commented 7 years ago

In the mean time, perhaps it would be good to make this dependency explicit in the python package so new users don't have to handle this themselves?

diehl commented 7 years ago

@fredcallaway I'm not sure this would make much difference. In my attempt to revert to an earlier version of Tensorflow (0.11.0) with pip, I discovered the only available versions of TF are 0.12 release candidates.

$ pip install tensorflow==
Collecting tensorflow==
  Could not find a version that satisfies the requirement tensorflow== (from versions: 0.12.0rc0, 0.12.0rc1)
No matching distribution found for tensorflow==

If someone has other ideas about how to revert to 0.11.0 without compiling from source, I'm all ears!

gokceneraslan commented 7 years ago

The code giving rise to this error (https://github.com/tensorflow/tensorflow/commit/3cb343915a9726b943d2fbb45e26148e9b83fa0e#diff-f71a6ea6b5cca22cde7783b6c3511960R149) was never merged into TF 0.11 branch, therefore all 0.11 versions should be safe to use. You've probably compiled TF from the master branch, not from 0.11 branch. Reverting your TF to latest 0.11 (e.g. pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp35-cp35m-linux_x86_64.whl) would probably fix it.

The good news about the bug is that it's been fixed now in the master branch (https://github.com/tensorflow/tensorflow/commit/77cfa97ac784212130e97bc6fa9e6f8acfc86c08). But because there exist other incompatibilities in 0.12 and master, edward doesn't work by default, so do not upgrade to 0.12 for now, or follow https://github.com/blei-lab/edward/pull/374 if you do.

diehl commented 7 years ago

@gokceneraslan appreciate this feedback! I followed your pip install suggestion using the URL and got TF reverted to 0.11.0. would still be nice if the stock pip install edward would take care of grabbing the appropriate version of TF for the available version of edward.

dustinvtran commented 7 years ago

@diehl: good idea. 82e534d prevents installing edward with 0.12.0rc0 or 0.12.0rc1; i also added a note to the website's getting started. edward version 1.1.6 is a hot fix incorporating this commit.

diehl commented 7 years ago

@dustinvtran I just attempted pip install edward on another machine and am seeing the following:

$ pip install -U edward
Collecting edward
  Downloading edward-1.1.6-py2-none-any.whl (51kB)
    100% |████████████████████████████████| 61kB 407kB/s
Requirement already up-to-date: six>=1.10.0 in ./anaconda/envs/DataGuild/lib/python2.7/site-packages (from edward)
Collecting tensorflow!=0.12.0rc0,!=0.12.0rc1,>=0.11.0rc0 (from edward)
  Could not find a version that satisfies the requirement tensorflow!=0.12.0rc0,!=0.12.0rc1,>=0.11.0rc0 (from edward) (from versions: 0.12.0rc0, 0.12.0rc1)
No matching distribution found for tensorflow!=0.12.0rc0,!=0.12.0rc1,>=0.11.0rc0 (from edward)

As you can see, it's breaking due to the fact that you can only pip install the 0.12 release candidates for Tensorflow presently.

ghost commented 7 years ago

Hi, On Ubuntu, using version 0.11.0 as instructed above still does not work. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl 285 sudo pip install --upgrade $TF_BINARY_URL 286 sudo pip install --upgrade edward


TypeError Traceback (most recent call last)

in () ----> 1 import edward /opt/anaconda2/lib/python2.7/site-packages/edward/__init__.py in () 3 from __future__ import print_function 4 ----> 5 from edward import criticisms 6 from edward import inferences 7 from edward import models /opt/anaconda2/lib/python2.7/site-packages/edward/criticisms/__init__.py in () 3 from __future__ import print_function 4 ----> 5 from edward.criticisms.evaluate import * 6 from edward.criticisms.ppc import * /opt/anaconda2/lib/python2.7/site-packages/edward/criticisms/evaluate.py in () 7 import tensorflow as tf 8 ----> 9 from edward.models import RandomVariable 10 from edward.util import logit, get_session 11 /opt/anaconda2/lib/python2.7/site-packages/edward/models/__init__.py in () 5 from edward.models.models import * 6 from edward.models.random_variable import * ----> 7 from edward.models.random_variables import * /opt/anaconda2/lib/python2.7/site-packages/edward/models/random_variables.py in () 12 13 ---> 14 class Empirical(RandomVariable, distributions_Empirical): 15 def __init__(self, *args, **kwargs): 16 super(Empirical, self).__init__(*args, **kwargs) /opt/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/distributions/python/ops/distribution.pyc in __new__(mcs, classname, baseclasses, attrs) 136 if not issubclass(base, Distribution): 137 raise TypeError("First parent class declared for %s must be " --> 138 "Distribution, but saw '%s'" % (classname, base.__name__)) 139 for attr in _DISTRIBUTION_PUBLIC_METHOD_WRAPPERS: 140 special_attr = "_%s" % attr TypeError: First parent class declared for Empirical must be Distribution, but saw 'RandomVariable'
ghost commented 7 years ago

Problem is, edward ignores my existing Tensorflow and installs version 12: root@cto-datascience:~/dev# pip install --ignore-installed --upgrade edward Collecting edward Using cached edward-1.1.6-py2-none-any.whl Collecting tensorflow!=0.12.0rc0,!=0.12.0rc1,>=0.11.0rc0 (from edward) Using cached tensorflow-0.12.1-cp27-cp27mu-manylinux1_x86_64.whl

jstpierref commented 7 years ago

See @gokceneraslan answer to to it manually :)

ghost commented 7 years ago

As I wrote, I did exactly as suggested by @gokceneraslan. Still no luck.

dustinvtran commented 7 years ago

it looks like you're still using tensorflow 0.12+ instead of 0.11. this is likely independent of the edward install. can you confirm by running in terminal, python -c "import tensorflow as tf; print(tf.__version__)"?

ghost commented 7 years ago

Thanks, Found the issue. Must use: pip install $TF_BINARY_URL and NOT : sudo pip install $TF_BINARY_URL (which does not install under anaconda)

2017-01-11 09_04_11-sh_test_install

dustinvtran commented 7 years ago

perfect!

i should have the compatibility changes for the latest tensorflow 1.0.0 out soon. so once 1.0.0 is the default install, we will no longer have to deal with these issues. (they are fixed in 1.0.0)

dustinvtran commented 7 years ago

solved in Edward's upgrade to support 1.0.0 (v1.2.1).