Skip to content

Commit

Permalink
Don't write the ref file unless necessary (#2657)
Browse files Browse the repository at this point in the history
* Don't write the ref file unless necessary

* Add exception handling when dealing with ref file

* Update src/huggingface_hub/_snapshot_download.py

Co-authored-by: Lucain <[email protected]>

* Update src/huggingface_hub/_snapshot_download.py

---------

Co-authored-by: Lucain <[email protected]>
Co-authored-by: Lucain <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent 9e7ff04 commit d30853b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/huggingface_hub/_snapshot_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,12 @@ def snapshot_download(
# In that case store a ref.
if revision != commit_hash:
ref_path = os.path.join(storage_folder, "refs", revision)
os.makedirs(os.path.dirname(ref_path), exist_ok=True)
with open(ref_path, "w") as f:
f.write(commit_hash)
try:
os.makedirs(os.path.dirname(ref_path), exist_ok=True)
with open(ref_path, "w") as f:
f.write(commit_hash)
except OSError as e:
logger.warning(f"Ignored error while writing commit hash to {ref_path}: {e}.")

# we pass the commit_hash to hf_hub_download
# so no network call happens if we already
Expand Down

0 comments on commit d30853b

Please sign in to comment.