-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allow hf:// paths and add hf-transfer for faster hf downloads
- Loading branch information
Showing
6 changed files
with
117 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
import huggingface_hub | ||
|
||
ALLOW_PATTERNS = ["*.safetensors", "*.json", "*.txt"] | ||
|
||
|
||
def is_hf_model(model_id: str) -> bool: | ||
return model_id.startswith("hf://") | ||
|
||
|
||
def get_hf_model_id(model_id: str) -> str: | ||
if is_hf_model(model_id): | ||
return model_id.split("hf://")[1] | ||
return model_id | ||
|
||
|
||
def download_hf_model(model_id: str, use_hf_transfer: bool = False) -> str: | ||
""" | ||
Download the model from HF Hub. | ||
The model_id can be of format "hf://<repo_id>" to disambiguate from a local path, but <repo_id> is also accepted. | ||
""" | ||
model_id = get_hf_model_id(model_id) | ||
|
||
if use_hf_transfer: | ||
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1" | ||
|
||
return huggingface_hub.snapshot_download( | ||
repo_id=model_id, allow_patterns=ALLOW_PATTERNS | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters