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

@tf.function works the first time running the code but fails afterwards on Spyder IDE. #241

Open
eliphatfs opened this issue Jul 18, 2020 · 2 comments

Comments

@eliphatfs
Copy link

I turned here from a TensorFlow issue related with Spyder.
I copy my contents there, together with an analysis.

import tensorflow as tf


@tf.function
def mean(a):
    return tf.reduce_mean(tf.abs(a))

Output:

runfile('D:/tfbug.py', wdir='D:/')

mean([1, 2])
Out[2]: <tf.Tensor: id=9, shape=(), dtype=int32, numpy=1>

mean([1, 2])
Out[3]: <tf.Tensor: id=10, shape=(), dtype=int32, numpy=1>

runfile('D:/tfbug.py', wdir='D:/')
Reloaded modules: tmpv1iph1dn

mean([1, 2])
WARNING: Logging before flag parsing goes to stderr.
W0718 20:43:06.847428 10664 ag_logging.py:146] Entity <function mean at 0x000000001DB28B70> 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: 
WARNING: Entity <function mean at 0x000000001DB28B70> 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: 
Out[5]: <tf.Tensor: id=19, shape=(), dtype=int32, numpy=1>

Appending the following code, the warning disappears:

try:
    import os
    import sys
    from spyder_kernels.customize import spydercustomize as spc
    if spc.__umr__ is None:
        namelist = os.environ.get("SPY_UMR_NAMELIST", None)
        if namelist is not None:
            namelist = namelist.split(',')
        spc.__umr__ = spc.UserModuleReloader(namelist=namelist)
    spc.__umr__.namelist += \
        list(filter(lambda x: x.startswith("tmp"), sys.modules.keys()))
except ImportError:
    pass

In umr.py where the User Module Reloader is defined, there is a blocklist which may cause issues with the reloader and won't be reloaded.
Here tf.function temporary modules are in a name starting with tmp, which may be a characteristic to match with.

My suggestions: Either

  • Add regex support or so to the user defined name list that is blocked from the reloader.

Or

  • Match tmp prefix and exclude from the reloading process.
@ccordoba12
Copy link
Member

Hey @strongrex2001, I'm very sorry for big delay in commenting about your suggestion (I totally missed this issue). Is it ok if for now we simply add this line

spc.__umr__.namelist += \
    list(filter(lambda x: x.startswith("tmp"), sys.modules.keys()))

and later consider how to implement the ability to exclude modules from our UMR using regexp's?

@eliphatfs
Copy link
Author

Sorry for my delay in reply, and.. no, since we only have the modules generated after tensorflow is run, and when umr is initialized there is no such tmp module in sys.modules.

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

2 participants