question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Network connection error prevent use of a cached download

See original GitHub issue

When a network connection is not available an exception is rasied inside cached_download():

https://github.com/huggingface/huggingface_hub/blob/af1d49e9eed3b31be86652cfcfdae9bfba4f3814/src/huggingface_hub/file_download.py#L639

Surely it should check for a previously cached download and return that, isn’t that the whole point of the cached_download function?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Wauplincommented, Oct 14, 2022

@howff HF_HUB_OFFLINE=1 is indeed the way to go for your use case (thanks @LysandreJik to point this 🙏 )

Here is a small test script:

# download.py
from huggingface_hub import cached_download, hf_hub_download

print("With `cached_download` (deprecated)")
print(cached_download("https://huggingface.co/gpt2/blob/main/config.json"))

print("\nWith `hf_hub_download` (preferred)")
print(hf_hub_download(repo_id="gpt2", filename="config.json"))

And here is the result:

# Run once to cache the files
 ➜ python download.py
With `cached_download` (deprecated)
/home/wauplin/projects/huggingface_hub/src/huggingface_hub/file_download.py:588: FutureWarning: `cached_download` is the legacy way to download files from the HF hub, please consider upgrading to `hf_hub_download`
  warnings.warn(
/home/wauplin/.cache/huggingface/hub/32ced3a9285c2335a2cebda8f31de1554afda9139b7aca822498b4cfd2de5921.dd2196627193cbe5003d6f5943d141946baa2e01534cd8533176541bc777da45

With `hf_hub_download` (preferred)
/home/wauplin/.cache/huggingface/hub/models--gpt2/snapshots/909a290700bd99135e67c64eefc166960b67cfd2/config.json
 
 # Run a second time in offline mode (to run where your internet access is limited)
 ➜ HF_HUB_OFFLINE=1 python download.py 
With `cached_download` (deprecated)
/home/wauplin/projects/huggingface_hub/src/huggingface_hub/file_download.py:588: FutureWarning: `cached_download` is the legacy way to download files from the HF hub, please consider upgrading to `hf_hub_download`
  warnings.warn(
/home/wauplin/.cache/huggingface/hub/32ced3a9285c2335a2cebda8f31de1554afda9139b7aca822498b4cfd2de5921.dd2196627193cbe5003d6f5943d141946baa2e01534cd8533176541bc777da45

With `hf_hub_download` (preferred)
/home/wauplin/.cache/huggingface/hub/models--gpt2/snapshots/909a290700bd99135e67c64eefc166960b67cfd2/config.json

Does that solve your problem ? 😃

0reactions
Wauplincommented, Oct 26, 2022

I am closing this issue as the problem is clearly identified and is caused on purpose as highlighted in https://github.com/huggingface/huggingface_hub/issues/1099#issuecomment-1283589478.

Read more comments on GitHub >

github_iconTop Results From Across the Web

6 Ways to Fix the “Download Failed Network Error” on Chrome
6 Ways to Fix the “Download Failed Network Error” on Chrome · 1. Check Your Internet Speed and Connection · 2. Modify Your...
Read more >
8 Ways to Fix SSL Connection Errors on Various Browsers ...
Open the Chrome browser and access its Settings menu. · Go to Privacy and security. · Tap on Clear browsing data. · Select...
Read more >
How to Fix the ERR_CONNECTION_RESET Error in 7 Ways
6. Disable Proxy Server Access · Navigate to System Preferences -> Network. · Select your active internet connection. · Open the Advanced settings...
Read more >
connection issue · Issue #8690 · huggingface/transformers
"Connection error, and we cannot find the requested files in the cached path. ... Network connection error prevent use of a cached download...
Read more >
Troubleshoot Connected Cache - Configuration Manager
First, verify the registry properties are configured correctly: HKLM\SOFTWARE\Microsoft\Delivery Optimization In-Network Cache . For example, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found