Skip to content

Commit cf55dcf

Browse files
Fix Colab and Notebook checks for diffusers-cli env (huggingface#8408)
* chore: Update is_google_colab check to use environment variable * Check Colab with all possible COLAB_* env variables * Remove unnecessary word * Make `_is_google_colab` more inclusive * Revert "Make `_is_google_colab` more inclusive" This reverts commit 6406db2. * Make `_is_google_colab` more inclusive. * chore: Update import_utils.py with notebook check improvement * Refactor import_utils.py to improve notebook detection for VS Code's notebook * chore: Remove `is_notebook()` function and related code --------- Co-authored-by: Sayak Paul <[email protected]>
1 parent 7a95f8d commit cf55dcf

File tree

3 files changed

+2
-22
lines changed

3 files changed

+2
-22
lines changed

src/diffusers/commands/env.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
is_bitsandbytes_available,
2525
is_flax_available,
2626
is_google_colab,
27-
is_notebook,
2827
is_peft_available,
2928
is_safetensors_available,
3029
is_torch_available,
@@ -107,8 +106,6 @@ def run(self) -> dict:
107106

108107
platform_info = platform.platform()
109108

110-
is_notebook_str = "Yes" if is_notebook() else "No"
111-
112109
is_google_colab_str = "Yes" if is_google_colab() else "No"
113110

114111
accelerator = "NA"
@@ -123,7 +120,7 @@ def run(self) -> dict:
123120
out_str = out_str.decode("utf-8")
124121

125122
if len(out_str) > 0:
126-
accelerator = out_str.strip() + " VRAM"
123+
accelerator = out_str.strip()
127124
except FileNotFoundError:
128125
pass
129126
elif platform.system() == "Darwin": # Mac OS
@@ -155,7 +152,6 @@ def run(self) -> dict:
155152
info = {
156153
"🤗 Diffusers version": version,
157154
"Platform": platform_info,
158-
"Running on a notebook?": is_notebook_str,
159155
"Running on Google Colab?": is_google_colab_str,
160156
"Python version": platform.python_version(),
161157
"PyTorch version (GPU?)": f"{pt_version} ({pt_cuda_available})",

src/diffusers/utils/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
is_librosa_available,
7474
is_matplotlib_available,
7575
is_note_seq_available,
76-
is_notebook,
7776
is_onnx_available,
7877
is_peft_available,
7978
is_peft_version,

src/diffusers/utils/import_utils.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,7 @@ def is_timm_available():
321321
except importlib_metadata.PackageNotFoundError:
322322
_bitsandbytes_available = False
323323

324-
# Taken from `huggingface_hub`.
325-
_is_notebook = False
326-
try:
327-
shell_class = get_ipython().__class__ # type: ignore # noqa: F821
328-
for parent_class in shell_class.__mro__: # e.g. "is subclass of"
329-
if parent_class.__name__ == "ZMQInteractiveShell":
330-
_is_notebook = True # Jupyter notebook, Google colab or qtconsole
331-
break
332-
except NameError:
333-
pass # Probably standard Python interpreter
334-
335-
_is_google_colab = "google.colab" in sys.modules
324+
_is_google_colab = "google.colab" in sys.modules or any(k.startswith("COLAB_") for k in os.environ)
336325

337326

338327
def is_torch_available():
@@ -443,10 +432,6 @@ def is_bitsandbytes_available():
443432
return _bitsandbytes_available
444433

445434

446-
def is_notebook():
447-
return _is_notebook
448-
449-
450435
def is_google_colab():
451436
return _is_google_colab
452437

0 commit comments

Comments
 (0)