Registry / llm-agents / hf-transfer

hf-transfer

JSON →
library0.1.9pypypi✓ verified 23d ago

hf-transfer is a utility library designed to significantly speed up file transfers to and from the Hugging Face Hub. It works by optimizing the underlying transfer mechanisms used by the `huggingface_hub` library. The current version is 0.1.9, and it generally follows the release cadence of the broader Hugging Face ecosystem, with updates often tied to improvements in hub interaction.

pip install hf-transfer
INSTALL
IMPORT
SIG · HF-TRANSFER
H
hf-transfer
llm-agentspythonv0.1.9
Install
1.7s avg
Import
Disk
25MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 27.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.000s · 28MB
25MB installed
● package 25MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

hf_transfer
import hf_transfer
import hf-transfer
download
from hf_transfer import download
multipart_upload
from hf_transfer import multipart_upload

This quickstart demonstrates how to enable `hf_transfer` within your Python script and then use `huggingface_hub`'s `snapshot_download` function. `hf_transfer` will automatically accelerate the download operation once `hf_transfer.enable_transfer()` is called. Remember that `huggingface_hub` must also be installed for this to work.

import hf_transfer from huggingface_hub import snapshot_download import os # Enable hf_transfer to accelerate subsequent Hugging Face Hub operations hf_transfer.enable_transfer() # Example: Download a small model from the Hugging Face Hub # This operation will now be accelerated by hf_transfer repo_id = "HuggingFaceH4/no_deid_test_data" local_dir = "./no_deid_test_data_hf_transfer" print(f"Downloading {repo_id} to {local_dir} with hf_transfer acceleration...") try: snapshot_download(repo_id=repo_id, local_dir=local_dir) print(f"Successfully downloaded {repo_id} to {local_dir}") except Exception as e: print(f"An error occurred during download: {e}") finally: # Clean up downloaded files for subsequent runs if desired # import shutil # if os.path.exists(local_dir): # shutil.rmtree(local_dir) pass
Debug
Known issues
breakingThe environment variable for enabling hf-transfer changed from `HF_HUB_ENABLE_HF_TRANSFER` to `HF_TRANSFER_ENABLED`.
fix
Use `HF_TRANSFER_ENABLED=1` or `hf_transfer.enable_transfer()` in code. For older versions of `huggingface_hub` that might check the old variable, ensure compatibility or update `huggingface_hub`.
affects: <=0.1.3 (old env var), >=0.1.4 (new env var)
gotchahf-transfer must be enabled *before* any `huggingface_hub` operations are called for acceleration to take effect.
fix
Call `hf_transfer.enable_transfer()` at the very beginning of your script, or set the `HF_TRANSFER_ENABLED=1` environment variable before running your Python script.
affects: All versions
gotchahf-transfer does not provide standalone download/upload functionality; it acts as an accelerator for the `huggingface_hub` library. Therefore, `huggingface_hub` is a required dependency.
fix
Ensure `huggingface_hub` is installed (`pip install huggingface_hub`) alongside `hf-transfer`.
affects: All versions
gotchaPerformance benefits of hf-transfer are most noticeable for large files or many small files, and can be influenced by network conditions and local storage speed. It may not provide significant speedups for very small transfers.
fix
Evaluate performance in your specific use case. If you experience issues, consider checking network configuration, firewall settings, and disk I/O performance.
affects: All versions
Upgrade
Version history
0.1.9latest on PyPI · released Jan 7, 2025
Audit
Dependencies
huggingface_hubrequiredhf-transfer accelerates operations within huggingface_hub; it does not provide standalone transfer functionality.
Agent activity
39 hits · last 30 days
node
34
Perplexity
1
OpenAI (training)
1
Resources
hf-transfer — pip install hf-transfer · libregistry