From 18c2cf989a2263ee212fbd5ac0b3085d9450b80a Mon Sep 17 00:00:00 2001 From: Mihai Maruseac Date: Thu, 5 Sep 2019 12:48:30 -0700 Subject: [PATCH] Explicitly assign keras and estimator as attributes. This is required just to fix a strange side effect of our wrappers for lazy loading, deprecation messages, forwarding and virtual pip which causes failures in ``` console >>> import tensorflow as tf >>> tf.keras # tf.estimator has same error ``` We will need much more time to debug this, but this change seems to be a good way to patch this for now. PiperOrigin-RevId: 267431746 --- tensorflow/virtual_root_template_v1.__init__.py | 4 ++++ tensorflow/virtual_root_template_v2.__init__.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tensorflow/virtual_root_template_v1.__init__.py b/tensorflow/virtual_root_template_v1.__init__.py index 9603ddca5c0..d341de2721a 100644 --- a/tensorflow/virtual_root_template_v1.__init__.py +++ b/tensorflow/virtual_root_template_v1.__init__.py @@ -129,4 +129,8 @@ try: del examples except NameError: pass + +# Manually patch keras and estimator so tf.keras and tf.estimator work +keras = _sys.modules["tensorflow.keras"] +if not _root_estimator: estimator = _sys.modules["tensorflow.estimator"] # LINT.ThenChange(//tensorflow/virtual_root_template_v2.__init__.py.oss) diff --git a/tensorflow/virtual_root_template_v2.__init__.py b/tensorflow/virtual_root_template_v2.__init__.py index dc3011c96ee..b3e101902be 100644 --- a/tensorflow/virtual_root_template_v2.__init__.py +++ b/tensorflow/virtual_root_template_v2.__init__.py @@ -122,4 +122,8 @@ try: del examples except NameError: pass + +# Manually patch keras and estimator so tf.keras and tf.estimator work +keras = _sys.modules["tensorflow.keras"] +if not _root_estimator: estimator = _sys.modules["tensorflow.estimator"] # LINT.ThenChange(//tensorflow/virtual_root_template_v1.__init__.py.oss)