ComfyUI | Universal Huggingface Model Download Solution

Users of ComfyUI know that it is necessary to frequently download various large models from Huggingface, and during the download, three major problems need to be solved:
1. Network issues; domestic users cannot directly access and download large models.
2. Large file download issues; due to unstable networks or unstable proxies, downloads of large files often experience interruptions, requiring a re-download.
3. Multiple file download issues; we need to manually click to download one by one, making the download process overly tedious and mechanical.
How can we solve the above three problems? Today, I will share a tool that I often use, which can download large models from Huggingface very stably!
Download the script file and install the tool dependencies
We open the GitHub link:

https://github.com/LetheSec/HuggingFace-Download-Accelerator

ComfyUI | Universal Huggingface Model Download Solution

We need to download this script file to our local machine. As shown in the figure below:

ComfyUI | Universal Huggingface Model Download Solution
Then we execute the command in the current directory: python hf_download.py, as shown in the figure below:
ComfyUI | Universal Huggingface Model Download Solution

After execution, it will automatically download and install the dependencies required by this tool. I have already installed them, so it finished quickly.

Using the download tool

For example, I need to download the model required by the BiRefNet plugin, as shown in the figure below:

ComfyUI | Universal Huggingface Model Download Solution

Then we can execute the command: python hf_download.py --model=ViperYX/BiRefNet

The default download path is: C:\Users\Administrator\.cache\huggingface\hub\models--ViperYX--BiRefNet

For friends using ComfyUI, we need to download the model files into the comfyui/models folder, so we need to specify the download path.

ComfyUI | Universal Huggingface Model Download Solution

We place the hf_download.py script file in the models folder, then open cmd in the current directory:

ComfyUI | Universal Huggingface Model Download Solution

Then execute: python hf_download.py --model=ViperYX/BiRefNet --save_dir ./

Where ./ means the current directory, which is to download the files to the current directory, and the current directory is comfyui/models.

ComfyUI | Universal Huggingface Model Download Solution

You can see that the file has started downloading!

ComfyUI | Universal Huggingface Model Download Solution

You can see that the file has been downloaded to the models folder.

Solving download access restriction issues

Let’s take the download of black-forest-labs/FLUX.1-dev as an example:

python hf_download.py --model=black-forest-labs/FLUX.1-dev --save_dir ./

After execution, you will find an error: Access to model black-forest-labs/FLUX.1-dev is restricted. You must have access to it and be authenticated to access it. Please log in.

This means that authorization is required to download. By adding the –token parameter after the command, this can be resolved. Where does the token come from?

ComfyUI | Universal Huggingface Model Download Solution
ComfyUI | Universal Huggingface Model Download Solution
ComfyUI | Universal Huggingface Model Download Solution

Enter the name and check the permissions, then click the bottom Create token, and a pop-up box will appear as shown:

ComfyUI | Universal Huggingface Model Download Solution

We copy this token, and then paste it after –token to download:

python hf_download.py --model=black-forest-labs/FLUX.1-dev --save_dir ./ --token=hf_tSLgRjelwSoQPJJIJtmJKFWDQLdYqZKbe0

Leave a Comment