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

Module 'gast' has no attribute 'Num' #32319

Closed
mgreenbe opened this issue Sep 7, 2019 · 24 comments
Closed

Module 'gast' has no attribute 'Num' #32319

mgreenbe opened this issue Sep 7, 2019 · 24 comments
Assignees
Labels
TF 2.0 Issues relating to TensorFlow 2.0 type:build/install Build and install issues

Comments

@mgreenbe
Copy link

mgreenbe commented Sep 7, 2019

I got an error message including a request that I report a bug.

Here's the code:

import numpy as np
import tensorflow as tf
import platform

print()
print(f"PLATFORM:\n---------\n{platform.platform()}")
print("\nTENSORFLOW:\n----------")
for a in tf.version.__all__:
    print(f"{a}: {getattr(tf.version, a)}")

print(f"\nNUMPY:\n-----\n{np.version.version}")

print(f"\nPYTHON:\n-------\n{sys.version}\n")

np.random.seed(0)
tf.random.set_seed(0)


model = tf.keras.models.Sequential([
    tf.keras.layers.Dense(1, activation="linear")
])
model.compile(optimizer="sgd", loss="mse")

x = np.random.uniform(size=(1,1))
y = np.random.uniform(size=(1,))
model.fit(x, y, epochs=1)

And here's the output, including system info, module versions, etc.


PLATFORM:
---------
Darwin-18.7.0-x86_64-i386-64bit

TENSORFLOW:
----------
COMPILER_VERSION: 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)
GIT_VERSION: v2.0.0-beta1-5101-gc75bb66a99
GRAPH_DEF_VERSION: 119
GRAPH_DEF_VERSION_MIN_CONSUMER: 0
GRAPH_DEF_VERSION_MIN_PRODUCER: 0
VERSION: 2.0.0-rc0

NUMPY:
-----
1.17.1

PYTHON:
-------
3.7.4 (default, Jul  9 2019, 18:13:23) 
[Clang 10.0.1 (clang-1001.0.46.4)]

Train on 1 samples
WARNING:tensorflow:Entity <function Function._initialize_uninitialized_variables.<locals>.initialize_variables at 0x1492748c0> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: module 'gast' has no attribute 'Num'
WARNING: Entity <function Function._initialize_uninitialized_variables.<locals>.initialize_variables at 0x1492748c0> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: module 'gast' has no attribute 'Num'
1/1 [==============================] - 0s 157ms/sample - loss: 1.2336

<tensorflow.python.keras.callbacks.History at 0x14927b5d0>
@tocosastalo
Copy link

tocosastalo commented Sep 7, 2019

Hello,

