-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated chat bot example to support llama3
- Loading branch information
Showing
8 changed files
with
112 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import argparse | ||
import os | ||
|
||
from huggingface_hub import HfApi, snapshot_download | ||
|
||
|
||
def dir_path(path_str): | ||
if os.path.isdir(path_str): | ||
return path_str | ||
elif input(f"{path_str} does not exist, create directory? [y/n]").lower() == "y": | ||
os.makedirs(path_str) | ||
return path_str | ||
else: | ||
raise NotADirectoryError(path_str) | ||
|
||
|
||
class HFModelNotFoundError(Exception): | ||
def __init__(self, model_str): | ||
super().__init__(f"HuggingFace model not found: '{model_str}'") | ||
|
||
|
||
def hf_model(model_str): | ||
api = HfApi() | ||
models = [m.modelId for m in api.list_models()] | ||
if model_str in models: | ||
return model_str | ||
else: | ||
raise HFModelNotFoundError(model_str) | ||
|
||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--model_path", | ||
"-o", | ||
type=dir_path, | ||
default="model", | ||
help="Output directory for downloaded model files", | ||
) | ||
parser.add_argument( | ||
"--model_name", "-m", type=hf_model, required=True, help="HuggingFace model name" | ||
) | ||
parser.add_argument("--revision", "-r", type=str, default="main", help="Revision") | ||
args = parser.parse_args() | ||
|
||
snapshot_path = snapshot_download( | ||
repo_id=args.model_name, | ||
revision=args.revision, | ||
cache_dir=args.model_path, | ||
use_auth_token=True, | ||
ignore_patterns=["original/*", "pytorch_model*.bin"] | ||
) | ||
print(f"Files for '{args.model_name}' is downloaded to '{snapshot_path}'") |
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
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