huggingface_hub icon indicating copy to clipboard operation
huggingface_hub copied to clipboard

Logout raises warning in Colab

Open osanseviero opened this issue 1 year ago • 3 comments

Describe the bug

In Google Colab, if I have no HF_TOKEN secret, I get a long error

Reproduction

from huggingface_hub import logout

logout()

Logs

/usr/local/lib/python3.10/dist-packages/huggingface_hub/_login.py:337: UserWarning: 
The secret `HF_TOKEN` does not exist in your Colab secrets.
To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.
You will be able to reuse this secret in all of your notebooks.
Please note that authentication is recommended but still optional to access public models or datasets.
  warnings.warn(
Successfully logged out.
/usr/local/lib/python3.10/dist-packages/huggingface_hub/_login.py:337: UserWarning: 
The secret `HF_TOKEN` does not exist in your Colab secrets.
To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.
You will be able to reuse this secret in all of your notebooks.
Please note that authentication is recommended but still optional to access public models or datasets.
  warnings.warn(


### System info

```shell
Copy-and-paste the text below in your GitHub issue.

- huggingface_hub version: 0.20.0
- Platform: Linux-6.1.58+-x86_64-with-glibc2.35
- Python version: 3.10.12
- Running in iPython ?: Yes
- iPython shell: Shell
- Running in notebook ?: Yes
- Running in Google Colab ?: Yes
- Token path ?: /root/.cache/huggingface/token
- Has saved token ?: False
- Configured git credential helpers: store
- FastAI: 2.7.13
- Tensorflow: 2.15.0
- Torch: 2.1.0+cu121
- Jinja2: 3.1.2
- Graphviz: 0.20.1
- Pydot: 1.4.2
- Pillow: 9.4.0
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: 1.23.5
- pydantic: 1.10.13
- aiohttp: 3.9.1
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /root/.cache/huggingface/hub
- HF_ASSETS_CACHE: /root/.cache/huggingface/assets
- HF_TOKEN_PATH: /root/.cache/huggingface/token
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10

{'huggingface_hub version': '0.20.0',
 'Platform': 'Linux-6.1.58+-x86_64-with-glibc2.35',
 'Python version': '3.10.12',
 'Running in iPython ?': 'Yes',
 'iPython shell': 'Shell',
 'Running in notebook ?': 'Yes',
 'Running in Google Colab ?': 'Yes',
 'Token path ?': '/root/.cache/huggingface/token',
 'Has saved token ?': False,
 'Configured git credential helpers': 'store',
 'FastAI': '2.7.13',
 'Tensorflow': '2.15.0',
 'Torch': '2.1.0+cu121',
 'Jinja2': '3.1.2',
 'Graphviz': '0.20.1',
 'Pydot': '1.4.2',
 'Pillow': '9.4.0',
 'hf_transfer': 'N/A',
 'gradio': 'N/A',
 'tensorboard': 'N/A',
 'numpy': '1.23.5',
 'pydantic': '1.10.13',
 'aiohttp': '3.9.1',
 'ENDPOINT': 'https://huggingface.co',
 'HF_HUB_CACHE': '/root/.cache/huggingface/hub',
 'HF_ASSETS_CACHE': '/root/.cache/huggingface/assets',
 'HF_TOKEN_PATH': '/root/.cache/huggingface/token',
 'HF_HUB_OFFLINE': False,
 'HF_HUB_DISABLE_TELEMETRY': False,
 'HF_HUB_DISABLE_PROGRESS_BARS': None,
 'HF_HUB_DISABLE_SYMLINKS_WARNING': False,
 'HF_HUB_DISABLE_EXPERIMENTAL_WARNING': False,
 'HF_HUB_DISABLE_IMPLICIT_TOKEN': False,
 'HF_HUB_ENABLE_HF_TRANSFER': False,
 'HF_HUB_ETAG_TIMEOUT': 10,
 'HF_HUB_DOWNLOAD_TIMEOUT': 10}

osanseviero avatar Dec 20 '23 10:12 osanseviero

This is kinda expected, no? It's not really an error, it's a warning. The idea is to get quicker adoption by having a warning explaining authentication on Colab when a user tries to authenticate.

For the specific huggingface_hub.logout it feels kinda weird but looks like a corner case no? The logout mechanism should be to disable the HF_TOKEN secret in the Colab settings directly.

Wauplin avatar Dec 20 '23 10:12 Wauplin

Yes, I think it's a bug in the case of logout, but I agree it's clearly a corner case.

To clarify, doing logout will not remove the secret, is that correct?

osanseviero avatar Dec 20 '23 10:12 osanseviero

To clarify, doing logout will not remove the secret, is that correct?

That is correct.

However if the secret exists + is shared with the notebook and you call logout, an error will be raised to tell you that you are not logged out. <= this is the real use case that we should take care of IMO.

image

Yes, I think it's a bug in the case of logout, but I agree it's clearly a corner case.

To clarify, this corner case happens only if HF_TOKEN does not exist in your secrets. If it exists but is not shared with the notebook, the warning would be different. We can modify the workflow for logout specifically but low priority imo.

Wauplin avatar Dec 20 '23 11:12 Wauplin