3 hours ago, gast library was updated from 0.2.2 to 0.3.0 and Num constant was removed (check commit serge-sans-paille/gast@231ee7a#diff-88b99bb28683bd5b7e3a204826ead112R99).

TF requires gast>=0.2.0, so newer version of gast module is automatically installed and that's probably why it fails with error AttributeError: module 'gast' has no attribute 'Num'.

This error may occur for example on the line 236 in tensorflow/python/autograph/pyct/qual_names.py (https://github.com/tensorflow/tensorflow/blob/r1.14/tensorflow/python/autograph/pyct/qual_names.py#L236):

if isinstance(s.value, gast.Num):

@jlebar
Copy link
Contributor

jlebar commented Sep 8, 2019

@mgreenbe thank you for filing the bug, and @tocosastalo thanks for the info.

Workaround that worked for me: $ pip3 install 'gast==0.2.2'.

@ai-nikolai
Copy link

@jlebar & @tocosastalo & @mgreenbe thank you:

@mgreenbe thank you for filing the bug, and @tocosastalo thanks for the info.

Workaround that worked for me: $ pip3 install 'gast==0.2.2'.

This worked for me too: $ pip3 install gast==0.2.2.

@FeynmanDNA
Copy link

I encountered the same warning with tensorflow-gpu2.0beta1, and the above fix works for me too:

$ pip install gast==0.2.2
Collecting gast==0.2.2
Installing collected packages: gast
  Found existing installation: gast 0.3.1
    Uninstalling gast-0.3.1:
      Successfully uninstalled gast-0.3.1
Successfully installed gast-0.2.2

@mgreenbe
Copy link
Author

mgreenbe commented Sep 8, 2019

Using the older version of gast worked for me too. I'll leave it to @jlebar or someone else on the tensorflow team to close this issue at their discretion, presumably once tensorflow and gast=0.3.x are interacting nicely.

@mihaimaruseac
Copy link
Collaborator

#32332 fixes this for 1.15, there's a similar PR for 2.0 and a commit on master. Adding @goldiegadde as she is fixing this

@ravikyram ravikyram self-assigned this Sep 9, 2019
@ravikyram ravikyram added TF 2.0-rc0 type:build/install Build and install issues labels Sep 9, 2019
@ravikyram ravikyram assigned jvishnuvardhan and unassigned ravikyram Sep 9, 2019
@wchargin
Copy link
Contributor

wchargin commented Sep 10, 2019

I don’t understand what the status of this is. The corresponding commit
on master
hasn’t fixed this in nightlies:

$ cat test.py
import tensorflow as tf

print(tf.__version__)

@tf.function
def foo():
  return 1

foo()
$ AUTOGRAPH_VERBOSITY=10 python test.py
2.0.0-dev20190910
WARNING:tensorflow:Entity <function foo at 0x7f71ac1990d0> could not be transformed and will be executed as-is. Please report this to the AutoGraph team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: Bad argument number for Name: 3, expecting 4

Running pip install gast==0.2.2 fixes the above issue.

I’m not sure what those changes in pip_new.sh do, but is there a plan
to update the Pip dependencies in setup.py so that people who
simply run pip install tf-nightly-2.0-preview get a working install?

@mihaimaruseac
Copy link
Collaborator

Classical error of having same dependency specified in two places. I'll send a fix, sorry for this

@wchargin
Copy link
Contributor

wchargin commented Sep 10, 2019

thanks! and no worries :-)

yifeif pushed a commit that referenced this issue Sep 10, 2019
This fixes breakage caused by minor update breaking tensorflow.

PiperOrigin-RevId: 268261146
mihaimaruseac added a commit that referenced this issue Sep 10, 2019
This fixes breakage caused by minor update breaking tensorflow.

PiperOrigin-RevId: 268261146
mihaimaruseac added a commit that referenced this issue Sep 10, 2019
This fixes breakage caused by minor update breaking tensorflow.

PiperOrigin-RevId: 268261146
@mihaimaruseac
Copy link
Collaborator

Should be fixed by c72125b, #32390 and #32391 (the last two need merging before fixing on corresponding branches)

@jvishnuvardhan jvishnuvardhan removed their assignment Sep 10, 2019
mihaimaruseac added a commit that referenced this issue Sep 10, 2019
Freeze gast==0.2.2 (#32319) in setup.py requirements.
mihaimaruseac added a commit that referenced this issue Sep 10, 2019
Freeze gast==0.2.2 (#32319) in setup.py requirements.
@mihaimaruseac
Copy link
Collaborator

Should be fixed now, keeping issue open until verified

@arainboldt
Copy link

Thanks guys for the fix! Any chance we'll get a build for mac-python3.7?

@wchargin
Copy link
Contributor

Confirmed fixed for me on tf-nightly-2.0-preview==2.0.0.dev20190911. Thank you!

Feel free to close at your discretion.

@mihaimaruseac
Copy link
Collaborator

In that case, closing.

Thank you for verifying.

@arainboldt the fix should get released in all pips we are releasing.

@mihaimaruseac
Copy link
Collaborator

New update:

gast has been pinned to 0.2.2 for 1.15 and 2.0 and later releases as well as nightly.
TF 1.14 or earlier don't have gast pinned and won't get it as we are not doing more releases there (except for security vulnerabilities).

If you encounter this issue on 1.14 or earlier, please install gast==0.2.2 using pip before installing tensorflow.

dfalbel added a commit to rstudio/tfprobability that referenced this issue Oct 2, 2019
* testing right before checking

* move to the end

* try using python3

* use ubuntu xenial for python 3.6

* library before testing

* pin gast as a workarounf for tensorflow/tensorflow#32319

* define as_tensor on utils

* dont stop in failures right now

* remote test line
@bestwayyy
Copy link

I'm still getting the error even with gast 0.2.2.
I really need help to get this fixed.

@mihaimaruseac
Copy link
Collaborator

We are currently working on getting gast==0.3.2. Apologies for the delay.

tfgan-copybara-robot pushed a commit to tensorflow/gan that referenced this issue Jan 22, 2020
…ast version that supports TF1

Pin Gast to version 0.2.2 to address tensorflow/tensorflow#32319
When installing for TF2 on Python2, pin Tensorflow to 2.1.0 since that's the last version that supports Python2.

PiperOrigin-RevId: 291012176
Change-Id: I6910ee9b298a220415475ee0546ce28a64813cc3
@wookayin
Copy link
Contributor

Starting from TensorFlow 2.2.0, it will work with gast 0.3.x but NOT gast 0.2.x any more. For TF <= 2.1, gast 0.2.2 is needed.

@ddrous
Copy link

ddrous commented Jun 15, 2022

Thank you @wookayin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TF 2.0 Issues relating to TensorFlow 2.0 type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests