-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Fix Colab and Notebook checks for diffusers-cli env
#8408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
diffusers-cli env
diffusers-cli env
diffusers-cli env
diffusers-cli env
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why I was tagged to review this as I never use colab :D
I've seen conflicting information online about what does or does not work to detect the colab environment. This is probably also something that has changed over time.
As is, the current method works for me, as does the suggested change:
I wouldn't feel comfortable making this change before we understand what works in what circumstances.
|
Oh I see, so somehow Google Colab injects the library into ipython but not into python: !python -c 'import sys;print("google.colab" in sys.modules)'
False
!ipython -c 'import sys;print("google.colab" in sys.modules)'
22;0tTrue Relying on a single env var still sounds fragile to me, as there is no guarantee that this can't change at any moment. The most official statement I've seen is this reddit commit by a Google Colab employee, and this uses the current approach. I wonder if we should check if |
Also, |
Even with the proposed changes? |
I meant this: diffusers/src/diffusers/utils/import_utils.py Lines 324 to 333 in 0d68ddf
get_ipython() can be run in a notebook/ipython. But, it is in a .py file 🤔.
|
This reverts commit 6406db2.
…rs into fix-envinfo-notebook
Can/Should I remove |
I see. Indeed that doesn't work inside a colab notebook but at least locally, it works in a Jupyter notebook. So maybe we can extend the logic to say |
When I run |
We could include the logic of Colab check within the scope of the notebooks, too if that makes sense? |
Ah yes you're right, sorry for my mistake. At least in my environment, I see that jupyter sets |
src/diffusers/utils/import_utils.py
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is more generic in this way, right?
Btw, this gives Yes
in a conventional Jupyter notebook; but gives No
in VS Code's notebook :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I add any(k.startswith("VSCODE") for k in os.environ)
as well? No, this gives Yes
in VS Code's terminal too. But, "VSCODE_CLI" env var seems to give Yes
only in the VS Code notebook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we can't cover all possible cases. Honestly, I'm not sure why we need this information. For acccelerate
it is because there is a special notebook launcher. I don't know if/how this helps debugging diffusers
, so I can't say what cases we need to cover.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just removed the notebook check completely. Let's merge this? |
@BenjaminBossan WDYT? So, from what I understand, we are removing the notebook check because it can be broken and we cannot be deterministic most of the times, yeah? |
So my understanding is that the As to whether it's needed: I don't know enough about diffusers to answer that. Would it in any way help to debug diffusers issue if we had this information? If not, I would tend to remove it. If yes, I'd keep it, even if it's not super reliable. |
Yeah I don’t think having this information is super important for debugging purposes TBH. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @tolgacangoz for fixing this and for your patience.
Yeah I don’t think having this information is super important for debugging purposes TBH.
In that case, the PR LGTM. I'll leave the final review and merge to @sayakpaul.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
Thanks for the approvals! @DN6 Gently pinging here. |
Sorry for the delay @tolgacangoz appreciate your patience here. |
Thanks all for the reviews and merging! |
* 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 <spsayakpaul@gmail.com>
This pull request updates the
is_google_colab
check to use an environment variable instead of checking for the presence of thegoogle.colab
module. This change ensures that the check is more reliable. Currently,!diffusers-cli env
in a Colab's cell gives No.Also, the check of
is_notebook
gives No if someone commands!diffusers-cli env
in a notebook cell. Because, I guess, the checking code is run in a.py
file? What to do here? I took this check fromhuggingface_hub
. At the expansion proposal PR, I don't remember if I tried the command in a cell. Probably I tried the checking code directly within a cell. This was foris_google_colab
as well. Should I removeis_notebook
completely?