Skip to content

Commit ace2699

Browse files
SinaChavoshiTensorflow Cloud maintainers
authored andcommitted
Fix issue with detection of interactive environment for Vertex AI notebooks.
PiperOrigin-RevId: 385900781
1 parent 651b013 commit ace2699

File tree

1 file changed

+14
-15
lines changed
  • src/python/tensorflow_cloud/core

1 file changed

+14
-15
lines changed

src/python/tensorflow_cloud/core/run.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Module that contains the `run` API for scaling Keras/TensorFlow jobs."""
1515

16+
import logging
1617
import os
1718
import sys
1819
import uuid
@@ -23,6 +24,9 @@
2324
from . import machine_config
2425
from . import preprocess
2526
from . import validate
27+
from tensorflow_cloud.utils import google_api_client
28+
29+
logger = logging.getLogger(__name__)
2630

2731

2832
def remote():
@@ -304,8 +308,8 @@ def run(
304308
if preprocessed_entry_point is not None:
305309
os.close(pep_file_descriptor)
306310
os.remove(preprocessed_entry_point)
307-
for file_path, file_descriptor \
308-
in container_builder.get_generated_files(return_descriptors=True):
311+
for file_path, file_descriptor in container_builder.get_generated_files(
312+
return_descriptors=True):
309313
os.close(file_descriptor)
310314
os.remove(file_path)
311315

@@ -339,16 +343,11 @@ def run(
339343

340344
def _called_from_notebook():
341345
"""Detects if we are currently executing in a notebook environment."""
342-
try:
343-
import IPython # pylint: disable=g-import-not-at-top
344-
except ImportError:
345-
return False
346-
347-
try:
348-
shell = IPython.get_ipython().__class__.__name__
349-
if "Shell" in shell:
350-
return True
351-
else:
352-
return False
353-
except NameError:
354-
return False
346+
client_env = google_api_client.get_client_environment_name()
347+
if client_env in (
348+
google_api_client.ClientEnvironment.KAGGLE_NOTEBOOK.name,
349+
google_api_client.ClientEnvironment.COLAB.name):
350+
return True
351+
if client_env == google_api_client.ClientEnvironment.HOSTED_NOTEBOOK:
352+
logger.warning("Vertex AI notebook environment is not supported.")
353+
return False

0 commit comments

Comments
 (0)