Update api.py (#18049)
authorDan Moldovan <mdan@google.com>
Wed, 28 Mar 2018 19:59:04 +0000 (15:59 -0400)
committerRasmus Munk Larsen <rmlarsen@google.com>
Wed, 28 Mar 2018 19:59:04 +0000 (12:59 -0700)
Avoid overwriting existing namespace items that might replace the converted functions.

tensorflow/contrib/autograph/impl/api.py

index 1c4fcaa..dce994e 100644 (file)
@@ -247,7 +247,10 @@ def to_graph(e,
   # The compiled code should see everything the entry function saw.
   # TODO(mdan): This might not work well if the call tree spans modules?
   if tf_inspect.isfunction(e):
-    compiled_node.__dict__.update(inspect_utils.getnamespace(e))
+    for key, val in inspect_utils.getnamespace(e).items():
+      # Avoid overwriting entities that have been transformed.
+      if key not in compiled_node.__dict__:
+        compiled_node.__dict__[key] = val
   compiled_fn = getattr(compiled_node, name)
 
   if verbose: