tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.16k stars 1.08k forks source link

AttributeError: Tensorflow-Probabilty does not have right attribute #1823

Open Mr-Elysium opened 2 weeks ago

Mr-Elysium commented 2 weeks ago

I am using:

tensorflow==2.16.2 tensorflow-probability==0.24.0 tf-agents==0.19.0 tf-keras==2.16.0

The import inside the file I am trying to run are: ` import random import numpy as np

from tf_agents.specs import BoundedArraySpec from tf_agents.trajectories.time_step import StepType, TimeStep from tf_agents.environments import py_environment

from chinesecheckers_tf_env import ChineseCheckersEnv, BOARD_SIZE, MAX_MOVES `

The Error I then receive if:

Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode coro = func() ^^^^^^ File "", line 1, in File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:\Users\yonik\PycharmProjects\ChineseCheckers\chinesecheckers_env\env\chinesecheckers_tf_multi_agent_env.py", line 3, in from chinesecheckers_tf_env import ChineseCheckersEnv, BOARD_SIZE, MAX_MOVES File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\PycharmProjects\ChineseCheckers\chinesecheckers_env\env\chinesecheckers_tf_env.py", line 19, in from tf_agents.environments import py_environment File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_agents__init__.py", line 74, in from tf_agents import agents File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_agents\agents__init.py", line 17, in from tf_agents.agents import behavioral_cloning File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_agents\agents\behavioral_cloning__init__.py", line 17, in from tf_agents.agents.behavioral_cloning import behavioral_cloning_agent File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_agents\agents\behavioral_cloning\behavioral_cloning_agent.py", line 39, in from tf_agents.agents import tf_agent File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_agents\agents\tf_agent.py", line 29, in from tf_agents.policies import tf_policy File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_agents\policies__init__.py", line 18, in from tf_agents.policies import actor_policy File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_agents\policies\actor_policy.py", line 30, in from tf_agents.distributions import utils as distribution_utils File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_agents\distributions__init__.py", line 20, in from tf_agents.distributions import utils File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1.4\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tf_agents\distributions\utils.py", line 40, in class SquashToSpecNormal(tfp.distributions.AutoCompositeTensorDistribution): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\yonik\AppData\Local\Programs\Python\Python311\Lib\site-packages\tensorflow_probability\python\internal\lazy_loader.py", line 54, in getattr__ return getattr(module, item) ^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'tensorflow_probability.python.distributions' has no attribute 'AutoCompositeTensorDistribution'

Is there any quick fix like updating or downgrading or something else?

csuter commented 2 weeks ago

can you provide a full pip list dump?

Mr-Elysium commented 2 weeks ago

Of course, here it is:

Farama-Notifications | 0.0.4 | 0.0.4 Markdown | 3.6 | 3.6 MarkupSafe | 2.1.5 | 2.1.5 Pygments | 2.18.0 | 2.18.0 Werkzeug | 3.0.3 | 3.0.3 absl-py | 2.1.0 | 2.1.0 astunparse | 1.6.3 | 1.6.3 certifi | 2024.7.4 | 2024.7.4 charset-normalizer | 3.3.2 | 3.3.2 cloudpickle | 3.0.0 | 3.0.0 contourpy | 1.2.1 | 1.2.1 cycler | 0.12.1 | 0.12.1 decorator | 5.1.1 | 5.1.1 dm-tree | 0.1.8 | 0.1.8 flatbuffers | 24.3.25 | 24.3.25 fonttools | 4.53.1 | 4.53.1 gast | 0.6.0 | 0.6.0 gin-config | 0.5.0 | 0.5.0 google-pasta | 0.2.0 | 0.2.0 grpcio | 1.64.1 | 1.64.1 gym | 0.23.0 | 0.26.2 gym-notices | 0.0.8 | 0.0.8 gymnasium | 0.29.1 | 0.29.1 h5py | 3.11.0 | 3.11.0 idna | 3.7 | 3.7 keras | 3.4.1 | 3.4.1 kiwisolver | 1.4.5 | 1.4.5 libclang | 18.1.1 | 18.1.1 markdown-it-py | 3.0.0 | 3.0.0 matplotlib | 3.9.1 | 3.9.1 mdurl | 0.1.2 | 0.1.2 ml-dtypes | 0.3.2 | 0.4.0 namex | 0.0.8 | 0.0.8 numpy | 1.26.4 | 2.0.0 numpy | 2.0.0 | 2.0.0 opt-einsum | 3.3.0 | 3.3.0 optree | 0.12.1 | 0.12.1 packaging | 24.1 | 24.1 pettingzoo | 1.24.3 | 1.24.3 pillow | 10.4.0 | 10.4.0 pip | 23.2.1 | 24.1.2 protobuf | 4.25.3 | 5.27.2 protobuf | 5.27.2 | 5.27.2 pygame | 2.1.3 | 2.6.0 pyparsing | 3.1.2 | 3.1.2 python-dateutil | 2.9.0.post0 | 2.9.0.post0 requests | 2.32.3 | 2.32.3 rich | 13.7.1 | 13.7.1 setuptools | 68.2.0 | 70.3.0 six | 1.16.0 | 1.16.0 tensorboard | 2.16.2 | 2.17.0 tensorboard-data-server | 0.7.2 | 0.7.2 tensorflow | 2.16.2 | 2.16.2 tensorflow-io-gcs-filesystem | 0.37.1 | 0.37.1 tensorflow-probability | 0.24.0 | 0.24.0 termcolor | 2.4.0 | 2.4.0 tf-agents | 0.19.0 | 0.19.0 tf_keras | 2.16.0 | 2.16.0 typing_extensions | 4.5.0 | 4.12.2 typing_extensions | 4.12.2 | 4.12.2 urllib3 | 2.2.2 | 2.2.2 wheel | 0.41.2 | 0.43.0 wrapt | 1.16.0 | 1.16.0

