Skip to content

Commit 18e8d80

Browse files
feat: Update model DL script with new 'hf' Hugging Face CLI (#837)
* feat: Update model dl script with new hf Hugging Face CLI * fix duplicate 'login login' * rename HuggingFace -> Hugging Face * Updated hf download args to comply with new behaviour * Apply suggestion from @victorges Co-authored-by: Victor Elias <[email protected]> * Replace deprecated Hugging Face HF_HUB_ENABLE_HF_TRANSFER env var * Update development-guide.md * Update modal_app.py Replace deprecated HF_HUB_ENABLE_HF_TRANSFER -> HX_XET_HIGH_PERFORMANCE env var * Update ai-runner-models.yaml * Update ai-runner-models.yaml --------- Co-authored-by: Victor Elias <[email protected]>
1 parent e28f1ab commit 18e8d80

File tree

4 files changed

+41
-42
lines changed

4 files changed

+41
-42
lines changed

.github/workflows/ai-runner-models.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
MIN_MODELS_SIZE_MB: 500
3939
run: |
4040
set -e
41-
pip install 'huggingface_hub[cli,hf_transfer]' hf_transfer
41+
pip install huggingface_hub
4242
runner/dl_checkpoints.sh --batch
4343
du -hs ./models/
4444
@@ -114,7 +114,7 @@ jobs:
114114
MIN_MODELS_SIZE_MB: 500
115115
run: |
116116
set -e
117-
pip install 'huggingface_hub[cli,hf_transfer]' hf_transfer
117+
pip install huggingface_hub
118118
rm -rf ./models/*
119119
runner/dl_checkpoints.sh --tensorrt
120120
du -hs ./models/

docs/development-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The AI Runner container's runner app uses [HuggingFace](https://huggingface.co/)
2727
1. **Install Hugging Face CLI**: Install the Hugging Face CLI by running the following command:
2828

2929
```bash
30-
pip install huggingface_hub[cli,hf_transfer]
30+
pip install huggingface_hub
3131
```
3232

3333
2. **Set up Hugging Face Access Token**: Generate a Hugging Face access token as per the [official guide](https://huggingface.co/docs/hub/en/security-tokens) and assign it to the `HG_TOKEN` environment variable. This token enables downloading of [private models](https://huggingface.co/docs/transformers.js/en/guides/private) from the Hugging Face model hub. Alternatively, use the Hugging Face CLI's [login command](https://huggingface.co/docs/huggingface_hub/en/guides/cli#huggingface-cli-login) to install the token.

runner/dl_checkpoints.sh

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ select_gpu() {
8282
done
8383
}
8484

85-
# Checks HF_TOKEN and huggingface-cli login status and throw warning if not authenticated.
85+
# Check HF_TOKEN and Hugging Face CLI login status, throw warning if not authenticated.
8686
check_hf_auth() {
87-
if [ -z "$HF_TOKEN" ] && [ "$(huggingface-cli whoami)" = "Not logged in" ]; then
88-
printf "WARN: Not logged in and HF_TOKEN not set. Log in with 'huggingface-cli login' or set HF_TOKEN to download token-gated models.\n"
87+
if [ -z "$HF_TOKEN" ] && [ "$(hf auth whoami)" = "Not logged in" ]; then
88+
printf "WARN: Not logged in and HF_TOKEN not set. Log in with 'hf auth login' or set HF_TOKEN to download token-gated models.\n"
8989
exit 1
9090
fi
9191
}
@@ -118,27 +118,27 @@ function download_beta_models() {
118118
printf "\nDownloading unrestricted models...\n"
119119

120120
# Download text-to-image and image-to-image models.
121-
huggingface-cli download SG161222/RealVisXL_V4.0_Lightning --include "*.fp16.safetensors" "*.json" "*.txt" --exclude ".onnx" ".onnx_data" --cache-dir models
122-
huggingface-cli download ByteDance/SDXL-Lightning --include "*unet.safetensors" --cache-dir models
123-
huggingface-cli download timbrooks/instruct-pix2pix --include "*.fp16.safetensors" "*.json" "*.txt" --cache-dir models
121+
hf download SG161222/RealVisXL_V4.0_Lightning --include "*.fp16.safetensors" --include "*.json" --include "*.txt" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models
122+
hf download ByteDance/SDXL-Lightning --include "*unet.safetensors" --cache-dir models
123+
hf download timbrooks/instruct-pix2pix --include "*.fp16.safetensors" --include "*.json" --include "*.txt" --cache-dir models
124124

125125
# Download upscale models
126-
huggingface-cli download stabilityai/stable-diffusion-x4-upscaler --include "*.fp16.safetensors" --cache-dir models
126+
hf download stabilityai/stable-diffusion-x4-upscaler --include "*.fp16.safetensors" --cache-dir models
127127

128128
# Download audio-to-text models.
129-
huggingface-cli download openai/whisper-large-v3 --include "*.safetensors" "*.json" --cache-dir models
130-
huggingface-cli download distil-whisper/distil-large-v3 --include "*.safetensors" "*.json" --cache-dir models
131-
huggingface-cli download openai/whisper-medium --include "*.safetensors" "*.json" --cache-dir models
129+
hf download openai/whisper-large-v3 --include "*.safetensors" --include "*.json" --cache-dir models
130+
hf download distil-whisper/distil-large-v3 --include "*.safetensors" --include "*.json" --cache-dir models
131+
hf download openai/whisper-medium --include "*.safetensors" --include "*.json" --cache-dir models
132132

133133
# Download custom pipeline models.
134-
huggingface-cli download facebook/sam2-hiera-large --include "*.pt" "*.yaml" --cache-dir models
135-
huggingface-cli download parler-tts/parler-tts-large-v1 --include "*.safetensors" "*.json" "*.model" --cache-dir models
134+
hf download facebook/sam2-hiera-large --include "*.pt" --include "*.yaml" --cache-dir models
135+
hf download parler-tts/parler-tts-large-v1 --include "*.safetensors" --include "*.json" --include "*.model" --cache-dir models
136136

137137
printf "\nDownloading token-gated models...\n"
138138

139139
# Download image-to-video models (token-gated).
140140
check_hf_auth
141-
huggingface-cli download stabilityai/stable-video-diffusion-img2vid-xt-1-1 --include "*.fp16.safetensors" "*.json" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
141+
hf download stabilityai/stable-video-diffusion-img2vid-xt-1-1 --include "*.fp16.safetensors" --include "*.json" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
142142
}
143143

144144
# Download all models.
@@ -149,26 +149,26 @@ function download_all_models() {
149149

150150
# Download text-to-image and image-to-image models.
151151
printf "\nDownloading unrestricted models...\n"
152-
huggingface-cli download stabilityai/sd-turbo --include "*.fp16.safetensors" "*.json" "*.txt" --exclude ".onnx" ".onnx_data" --cache-dir models
153-
huggingface-cli download stabilityai/sdxl-turbo --include "*.fp16.safetensors" "*.json" "*.txt" --exclude ".onnx" ".onnx_data" --cache-dir models
154-
huggingface-cli download runwayml/stable-diffusion-v1-5 --include "*.fp16.safetensors" "*.json" "*.txt" --exclude ".onnx" ".onnx_data" --cache-dir models
155-
huggingface-cli download stabilityai/stable-diffusion-xl-base-1.0 --include "*.fp16.safetensors" "*.json" "*.txt" --exclude ".onnx" ".onnx_data" --cache-dir models
156-
huggingface-cli download prompthero/openjourney-v4 --include "*.safetensors" "*.json" "*.txt" --exclude ".onnx" ".onnx_data" --cache-dir models
157-
huggingface-cli download SG161222/RealVisXL_V4.0 --include "*.fp16.safetensors" "*.json" "*.txt" --exclude ".onnx" ".onnx_data" --cache-dir models
158-
huggingface-cli download stabilityai/stable-diffusion-3-medium-diffusers --include "*.fp16*.safetensors" "*.model" "*.json" "*.txt" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
159-
huggingface-cli download stabilityai/stable-diffusion-3.5-medium --include "transformer/*.safetensors" "*model.fp16*" "*.model" "*.json" "*.txt" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
160-
huggingface-cli download stabilityai/stable-diffusion-3.5-large --include "transformer/*.safetensors" "*model.fp16*" "*.model" "*.json" "*.txt" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
161-
huggingface-cli download SG161222/Realistic_Vision_V6.0_B1_noVAE --include "*.fp16.safetensors" "*.json" "*.txt" "*.bin" --exclude ".onnx" ".onnx_data" --cache-dir models
162-
huggingface-cli download black-forest-labs/FLUX.1-schnell --include "*.safetensors" "*.json" "*.txt" "*.model" --exclude ".onnx" ".onnx_data" --cache-dir models
152+
hf download stabilityai/sd-turbo --include "*.fp16.safetensors" --include "*.json" --include "*.txt" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models
153+
hf download stabilityai/sdxl-turbo --include "*.fp16.safetensors" --include "*.json" --include "*.txt" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models
154+
hf download runwayml/stable-diffusion-v1-5 --include "*.fp16.safetensors" --include "*.json" --include "*.txt" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models
155+
hf download stabilityai/stable-diffusion-xl-base-1.0 --include "*.fp16.safetensors" --include "*.json" --include "*.txt" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models
156+
hf download prompthero/openjourney-v4 --include "*.safetensors" --include "*.json" --include "*.txt" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models
157+
hf download SG161222/RealVisXL_V4.0 --include "*.fp16.safetensors" --include "*.json" --include "*.txt" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models
158+
hf download stabilityai/stable-diffusion-3-medium-diffusers --include "*.fp16*.safetensors" --include "*.model" --include "*.json" --include "*.txt" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
159+
hf download stabilityai/stable-diffusion-3.5-medium --include "transformer/*.safetensors" --include "*model.fp16*" --include "*.model" --include "*.json" --include "*.txt" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
160+
hf download stabilityai/stable-diffusion-3.5-large --include "transformer/*.safetensors" --include "*model.fp16*" --include "*.model" --include "*.json" --include "*.txt" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
161+
hf download SG161222/Realistic_Vision_V6.0_B1_noVAE --include "*.fp16.safetensors" --include "*.json" --include "*.txt" --include "*.bin" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models
162+
hf download black-forest-labs/FLUX.1-schnell --include "*.safetensors" --include "*.json" --include "*.txt" --include "*.model" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models
163163

164164
# Download image-to-video models.
165-
huggingface-cli download stabilityai/stable-video-diffusion-img2vid-xt --include "*.fp16.safetensors" "*.json" --cache-dir models
165+
hf download stabilityai/stable-video-diffusion-img2vid-xt --include "*.fp16.safetensors" --include "*.json" --cache-dir models
166166

167167
# Download image-to-text models.
168-
huggingface-cli download Salesforce/blip-image-captioning-large --include "*.safetensors" "*.json" --cache-dir models
168+
hf download Salesforce/blip-image-captioning-large --include "*.safetensors" --include "*.json" --cache-dir models
169169

170170
# Custom pipeline models.
171-
huggingface-cli download facebook/sam2-hiera-large --include "*.pt" "*.yaml" --cache-dir models
171+
hf download facebook/sam2-hiera-large --include "*.pt" --include "*.yaml" --cache-dir models
172172

173173
download_live_models
174174
}
@@ -386,23 +386,23 @@ function download_restricted_models() {
386386
printf "\nDownloading restricted models...\n"
387387

388388
# Download text-to-image and image-to-image models.
389-
huggingface-cli download black-forest-labs/FLUX.1-dev --include "*.safetensors" "*.json" "*.txt" "*.model" --exclude ".onnx" ".onnx_data" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
389+
hf download black-forest-labs/FLUX.1-dev --include "*.safetensors" --include "*.json" --include "*.txt" --include "*.model" --exclude ".onnx" --exclude ".onnx_data" --cache-dir models ${TOKEN_FLAG:+"$TOKEN_FLAG"}
390390
# Download LLM models (Warning: large model size)
391-
huggingface-cli download meta-llama/Meta-Llama-3.1-8B-Instruct --include "*.json" "*.bin" "*.safetensors" "*.txt" --cache-dir models
391+
hf download meta-llama/Meta-Llama-3.1-8B-Instruct --include "*.json" --include "*.bin" --include "*.safetensors" --include "*.txt" --cache-dir models
392392

393393
}
394394

395395
function download_batch_models() {
396396
printf "\nDownloading Batch models...\n"
397397

398-
huggingface-cli download facebook/sam2-hiera-large --include "*.pt" "*.yaml" --cache-dir models
398+
hf download facebook/sam2-hiera-large --include "*.pt" --include "*.yaml" --cache-dir models
399399
}
400400

401-
# Enable HF transfer acceleration.
402-
# See: https://huggingface.co/docs/huggingface_hub/v0.22.1/package_reference/environment_variables#hfhubenablehftransfer.
403-
export HF_HUB_ENABLE_HF_TRANSFER=1
401+
# Enable XET High Performance.
402+
# See: https://huggingface.co/docs/huggingface_hub/main/en/package_reference/environment_variables#hfxethighperformance
403+
export HF_XET_HIGH_PERFORMANCE=1
404404

405-
# Use HF_TOKEN if set, otherwise use huggingface-cli's login.
405+
# Use HF_TOKEN if set, otherwise use Hugging Face CLI's login.
406406
[ -n "$HF_TOKEN" ] && TOKEN_FLAG="--token=${HF_TOKEN}" || TOKEN_FLAG=""
407407

408408
# Parse command-line arguments.
@@ -447,10 +447,9 @@ echo "Starting livepeer AI subnet model downloader..."
447447
echo "Creating 'models' directory in the current working directory..."
448448
mkdir -p models/checkpoints models/StreamDiffusion--engines models/insightface models/StreamDiffusion--models models/ComfyUI--{models,output}
449449

450-
# Ensure 'huggingface-cli' is installed.
451-
echo "Checking if 'huggingface-cli' is installed..."
452-
if ! command -v huggingface-cli >/dev/null 2>&1; then
453-
echo "WARN: The huggingface-cli is required to download models. Please install it using 'pip install huggingface_hub[cli,hf_transfer]'."
450+
echo "Checking if 'hf' Hugging Face CLI is installed..."
451+
if ! command -v hf >/dev/null 2>&1; then
452+
echo "ERROR: The Hugging Face CLI is required to download models. Please install it using 'pip install huggingface_hub'."
454453
exit 1
455454
fi
456455

runner/modal_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"huggingface_hub==0.20.2",
2323
"hf-transfer==0.1.4",
2424
)
25-
.env({"HF_HUB_ENABLE_HF_TRANSFER": "1", "HF_HUB_DISABLE_PROGRESS_BARS": "1"})
25+
.env({"HF_XET_HIGH_PERFORMANCE": "1", "HF_HUB_DISABLE_PROGRESS_BARS": "1"})
2626
)
2727
models_volume = Volume.persisted("models")
2828
models_path = Path("/models")

0 commit comments

Comments
 (0)