From 3a368f28feb4daf531ef1f03a2e0093173bb53db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tolga=20Cang=C3=B6z?= Date: Mon, 3 Jun 2024 10:15:56 +0300 Subject: [PATCH 1/9] chore: Update is_google_colab check to use environment variable --- src/diffusers/utils/import_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index 6f70f5888910..206acf292af3 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -333,7 +333,7 @@ def is_timm_available(): except NameError: pass # Probably standard Python interpreter -_is_google_colab = "google.colab" in sys.modules +_is_google_colab = bool(os.getenv("COLAB_RELEASE_TAG")) def is_torch_available(): From dd71787ba592b578320bcba9425bf259c92f92f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tolga=20Cang=C3=B6z?= Date: Fri, 7 Jun 2024 09:51:46 +0300 Subject: [PATCH 2/9] Check Colab with all possible COLAB_* env variables --- src/diffusers/utils/import_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index 206acf292af3..12e61ac816b5 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -333,7 +333,7 @@ def is_timm_available(): except NameError: pass # Probably standard Python interpreter -_is_google_colab = bool(os.getenv("COLAB_RELEASE_TAG")) +_is_google_colab = any(k.startswith("COLAB_") for k in os.environ) def is_torch_available(): From 82ef0cc6da651cb3ca81da03460d5c9e39dba30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tolga=20Cang=C3=B6z?= Date: Fri, 7 Jun 2024 10:09:34 +0300 Subject: [PATCH 3/9] Remove unnecessary word --- src/diffusers/commands/env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/commands/env.py b/src/diffusers/commands/env.py index 7a6b598469a8..db6235147619 100644 --- a/src/diffusers/commands/env.py +++ b/src/diffusers/commands/env.py @@ -123,7 +123,7 @@ def run(self) -> dict: out_str = out_str.decode("utf-8") if len(out_str) > 0: - accelerator = out_str.strip() + " VRAM" + accelerator = out_str.strip() except FileNotFoundError: pass elif platform.system() == "Darwin": # Mac OS From 6406db21ac46139c20ccae20ccb44877eec87ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tolga=20Cang=C3=B6z?= Date: Fri, 7 Jun 2024 15:54:45 +0300 Subject: [PATCH 4/9] Make `_is_google_colab` more inclusive --- src/diffusers/utils/import_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index 12e61ac816b5..1662142ba62d 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -333,7 +333,7 @@ def is_timm_available(): except NameError: pass # Probably standard Python interpreter -_is_google_colab = any(k.startswith("COLAB_") for k in os.environ) +_is_google_colab = "google.colab" in sys.modules or any(k.startswith("COLAB_") for k in os.environ) def is_torch_available(): From c1d57b4e7f5ed6e643e9b0ae16ecfbf863aa8b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tolga=20Cang=C3=B6z?= Date: Fri, 7 Jun 2024 15:59:07 +0300 Subject: [PATCH 5/9] Revert "Make `_is_google_colab` more inclusive" This reverts commit 6406db21ac46139c20ccae20ccb44877eec87ba7. --- src/diffusers/utils/import_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index 1662142ba62d..12e61ac816b5 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -333,7 +333,7 @@ def is_timm_available(): except NameError: pass # Probably standard Python interpreter -_is_google_colab = "google.colab" in sys.modules or any(k.startswith("COLAB_") for k in os.environ) +_is_google_colab = any(k.startswith("COLAB_") for k in os.environ) def is_torch_available(): From 7e102a025070893145c1907c0935d23cd0ed398b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tolga=20Cang=C3=B6z?= Date: Fri, 7 Jun 2024 16:01:45 +0300 Subject: [PATCH 6/9] Make `_is_google_colab` more inclusive. --- src/diffusers/utils/import_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index 12e61ac816b5..1662142ba62d 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -333,7 +333,7 @@ def is_timm_available(): except NameError: pass # Probably standard Python interpreter -_is_google_colab = any(k.startswith("COLAB_") for k in os.environ) +_is_google_colab = "google.colab" in sys.modules or any(k.startswith("COLAB_") for k in os.environ) def is_torch_available(): From ff3a4d7aae2a2f1d9b77d0e2bf477051c4e05492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tolga=20Cang=C3=B6z?= Date: Wed, 19 Jun 2024 17:45:18 +0300 Subject: [PATCH 7/9] chore: Update import_utils.py with notebook check improvement --- src/diffusers/utils/import_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index fb14e8c6d1fc..f9e1cf469c5d 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -321,7 +321,7 @@ def is_timm_available(): except importlib_metadata.PackageNotFoundError: _bitsandbytes_available = False -# Taken from `huggingface_hub`. +# try part is taken from `huggingface_hub`. _is_notebook = False try: shell_class = get_ipython().__class__ # type: ignore # noqa: F821 @@ -330,7 +330,7 @@ def is_timm_available(): _is_notebook = True # Jupyter notebook, Google colab or qtconsole break except NameError: - pass # Probably standard Python interpreter + _is_notebook = any(k.startswith("JPY_") for k in os.environ) _is_google_colab = "google.colab" in sys.modules or any(k.startswith("COLAB_") for k in os.environ) From 63d99e0f14cde56d6ccc486f9ee849ece46e8430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tolga=20Cang=C3=B6z?= Date: Wed, 19 Jun 2024 17:57:53 +0300 Subject: [PATCH 8/9] Refactor import_utils.py to improve notebook detection for VS Code's notebook --- src/diffusers/utils/import_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index f9e1cf469c5d..fe2a48312068 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -330,7 +330,7 @@ def is_timm_available(): _is_notebook = True # Jupyter notebook, Google colab or qtconsole break except NameError: - _is_notebook = any(k.startswith("JPY_") for k in os.environ) + _is_notebook = any(k.startswith("JPY_") or k == "VSCODE_CLI" for k in os.environ) _is_google_colab = "google.colab" in sys.modules or any(k.startswith("COLAB_") for k in os.environ) From 7981d7614f0ca76654f2179b7314f08a1fd8d572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tolga=20Cang=C3=B6z?= Date: Fri, 21 Jun 2024 22:03:49 +0300 Subject: [PATCH 9/9] chore: Remove `is_notebook()` function and related code --- src/diffusers/commands/env.py | 4 ---- src/diffusers/utils/__init__.py | 1 - src/diffusers/utils/import_utils.py | 15 --------------- 3 files changed, 20 deletions(-) diff --git a/src/diffusers/commands/env.py b/src/diffusers/commands/env.py index db6235147619..d0af30bf1c65 100644 --- a/src/diffusers/commands/env.py +++ b/src/diffusers/commands/env.py @@ -24,7 +24,6 @@ is_bitsandbytes_available, is_flax_available, is_google_colab, - is_notebook, is_peft_available, is_safetensors_available, is_torch_available, @@ -107,8 +106,6 @@ def run(self) -> dict: platform_info = platform.platform() - is_notebook_str = "Yes" if is_notebook() else "No" - is_google_colab_str = "Yes" if is_google_colab() else "No" accelerator = "NA" @@ -155,7 +152,6 @@ def run(self) -> dict: info = { "🤗 Diffusers version": version, "Platform": platform_info, - "Running on a notebook?": is_notebook_str, "Running on Google Colab?": is_google_colab_str, "Python version": platform.python_version(), "PyTorch version (GPU?)": f"{pt_version} ({pt_cuda_available})", diff --git a/src/diffusers/utils/__init__.py b/src/diffusers/utils/__init__.py index 1612ca5ae4c0..f41edfcda3d8 100644 --- a/src/diffusers/utils/__init__.py +++ b/src/diffusers/utils/__init__.py @@ -73,7 +73,6 @@ is_librosa_available, is_matplotlib_available, is_note_seq_available, - is_notebook, is_onnx_available, is_peft_available, is_peft_version, diff --git a/src/diffusers/utils/import_utils.py b/src/diffusers/utils/import_utils.py index fe2a48312068..44477df2e220 100644 --- a/src/diffusers/utils/import_utils.py +++ b/src/diffusers/utils/import_utils.py @@ -321,17 +321,6 @@ def is_timm_available(): except importlib_metadata.PackageNotFoundError: _bitsandbytes_available = False -# try part is taken from `huggingface_hub`. -_is_notebook = False -try: - shell_class = get_ipython().__class__ # type: ignore # noqa: F821 - for parent_class in shell_class.__mro__: # e.g. "is subclass of" - if parent_class.__name__ == "ZMQInteractiveShell": - _is_notebook = True # Jupyter notebook, Google colab or qtconsole - break -except NameError: - _is_notebook = any(k.startswith("JPY_") or k == "VSCODE_CLI" for k in os.environ) - _is_google_colab = "google.colab" in sys.modules or any(k.startswith("COLAB_") for k in os.environ) @@ -443,10 +432,6 @@ def is_bitsandbytes_available(): return _bitsandbytes_available -def is_notebook(): - return _is_notebook - - def is_google_colab(): return _is_google_colab