HuggingFace China Download Guide | Generated by AI

Home 2026.05

Two env vars do all the work:

Variable What it does
HF_ENDPOINT=https://hf-mirror.com Route all HF Hub traffic through the China mirror. No proxy needed, doesn’t touch your DMIT VPS.
HF_HUB_ENABLE_HF_TRANSFER=1 Use the Rust hf_transfer client for parallel multi-chunk downloads (5–10× faster). Requires pip install hf_transfer.

One-off command

HF_ENDPOINT=https://hf-mirror.com HF_HUB_ENABLE_HF_TRANSFER=1 \
  python3.11 sample.py --init_from=gpt2-medium --start="Hello" --num_samples=1

Add to ~/.bashrc so you never forget:

export HF_ENDPOINT=https://hf-mirror.com
export HF_HUB_ENABLE_HF_TRANSFER=1

Then source ~/.bashrc. Every Python script that uses transformers / datasets / huggingface_hub will pick it up automatically.

Pre-download (avoid downloading mid-training)

huggingface-cli download gpt2-medium                              # model
huggingface-cli download HuggingFaceFW/fineweb --repo-type=dataset --include="sample/10BT/*"  # dataset

Files land in ~/.cache/huggingface/hub/ and are reused by every subsequent from_pretrained() call.

What it applies to

Gotchas

Verify it’s working

HF_ENDPOINT=https://hf-mirror.com huggingface-cli download gpt2 --quiet
echo $?   # 0 = success

Or watch the URL in the progress bar — should say hf-mirror.com, not huggingface.co.


Back Donate