Skip to content
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

Errors with numpy 1.24.0 #807

Open
sebastianknopf opened this issue Dec 21, 2022 · 10 comments
Open

Errors with numpy 1.24.0 #807

sebastianknopf opened this issue Dec 21, 2022 · 10 comments
Assignees

Comments

@sebastianknopf
Copy link

I tried to use tf-agents, the latest version. However, if I run a simple class which only extends PyEnvironment but nothing else, I receive an with a message like

module 'numpy' does not contain attribute named 'bool'. Did you mean 'bool_'

There are several similar issues with numpy, sometimes re-installing numpy helps. In my case it didn't, I tried the common workflow of uninstalling setuptools and numpy.

I'm using:

  • Python 3.10 (Python 3.11 doesn't work also...)
  • Numpy 1.24.0

Is there anything I've left?

@zsdadisscy
Copy link

I had the same problem I tried lowering the numpy version and it didn't help

@coreyleveen
Copy link
Contributor

@sebastianknopf Would you mind sharing your code?

@sebastianknopf
Copy link
Author

Sadly I can't share any code. I needed to switch to a manual implementation.

Maybe @zsdadisscy can share some code, since facing the same issue?

@sgboakes
Copy link

sgboakes commented Jan 5, 2023

Having a similar issue with error AttributeError: module 'numpy' has no attribute 'bool'. Did you mean: 'bool_'? when importing tf_agents.types. In release 0.15.0, in tf-agents.typing.types.py, line 81 has np.bool. This is not there in the master branch of tf-agents, so I suppose we'll need to wait until this gets pushed to pypi.

@tfboyd
Copy link
Member

tfboyd commented Jan 5, 2023

nightly should be working. numpy 0.24. removed np.bool. Long story and it doesn't matter. We were preparing for this; but the holiday's slowed us down. I hope to have an RC and maybe a full release done today. 05-JAN.

@tfboyd tfboyd self-assigned this Jan 5, 2023
@tfboyd
Copy link
Member

tfboyd commented Jan 5, 2023

I will ping this thread will progress.

@tfboyd
Copy link
Member

tfboyd commented Jan 5, 2023

Update: I have not done a root cause but here is the situation and there is nothing I can do until Tensorflow is updated to support Numpy 1.24.0. Keep in mind Numpy 1.24.0 was released at the end of December 2022.

The tl;dr; is you need to install numpy 1.23.5: pip install numpy==1.23.5

Using numpy 1.24.0 causes an error as illustrated by running python3 -m tf_agents.agents.ppo.ppo_utils_test but I don't see that error with numpy 1.23.5 keeping everything else exactly the same.

The error is:

======================================================================
ERROR: test_get_distribution_params_WithLegacyDistributionNetwork (__main__.PPOUtilsTest)
PPOUtilsTest.test_get_distribution_params_WithLegacyDistributionNetwork
test_get_distribution_params_WithLegacyDistributionNetwork(True)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/absl/testing/parameterized.py", line 320, in bound_param_test
    return test_method(self, *testcase_params)
  File "/workspace/tf_agents/agents/ppo/ppo_utils_test.py", line 108, in test_get_distribution_params
    self.assertAllEqual([[[2]], [[2], [2]]],
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/test_util.py", line 1532, in decorated
    return f(*args, **kwds)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/test_util.py", line 3208, in assertAllEqual
    a = self._GetNdArray(a)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/test_util.py", line 2949, in _GetNdArray
    return np.array(a)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

I did a test with tf-agents-nightly (which then also uses tf-nightly, dm-reverb-nightly, and tfp-nightly). The test worked with numpy 1.23.5 but again failed with numpy 1.24.0 and tf-nightly (tensorflow) throws a warning during the install of numpy 1.24.0 that tensorflow current supports numpy<1.24,>=1.20

All of that said, tf-agents has been updated in tf-agents nightly to support numpy 0.24.0 by no longer using np.bool.

@sgboakes
Copy link

sgboakes commented Jan 6, 2023

Thanks for the update!

@sebastianknopf
Copy link
Author

Thank you too for the update!

@tfboyd
Copy link
Member

tfboyd commented Feb 4, 2023

Python 3.11 is now supported in tf-nightly. Tensorflow 2.12 branch was cut so the next stable will have 3.11. Numpy is still a mess and I don't think TF has moved to 1.24 yet so there must be some struggles. I keep checking as it is annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants