You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cannot import name 'cached_download' from 'huggingface_hub' #1851
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
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)
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
Reacted by XDM-Inc, Kyle McDonald, ctallen95, Neil Innes, Hudson Ventura, Ruping Cao, Wei Tao, Chad Serrant, Antoine-Hugueney, LiKehan and 170 more
Reacted by Aaron Feng, Timflw, Kephone Gaon, 정소현, Yunwei Zhao, zhongli, Kevin Pruvost, Achyuth S.S, Jeong U-Tae, Juneleung and 16 more
Reacted by Rachad Lakis, Varsha Kesavan, Pulkit Verma, Timflw, Kephone Gaon, 정소현, Kevin Pruvost, Juneleung, Chu^2, Nahid Alam and 13 more
Reacted by boorboor, Sergey Zhdanov, Tazik Shahjahan, Timflw, Kephone Gaon, Alan Lee, 정소현, Kevin Pruvost, Yuxuan Wang, Juneleung and 15 more
Reacted by Raghuveer Awankar, Ricardo F., Yuda Qiu, ChaeSeoyoung, Prajwal Singh, Timflw, Raghavendra, Kephone Gaon, 정소현, chck and 22 more
Reacted by Jeonghan, Om Rastogi, Tazik Shahjahan, Dongping Chen, Rachad Lakis, Andrea Cicero, Timflw, Kephone Gaon, 정소현, zhongli and 22 more
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
Reacted by a96123155, zdke and Wei-Hsin Yeh
Reacted by Rodrigo Fernandez Testa, YYYYYHC, santis_yang, Jay Hu, MANMEET SINGH and Z_L
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
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
Reacted by Bassam, Nobel Dang, W1Real and Owolabi Daniel Gbenga
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.
Describe the bug cannot import name 'cached_download' from 'huggingface_hub'
To Reproduce Steps to reproduce the behavior:
Go to '...'
Click on '....'
Scroll down to '....'
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.
Reacted by zybeich, Jeongmin Moon, markandrewc, Qian Wu and Dejia Xu
@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!
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.
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
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
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.
Activity
vertikalm commentedon Oct 19, 2024
Same error with a fresh and clean Debian 12
XDM-Inc commentedon Oct 20, 2024
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
orossant commentedon Oct 20, 2024
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)
SrushtiPednekar commentedon Oct 20, 2024
same issue here
xezwary commentedon Oct 20, 2024
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.pyThat fixed it for me
XDM-Inc commentedon Oct 20, 2024
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
hudsonventura commentedon Oct 22, 2024
@xezwary, you tip works to me. Thanks.
QueryType commentedon Oct 24, 2024
Same here. I applied the workaround and got an astronaut on a horse
guangchen811 commentedon Oct 25, 2024
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
Bassaoud commentedon Oct 27, 2024
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_downloadinstead.thakral-kartik commentedon Oct 27, 2024
Downgrading from 0.26.1 to 0.20.2 worked for me.
lauraaisling commentedon Oct 28, 2024
Likewise, downgrading to 0.25.0 seems to work, so it must be something with 0.26.
Bassaoud commentedon Oct 28, 2024
SOLUTION : Replace cached_download by hf_hub_download in your model.py.
VioletaChatalbasheva commentedon Oct 28, 2024
You could also update diffusers to the latest version which seems to be working without
cached_download14 remaining items
cmdr2 commentedon Dec 11, 2024
@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!
cmdr2 commentedon Dec 17, 2024
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.
Wauplin commentedon Jan 15, 2025
Hey there, maintainer of
huggingface_hubhere. Sorry for all the trouble this breaking change introduced. The best-and future proof- solution to fix this is to upgrade
diffusersversion to a more recent version (>=0.29.0).This fixed version dates back to June 2024. The issue with pinning
huggingface_hubto an old version is that it might conflict with future versions of diffusers/transformers.Hope this will prove useful 🙏
cmdr2 commentedon Jan 15, 2025
Hey @Wauplin Thanks for your reply, much appreciated! We will upgrade to a newer version of diffusers soon.
DCharles01 commentedon Jan 19, 2025
This worked for me
Fix huggingface hub issue
ShraddhaPai2001 commentedon Jan 24, 2025
Still facing the same issue, even after installing the above mentioned version of diffusers
emosGambler commentedon Jan 28, 2025
For anyone lost here coming from ComfyUI, downgrade the huggingface_hub:
pip install huggingface_hub==0.20.2sdml0 commentedon Feb 7, 2025
"pip install --upgrade diffusers" solved everything.
shahzain110 commentedon Feb 10, 2025
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
1036831050 commentedon Mar 20, 2025
太棒了,确实解决了
abhijit-innovxcare commentedon Aug 7, 2025
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
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
Apply the patch immediately when this module is imported
apply_patch()
`
This is very straight forward without messing up with the version of diffusers.
Jaykumaran commentedon Apr 17, 2026
Downgrade huggingface_hub to 0.24