Omega
Omega

Reputation: 125

Issue: tf.function raising a warning and failing with tf.stack

I am having problems with tf.function in tensorflow. It seems to fail to convert functions containing the instruction tf.stack().

Here a simple code I wrote to highlight the issue:

import tensorflow as tf
c = tf.Variable([[1., 5.], [2., 4.]])
@tf.function
def toy_fct(x):
    y = tf.stack([x[0,:], x[1,:]], axis=0)
    return y
toy_fct(c)

The messages I get are the following:

WARNING:tensorflow:AutoGraph could not transform <function toy_fct at 0x000001DC9A13A670> and will run it as-is.
Please report this to the TensorFlow 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 'Index'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
WARNING: AutoGraph could not transform <function toy_fct at 0x000001DC9A13A670> and will run it as-is.
Please report this to the TensorFlow 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 'Index'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert

<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[1., 5.],
       [2., 4.]], dtype=float32)>

Does anybody have any idea?

Upvotes: 1

Views: 325

Answers (1)

Innat
Innat

Reputation: 17239

I've tested your code in tf 2.0 to tf 2.4 without any issue. But it appears when I used gast==0.4.0. Try this

pip install --upgrade pip
pip install gast==0.2.2

FYI, it runs fine with gast==0.4.0 with latest tf 2.5.0-rc0.

Upvotes: 1

Related Questions