csuter commented 2 weeks ago

I am unable to reproduce the error with (AFAICT) matching versions of the relevant libraries. I do not have easy access to a windows machine so can't rule out subtleties w.r.t. that.

The only thing I can think of is that tf-agents 0.19 wants TFP 0.23, not TFP 0.24, although I'd be surprised if that difference caused the attached error.

If you are able to share a public colab notebook with !pip uninstall/install commands that reproduce the environment you're in and replicates the error, I can attempt to debug further. Sorry not to be more help at this time.

Mr-Elysium commented 4 days ago

Hi, sorry for getting back so long, I was away for a couple days and did not have access to my PC, I realised that my previous post was spurious. Also, the problem has since seemed to resolve itself for no apparent reason, the code now runs without erroring. Nevertheless, the correct set of libraries is:

Farama-Notifications | 0.0.4 | 0.0.4 Markdown | 3.6 | 3.6 MarkupSafe | 2.1.5 | 2.1.5 Pygments | 2.18.0 | 2.18.0 Werkzeug | 3.0.3 | 3.0.3 absl-py | 2.1.0 | 2.1.0 astunparse | 1.6.3 | 1.6.3 certifi | 2024.7.4 | 2024.7.4 charset-normalizer | 3.3.2 | 3.3.2 cloudpickle | 3.0.0 | 3.0.0 contourpy | 1.2.1 | 1.2.1 cycler | 0.12.1 | 0.12.1 decorator | 5.1.1 | 5.1.1 dm-tree | 0.1.8 | 0.1.8 flatbuffers | 24.3.25 | 24.3.25 fonttools | 4.53.1 | 4.53.1 gast | 0.6.0 | 0.6.0 gin-config | 0.5.0 | 0.5.0 google-pasta | 0.2.0 | 0.2.0 grpcio | 1.64.1 | 1.65.1 gym | 0.23.0 | 0.26.2 gym-notices | 0.0.8 | 0.0.8 gymnasium | 0.29.1 | 0.29.1 h5py | 3.11.0 | 3.11.0 idna | 3.7 | 3.7 keras | 3.4.1 | 3.4.1 keras-nightly | 3.4.1.dev2024070503 |   kiwisolver | 1.4.5 | 1.4.5 libclang | 18.1.1 | 18.1.1 markdown-it-py | 3.0.0 | 3.0.0 matplotlib | 3.9.1 | 3.9.1 mdurl | 0.1.2 | 0.1.2 ml-dtypes | 0.3.2 | 0.4.0 namex | 0.0.8 | 0.0.8 numpy | 1.26.4 | 2.0.1 opt-einsum | 3.3.0 | 3.3.0 optree | 0.12.0 | 0.12.1 packaging | 24.1 | 24.1 pettingzoo | 1.24.3 | 1.24.3 pillow | 10.4.0 | 10.4.0 pip | 24.0 | 24.1.2 protobuf | 4.25.3 | 5.27.2 pygame | 2.1.3 | 2.6.0 pyparsing | 3.1.2 | 3.1.2 python-dateutil | 2.9.0.post0 | 2.9.0.post0 requests | 2.32.3 | 2.32.3 rich | 13.7.1 | 13.7.1 setuptools | 65.5.0 | 71.1.0 six | 1.16.0 | 1.16.0 tb-nightly | 2.18.0a20240705 |   tensorboard | 2.16.2 | 2.17.0 tensorboard-data-server | 0.7.2 | 0.7.2 tensorflow | 2.16.2 | 2.17.0 tensorflow-intel | 2.16.2 | 2.17.0 tensorflow-io-gcs-filesystem | 0.31.0 | 0.37.1 tensorflow-probability | 0.24.0 | 0.24.0 termcolor | 2.4.0 | 2.4.0 tf-agents | 0.19.0 | 0.19.0 tf_keras | 2.16.0 | 2.17.0 typing_extensions | 4.5.0 | 4.12.2 urllib3 | 2.2.2 | 2.2.2 wheel | 0.43.0 | 0.43.0 wrapt | 1.16.0 | 1.16.0

For now, the error is resolved, but I can see it appearing out of nowhere in the future just as it dissapeared out of nowhere now.