|
13 | 13 | # limitations under the License.
|
14 | 14 | """Module that contains the `run` API for scaling Keras/TensorFlow jobs."""
|
15 | 15 |
|
| 16 | +import logging |
16 | 17 | import os
|
17 | 18 | import sys
|
18 | 19 | import uuid
|
|
23 | 24 | from . import machine_config
|
24 | 25 | from . import preprocess
|
25 | 26 | from . import validate
|
| 27 | +from tensorflow_cloud.utils import google_api_client |
| 28 | + |
| 29 | +logger = logging.getLogger(__name__) |
26 | 30 |
|
27 | 31 |
|
28 | 32 | def remote():
|
@@ -304,8 +308,8 @@ def run(
|
304 | 308 | if preprocessed_entry_point is not None:
|
305 | 309 | os.close(pep_file_descriptor)
|
306 | 310 | 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): |
309 | 313 | os.close(file_descriptor)
|
310 | 314 | os.remove(file_path)
|
311 | 315 |
|
@@ -339,16 +343,11 @@ def run(
|
339 | 343 |
|
340 | 344 | def _called_from_notebook():
|
341 | 345 | """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