huggingface / huggingface_hub

The official Python client for the Huggingface Hub.
https://huggingface.co/docs/huggingface_hub
Apache License 2.0
2.03k stars 531 forks source link

error with `snapshot_download` #2200

Closed not-lain closed 6 months ago

not-lain commented 6 months ago

Describe the bug

cannot download a public repo

Reproduction

from huggingface_hub import snapshot_download snapshot_download("Maikou/Michelangelo")

Logs

TypeError                                 Traceback (most recent call last)
<ipython-input-20-4216198be399> in <cell line: 2>()
      1 from huggingface_hub import snapshot_download , hf_hub_download
----> 2 snapshot_download("Maikou/Michelangelo")

1 frames
/usr/local/lib/python3.10/dist-packages/huggingface_hub/_snapshot_download.py in snapshot_download(repo_id, repo_type, revision, cache_dir, local_dir, local_dir_use_symlinks, library_name, library_version, user_agent, proxies, etag_timeout, resume_download, force_download, token, local_files_only, allow_patterns, ignore_patterns, max_workers, tqdm_class, headers, endpoint)
    177         try:
    178             # if we have internet connection we want to list files to download
--> 179             api = HfApi(
    180                 library_name=library_name,
    181                 library_version=library_version,

TypeError: HfApi.__init__() got an unexpected keyword argument 'headers'

System info

- huggingface_hub version: 0.20.3
- 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 ?: True
- Who am I ?: not-lain
- Configured git credential helpers: 
- FastAI: 2.7.14
- Tensorflow: 2.15.0
- Torch: 2.2.1+cu121
- Jinja2: 3.1.3
- Graphviz: 0.20.3
- Pydot: 1.4.2
- Pillow: 9.4.0
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: 1.25.2
- pydantic: 2.6.4
- aiohttp: 3.9.3
- 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.3',
 '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 ?': True,
 'Who am I ?': 'not-lain',
 'Configured git credential helpers': '',
 'FastAI': '2.7.14',
 'Tensorflow': '2.15.0',
 'Torch': '2.2.1+cu121',
 'Jinja2': '3.1.3',
 'Graphviz': '0.20.3',
 'Pydot': '1.4.2',
 'Pillow': '9.4.0',
 'hf_transfer': 'N/A',
 'gradio': 'N/A',
 'tensorboard': 'N/A',
 'numpy': '1.25.2',
 'pydantic': '2.6.4',
 'aiohttp': '3.9.3',
 '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}
not-lain commented 6 months ago

I know it works with other repos but not sure why this one is broken, I can get around this just fine with hf_hub_download, but that would mean me downloading each and every file manually but i'm too cute for that, and cloning the repo works fine too but it's not huggingface tool so I give it an L . TLDR; this is me without snapshot_download : (┬┬﹏┬┬)

Wauplin commented 6 months ago

Hi @not-lain, I think that for some reason there is a problem in your setup. In huggingface_hub v0.20.3 (the one you are reporting), the headers parameters in not passed on that line (see https://github.com/huggingface/huggingface_hub/blob/v0.20.3/src/huggingface_hub/_snapshot_download.py#L176). headers has been introduced in v0.22.0 (see https://github.com/huggingface/huggingface_hub/blob/v0.22.0/src/huggingface_hub/_snapshot_download.py#L184). But it's not an issue specific to this repo id.

FWIW, latest version is v.0.22.2 so I just advice you to pip uninstall -y huggingface_hub + pip install -U huggingface_hub (to be sure corrupted install is completely removed). I'll close this issue but let me know if the problem persists.