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

Autograph failure with \ #35765

Closed
emailweixu opened this issue Jan 11, 2020 · 8 comments
Closed

Autograph failure with \ #35765

emailweixu opened this issue Jan 11, 2020 · 8 comments
Assignees
Labels
comp:autograph Autograph related issues TF 2.1 for tracking issues in 2.1 release type:bug Bug

Comments

@emailweixu
Copy link

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): v2.1.0-rc2-17-ge5bf8de 2.1.0
  • Python version: 3.6
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory: Nvidia RTX 2080

Describe the current behavior
Tensorflow shows warning about failure of autograph

WARNING:tensorflow:AutoGraph could not transform <bound method C.f of <__main__.C object at 0x7f4a83904668>> 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: expected exactly one node node, found [<gast.gast.FunctionDef object at 0x7f4a47e0d5c0>, <gast.gast.Return object at 0x7f4a47e0df28>]

The warning seems to be caused by the backslash "\".

Describe the expected behavior
There should be no such warning

Code to reproduce the issue

import tensorflow as tf

class C(object):
    def f(self):
        # error disappear if \ in the following line is removed
        a = \
            1
        return a

obj = C()

@tf.function
def func():
    mem =  obj.f()
    return mem

def main():
    print(func())

if __name__ == "__main__":
    main()
emailweixu added a commit to HorizonRobotics/alf that referenced this issue Jan 11, 2020
TF autograph has bug handling `\` (tensorflow/tensorflow#35765)
emailweixu added a commit to HorizonRobotics/alf that referenced this issue Jan 12, 2020
TF autograph has bug handling `\` (tensorflow/tensorflow#35765)
@oanush oanush self-assigned this Jan 13, 2020
@oanush oanush added comp:autograph Autograph related issues TF 2.1 for tracking issues in 2.1 release type:bug Bug labels Jan 13, 2020
@oanush oanush assigned jvishnuvardhan and unassigned oanush Jan 13, 2020
@r-wheeler
Copy link

Just ran into this as well, removing the slash fixed it.

@jvishnuvardhan
Copy link
Contributor

I am closing this as the related PR fix merged. Thanks!

@tensorflow-bot
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@tensorflow tensorflow deleted a comment from tensorflow-bot bot Jan 14, 2020
@emailweixu
Copy link
Author

@jvishnuvardhan which PR fixed this bug?

@jvishnuvardhan
Copy link
Contributor

@emailweixu Sorry. I thought it was merged into master branch in tensorflow. It was my mistake. I am reopening it. Thanks!

MokkeMeguru added a commit to MokkeMeguru/TFGENZOO that referenced this issue Jan 15, 2020
Haichao-Zhang pushed a commit to Haichao-Zhang/alf that referenced this issue Jan 15, 2020
@jvishnuvardhan jvishnuvardhan added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jan 15, 2020
@mdanatg
Copy link

mdanatg commented Jan 15, 2020

Looks like a bug in the parser. dedent_block seems to be confused by the backslash continuation:

s = r'''
    def f():
        a = \
            1
        return a
'''

print(dedent_block(s))
def f():
    a = \
    1
return a

@mdanatg
Copy link

mdanatg commented Jan 17, 2020

For a workaround until this is fixed, note that you can use parentheses to break expressions on multiple lines:

a = (
    1)

@tensorflow-bot
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@goldiegadde goldiegadde added this to Done in TensorFlow 2.2.0 Feb 6, 2020
zhangxuan1918 added a commit to zhangxuan1918/tensorflow3DMMRendering that referenced this issue Mar 15, 2020
WeichenXu123 added a commit to uber/petastorm that referenced this issue Apr 21, 2020
Currently, for some function, TF2 autograph will fail.
See
tensorflow/tensorflow#35765
tensorflow/tensorflow#30149
tensorflow/autograph#3

If autograph failed, the functions will be run eagerly and TF cannot optimize them. So we'd better address them.


## Manually test
~~~python
df1 = spark.range(100)
from petastorm.spark import make_spark_converter

# Set a cache directory on DBFS FUSE for intermediate data.
spark.conf.set("petastorm.spark.converter.parentCacheDirUrl", "file:///dbfs/ml/tmp/petastorm/QA/bugs/")
converter1 = make_spark_converter(df1)

with converter1.make_tf_dataset(num_epochs=1) as dataset:
  for batch in dataset:
    print(batch.id)
~~~

* Before
Output includes:
```
WARNING:tensorflow:AutoGraph could not transform <function _NamedtupleCache.get at 0x7f0bfbe6f200> 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: expected exactly one node node, found [<gast.gast.FunctionDef object at 0x7f0bfad5d050>, <gast.gast.Return object at 0x7f0bfad5d7d0>]
WARNING:tensorflow:AutoGraph could not transform <function make_petastorm_dataset.<locals>.<lambda> at 0x7f0bf8da03b0> and will run it as-is.
Cause: could not parse the source code:

            .map(lambda row: _set_shape_to_named_tuple(reader.schema, row, reader.batched_output))

This error may be avoided by creating the lambda in a standalone statement.
```

* After
The warnings listed above disappear.
liuhenry added a commit to liuhenry/gkp-rl that referenced this issue Aug 19, 2020
Autograph isn't able to trace functions with a backslash continuation,
see: tensorflow/tensorflow#35765
tkakantousis pushed a commit to logicalclocks/petastorm that referenced this issue Sep 16, 2020
Currently, for some function, TF2 autograph will fail.
See
tensorflow/tensorflow#35765
tensorflow/tensorflow#30149
tensorflow/autograph#3

If autograph failed, the functions will be run eagerly and TF cannot optimize them. So we'd better address them.


## Manually test
~~~python
df1 = spark.range(100)
from petastorm.spark import make_spark_converter

# Set a cache directory on DBFS FUSE for intermediate data.
spark.conf.set("petastorm.spark.converter.parentCacheDirUrl", "file:///dbfs/ml/tmp/petastorm/QA/bugs/")
converter1 = make_spark_converter(df1)

with converter1.make_tf_dataset(num_epochs=1) as dataset:
  for batch in dataset:
    print(batch.id)
~~~

* Before
Output includes:
```
WARNING:tensorflow:AutoGraph could not transform <function _NamedtupleCache.get at 0x7f0bfbe6f200> 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: expected exactly one node node, found [<gast.gast.FunctionDef object at 0x7f0bfad5d050>, <gast.gast.Return object at 0x7f0bfad5d7d0>]
WARNING:tensorflow:AutoGraph could not transform <function make_petastorm_dataset.<locals>.<lambda> at 0x7f0bf8da03b0> and will run it as-is.
Cause: could not parse the source code:

            .map(lambda row: _set_shape_to_named_tuple(reader.schema, row, reader.batched_output))

This error may be avoided by creating the lambda in a standalone statement.
```

* After
The warnings listed above disappear.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:autograph Autograph related issues TF 2.1 for tracking issues in 2.1 release type:bug Bug
Projects
Development

No branches or pull requests

6 participants