Skip to content
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

ImportError: cannot import name 'cached_download' from 'huggingface_hub' #92

Closed
MoritzLaurer opened this issue Oct 21, 2024 · 4 comments · Fixed by #96
Closed

ImportError: cannot import name 'cached_download' from 'huggingface_hub' #92

MoritzLaurer opened this issue Oct 21, 2024 · 4 comments · Fixed by #96

Comments

@MoritzLaurer
Copy link

MoritzLaurer commented Oct 21, 2024

A dedicated inference endpoint using a custom handler just failed with the error below.
I think the cause is that huggingface_hub version 2.6.0 has removed the cached_download method and the endpoint seems to use this latest version (?), but huggingface-inference-toolkit still uses an older version huggingface_hub[hf_transfer]==0.24.5 (source).

Exit code: 1. Reason: ng(self.app)
  File "/usr/local/lib/python3.10/dist-packages/uvicorn/importer.py", line 19, in import_from_string
    module = importlib.import_module(module_str)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/app/webservice_starlette.py", line 19, in <module>
    from huggingface_inference_toolkit.handler import get_inference_handler_either_custom_or_default_handler
  File "/app/huggingface_inference_toolkit/handler.py", line 5, in <module>
    from huggingface_inference_toolkit.utils import check_and_register_custom_pipeline_from_directory, get_pipeline
  File "/app/huggingface_inference_toolkit/utils.py", line 13, in <module>
    from huggingface_inference_toolkit.diffusers_utils import (
  File "/app/huggingface_inference_toolkit/diffusers_utils.py", line 18, in <module>
    from diffusers import AutoPipelineForText2Image, DPMSolverMultistepScheduler, StableDiffusionPipeline
  File "/usr/local/lib/python3.10/dist-packages/diffusers/__init__.py", line 5, in <module>
    from .utils import (
  File "/usr/local/lib/python3.10/dist-packages/diffusers/utils/__init__.py", line 38, in <module>
    from .dynamic_modules_utils import get_class_from_dynamic_module
  File "/usr/local/lib/python3.10/dist-packages/diffusers/utils/dynamic_modules_utils.py", line 28, in <module>
    from huggingface_hub import cached_download, hf_hub_download, model_info
ImportError: cannot import name 'cached_download' from 'huggingface_hub' (/usr/local/lib/python3.10/dist-packages/huggingface_hub/__init__.py)
@MoritzLaurer
Copy link
Author

short-term fix in case someone encounters the same issue:
you can add huggingface_hub<0.26.0 to your requirements.txt file in your custom handler repository.

@Erreur-405
Copy link

short-term fix in case someone encounters the same issue: you can add huggingface_hub<0.26.0 to your requirements.txt file in your custom handler repository.

hello where is that file exactly please ? ive been spending hours looking for it, how can i access that repository ? ty

@MoritzLaurer
Copy link
Author

you mean where to find the requirements.txt file @Erreur-405 ? This depends on your setup and where/how you are encountering the error. HF spaces often have a requirements.txt file in the files tab, see e.g. this example space: https://huggingface.co/spaces/jadechoghari/OmniParser/tree/main

@MoritzLaurer
Copy link
Author

This is an example with a model repo with a custom handler and a requirements.txt file in the files tab: https://huggingface.co/sergeipetrov/asrdiarization-handler/tree/main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants