-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from redhat-ai-services/download-flags
setup flags for download script
- Loading branch information
Showing
7 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
# Huggingface-modelcar-builder | ||
|
||
[![GitHub](https://img.shields.io/badge/GitHub-repo-blue.svg)](https://github.com/redhat-ai-services/modelcar-catalog/tree/main/huggingface-modelcar-builder) [![Quay.io](https://img.shields.io/badge/Quay.io-image-blue.svg)](https://quay.io/repository/redhat-ai-services/huggingface-modelcar-builder) | ||
|
||
## download_model | ||
|
||
``` | ||
python download_model.py -h | ||
usage: download_model.py [-h] [-m MODEL_REPO] [-t TARGET_DIR] [-a ALLOW_PATTERNS [ALLOW_PATTERNS ...]] | ||
options: | ||
-h, --help show this help message and exit | ||
-m MODEL_REPO, --model-repo MODEL_REPO | ||
The model repo on huggingface | ||
-t TARGET_DIR, --target-dir TARGET_DIR | ||
The target directory to download the model | ||
-a ALLOW_PATTERNS [ALLOW_PATTERNS ...], --allow-patterns ALLOW_PATTERNS [ALLOW_PATTERNS ...] | ||
The allowed patterns to download | ||
``` |
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 |
---|---|---|
@@ -1,13 +1,48 @@ | ||
import os | ||
from typing import List | ||
|
||
import argparse | ||
|
||
from huggingface_hub import snapshot_download | ||
|
||
model_repo = os.getenv("MODEL_REPO") | ||
def main( | ||
model_repo: str, | ||
local_dir: str = "./models", | ||
allow_patterns: List[str] = ["*.safetensors", "*.json", "*.txt"], | ||
): | ||
print(f"Attempting to download the following model from huggingface: {model_repo}") | ||
print(f"Target director: {local_dir}") | ||
print(f"With allow-patterns: {allow_patterns}") | ||
|
||
snapshot_download( | ||
repo_id=model_repo, | ||
local_dir=local_dir, | ||
allow_patterns=allow_patterns, | ||
) | ||
|
||
print(f"Attempting to download the following model from huggingface: {model_repo}") | ||
|
||
snapshot_download( | ||
repo_id=model_repo, | ||
local_dir="/models", | ||
allow_patterns=["*.safetensors", "*.json", "*.txt"], | ||
) | ||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-m", "--model-repo", help="The model repo on huggingface", type=str | ||
) | ||
parser.add_argument( | ||
"-t", | ||
"--target-dir", | ||
help="The target directory to download the model", | ||
default="./models", | ||
type=str, | ||
) | ||
parser.add_argument( | ||
"-a", | ||
"--allow-patterns", | ||
help="The allowed patterns to download", | ||
nargs="+", | ||
default=["*.safetensors", "*.json", "*.txt"], | ||
) | ||
args = parser.parse_args() | ||
main( | ||
model_repo=args.model_repo, | ||
local_dir=args.target_dir, | ||
allow_patterns=args.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[project] | ||
name = "huggingface-modelcar-builder" | ||
description = "A container image to help build modelcar images" | ||
version = "0.1.0" | ||
version = "0.2.0" |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
argparse | ||
huggingface-hub |
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