Skip to content

Commit

Permalink
setup flags for download script
Browse files Browse the repository at this point in the history
  • Loading branch information
strangiato committed Nov 5, 2024
1 parent 493ee65 commit 97b2dc9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
4 changes: 2 additions & 2 deletions granite-3.0-2b-instruct/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ FROM quay.io/redhat-ai-services/huggingface-modelcar-builder:latest as base
# The model repo to download
ENV MODEL_REPO="ibm-granite/granite-3.0-2b-instruct"

# Download the necessary model files (config.json, tokenizer.json, and safetensors)
RUN python3 download_model.py
# Download the necessary model files
RUN python3 download_model.py --model-repo ${MODEL_REPO}

# Final image containing only the essential model files
FROM registry.access.redhat.com/ubi9/ubi-micro:9.4
Expand Down
4 changes: 2 additions & 2 deletions granite-3.0-8b-instruct/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ FROM quay.io/redhat-ai-services/huggingface-modelcar-builder:latest as base
# The model repo to download
ENV MODEL_REPO="ibm-granite/granite-3.0-8b-instruct"

# Download the necessary model files (config.json, tokenizer.json, and safetensors)
RUN python3 download_model.py
# Download the necessary model files
RUN python3 download_model.py --model-repo ${MODEL_REPO}

# Final image containing only the essential model files
FROM registry.access.redhat.com/ubi9/ubi-micro:9.4
Expand Down
16 changes: 16 additions & 0 deletions huggingface-modelcar-builder/README.md
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
```
49 changes: 42 additions & 7 deletions huggingface-modelcar-builder/download_model.py
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,
)
2 changes: 1 addition & 1 deletion huggingface-modelcar-builder/pyproject.toml
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"
1 change: 1 addition & 0 deletions huggingface-modelcar-builder/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
argparse
huggingface-hub
3 changes: 2 additions & 1 deletion mistral-7b-instruct-v0.3/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ ARG HF_TOKEN
ENV MODEL_REPO="mistralai/Mistral-7B-Instruct-v0.3"

# Download the necessary model files (config.json, tokenizer.json, and safetensors)
RUN python3 download_model.py
RUN python3 download_model.py --model-repo ${MODEL_REPO} \
--allow-patterns "params.json" "consolidated.safetensors" "tokenizer.model.v3"

# Final image containing only the essential model files
FROM registry.access.redhat.com/ubi9/ubi-micro:9.4
Expand Down

0 comments on commit 97b2dc9

Please sign in to comment.