Skip to content

cannot import name 'cached_download' from 'huggingface_hub' #1851

Closed

Description

@Trantu1102

Describe the bug
cannot import name 'cached_download' from 'huggingface_hub'

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS:
  • Browser:
  • Version:

Smartphone (please complete the following information):

  • Device:
  • OS:
  • Browser
  • Version

Additional context
Add any other context about the problem here.

Activity

  1. vertikalm commented on Oct 19, 2024

    @vertikalm

    Same error with a fresh and clean Debian 12

  2. XDM-Inc commented on Oct 20, 2024

    @XDM-Inc

    same issue here, it looks like hugging face changed a lot of urls and i think thats what messed things up a bit. thats my educated guess because when i try go to the website its asking for it says 404 page not found

  3. orossant commented on Oct 20, 2024

    @orossant

    same issues on fresh install on Mac. the failed msg mention a folder and file that exist even if the path is a quite long string : ImportError: cannot import name 'cached_download' from 'huggingface_hub'
    (/Documents/MyTP/easy-diffusion/installer_files/env/lib/python3.8/sitepackages/huggingface_hub/init.py)

  4. SrushtiPednekar commented on Oct 20, 2024

    @SrushtiPednekar

    same issue here

  5. xezwary commented on Oct 20, 2024

    @xezwary

    I removed cached_download from the import line in the file /easy-diffusion/installer_files/env/lib/python3.8/site-packages/diffusers/utils/dynamic_modules_utils.py
    That fixed it for me

  6. XDM-Inc commented on Oct 20, 2024

    @XDM-Inc

    I removed cached_download from the import line in the file /easy-diffusion/installer_files/env/lib/python3.8/site-packages/diffusers/utils/dynamic_modules_utils.py That fixed it for me

    That I did the trick! 👍
    Now I just got to figure out how to get my Radeon 7900 xtx on working and I'll be off to the races

  7. hudsonventura commented on Oct 22, 2024

    @hudsonventura

    I removed cached_download from the import line in the file /easy-diffusion/installer_files/env/lib/python3.8/site-packages/diffusers/utils/dynamic_modules_utils.py That fixed it for me

    @xezwary, you tip works to me. Thanks.

  8. QueryType commented on Oct 24, 2024

    @QueryType

    same issues on fresh install on Mac. the failed msg mention a folder and file that exist even if the path is a quite long string : ImportError: cannot import name 'cached_download' from 'huggingface_hub' (/Documents/MyTP/easy-diffusion/installer_files/env/lib/python3.8/sitepackages/huggingface_hub/init.py)

    Same here. I applied the workaround and got an astronaut on a horse

  9. guangchen811 commented on Oct 25, 2024

    @guangchen811

    This issue seems to arise from a breaking change in huggingface_hub version 0.26.0, where the cached_download() function has been fully removed. Downgrading to an earlier version of huggingface_hub should resolve this problem.

    More details: https://github.com/huggingface/huggingface_hub/releases/tag/v0.26.0

  10. Bassaoud commented on Oct 27, 2024

    @Bassaoud

    Describe the bug cannot import name 'cached_download' from 'huggingface_hub'

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS:
    • Browser:
    • Version:

    Smartphone (please complete the following information):

    • Device:
    • OS:
    • Browser
    • Version

    Additional context Add any other context about the problem here.

    solution seems to here. While downgrading version i get this warning :
    FutureWarning: 'cached_download' (from 'huggingface_hub.file_download') is deprecated and will be removed from version '0.26'. Use hf_hub_download instead.

  11. thakral-kartik commented on Oct 27, 2024

    @thakral-kartik

    Downgrading from 0.26.1 to 0.20.2 worked for me.

  12. lauraaisling commented on Oct 28, 2024

    @lauraaisling

    Likewise, downgrading to 0.25.0 seems to work, so it must be something with 0.26.

  13. Bassaoud commented on Oct 28, 2024

    @Bassaoud

    SOLUTION : Replace cached_download by hf_hub_download in your model.py.

  14. VioletaChatalbasheva commented on Oct 28, 2024

    @VioletaChatalbasheva

    You could also update diffusers to the latest version which seems to be working without cached_download

  15. 14 remaining items

  16. cmdr2 commented on Dec 11, 2024

    @cmdr2
    Collaborator

    @Undefinedefity @rainleon @ishandutta2007 Sorry, but were you still facing this problem? Easy Diffusion already pins huggingface_hub to 0.21.4 (which shouldn't face this problem).

    I pushed that fix nearly a month ago (Nov 15).

    Since you've replied after the fix was pushed, I'm curious whether you're still facing this problem. Thanks!

  17. reopened this on Dec 11, 2024
  18. cmdr2 commented on Dec 17, 2024

    @cmdr2
    Collaborator

    Closing this, since it was fixed and I haven't heard back from anyone recently about this problem returning.

    If it's still a problem for anyone, please let me know, and I'd be happy to reopen this issue.

  19. Wauplin commented on Jan 15, 2025

    @Wauplin

    Hey there, maintainer of huggingface_hub here. Sorry for all the trouble this breaking change introduced. The best
    -and future proof- solution to fix this is to upgrade diffusers version to a more recent version (>=0.29.0).

    pip install "diffusers>=0.29.0"
    

    This fixed version dates back to June 2024. The issue with pinning huggingface_hub to an old version is that it might conflict with future versions of diffusers/transformers.

    Hope this will prove useful 🙏

  20. cmdr2 commented on Jan 15, 2025

    @cmdr2
    Collaborator

    Hey @Wauplin Thanks for your reply, much appreciated! We will upgrade to a newer version of diffusers soon.

  21. DCharles01 commented on Jan 19, 2025

    @DCharles01

    Likewise, downgrading to 0.25.0 seems to work, so it must be something with 0.26.

    This worked for me

  22. added a commit that references this issue on Jan 22, 2025
  23. ShraddhaPai2001 commented on Jan 24, 2025

    @ShraddhaPai2001

    Hey there, maintainer of huggingface_hub here. Sorry for all the trouble this breaking change introduced. The best -and future proof- solution to fix this is to upgrade diffusers version to a more recent version (>=0.29.0).

    pip install "diffusers>=0.29.0"
    

    This fixed version dates back to June 2024. The issue with pinning huggingface_hub to an old version is that it might conflict with future versions of diffusers/transformers.

    Hope this will prove useful 🙏

    Still facing the same issue, even after installing the above mentioned version of diffusers

  24. emosGambler commented on Jan 28, 2025

    @emosGambler

    For anyone lost here coming from ComfyUI, downgrade the huggingface_hub:
    pip install huggingface_hub==0.20.2

  25. sdml0 commented on Feb 7, 2025

    @sdml0

    "pip install --upgrade diffusers" solved everything.

  26. shahzain110 commented on Feb 10, 2025

    @shahzain110

    I removed cached_download from the import line in the file /easy-diffusion/installer_files/env/lib/python3.8/site-packages/diffusers/utils/dynamic_modules_utils.py That fixed it for me

  27. 1036831050 commented on Mar 20, 2025

    @1036831050

    "pip install --upgrade diffusers" solved everything.

    太棒了,确实解决了

  28. abhijit-innovxcare commented on Aug 7, 2025

    @abhijit-innovxcare

    Use a monkey patch for cached_download function that was removed in newer versions of huggingface_hub.

    `
    """
    Patch for huggingface_hub compatibility with diffusers 0.28.0
    This fixes the ImportError: cannot import name 'cached_download' from 'huggingface_hub'
    """

    import sys
    from typing import Optional, Union
    from pathlib import Path

    Monkey patch for cached_download function that was removed in newer versions of huggingface_hub

    def cached_download(
    url_or_filename: Union[str, Path],
    cache_dir: Optional[Union[str, Path]] = None,
    force_download: bool = False,
    proxies: Optional[dict] = None,
    resume_download: bool = False,
    user_agent: Optional[Union[str, dict]] = None,
    use_auth_token: Optional[Union[bool, str]] = None,
    local_files_only: bool = False,
    legacy_cache_layout: bool = False,
    ) -> str:
    """
    Legacy function that was removed from huggingface_hub.
    This is a compatibility wrapper that uses hf_hub_download instead.
    """
    from huggingface_hub import hf_hub_download

    # If it's a URL, we can't use hf_hub_download, so we'll use requests
    if str(url_or_filename).startswith(('http://', 'https://')):
        import requests
        import tempfile
        import os
        
        response = requests.get(url_or_filename, stream=True)
        response.raise_for_status()
        
        # Create a temporary file
        if cache_dir is None:
            cache_dir = os.path.expanduser("~/.cache/huggingface/hub")
        
        os.makedirs(cache_dir, exist_ok=True)
        filename = os.path.basename(url_or_filename)
        cache_path = os.path.join(cache_dir, filename)
        
        if not force_download and os.path.exists(cache_path):
            return cache_path
        
        with open(cache_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        
        return cache_path
    else:
        # For local files, just return the path
        return str(url_or_filename)
    

    Apply the monkey patch

    def apply_patch():
    """Apply the monkey patch to huggingface_hub"""
    try:
    import huggingface_hub
    if not hasattr(huggingface_hub, 'cached_download'):
    huggingface_hub.cached_download = cached_download
    print("Applied huggingface_hub patch for cached_download")
    except ImportError:
    # If huggingface_hub hasn't been imported yet, we'll patch it when it's imported
    import builtins
    original_import = builtins.import

        def patched_import(name, *args, **kwargs):
            module = original_import(name, *args, **kwargs)
            if name == 'huggingface_hub' and not hasattr(module, 'cached_download'):
                module.cached_download = cached_download
                print("Applied huggingface_hub patch for cached_download")
            return module
        
        builtins.__import__ = patched_import
    

    Apply the patch immediately when this module is imported

    apply_patch()
    `

    This is very straight forward without messing up with the version of diffusers.

  29. Jaykumaran commented on Apr 17, 2026

    @Jaykumaran

    Downgrade huggingface_hub to 0.24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions