feat: add HuggingFace mirror support for VM providers (#278)

Add support for HuggingFace mirror (hf-mirror.com) to improve download
speeds in regions where huggingface.co access is slow.

- Support HF_ENDPOINT environment variable detection
- Automatically switch to hf-mirror.com when HF_ENDPOINT is set
- Apply to Docker, VMware, and VirtualBox providers
- Maintain backward compatibility with default huggingface.co URLs

Users can now set HF_ENDPOINT=https://hf-mirror.com to use the mirror.
This commit is contained in:
张逸群
2025-07-23 03:40:35 +08:00
committed by GitHub
parent 0a37cccd53
commit 4a5d48000f
3 changed files with 26 additions and 0 deletions

View File

@@ -57,6 +57,12 @@ def _install_vm(vm_name, vms_dir, downloaded_file_name, original_vm_name="Ubuntu
else:
raise Exception("Unsupported platform or architecture.")
# Check for HF_ENDPOINT environment variable and replace domain if set to hf-mirror.com
hf_endpoint = os.environ.get('HF_ENDPOINT')
if hf_endpoint and 'hf-mirror.com' in hf_endpoint:
url = url.replace('huggingface.co', 'hf-mirror.com')
logger.info(f"Using HF mirror: {url}")
# Download the virtual machine image
logger.info("Downloading the virtual machine image...")
downloaded_size = 0