-
-
Notifications
You must be signed in to change notification settings - Fork 44
feat:update model loader #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,4 +31,5 @@ cache | |
| __pycache__ | ||
| *.pyc | ||
| .pytest_cache | ||
| *.tgz | ||
| *.tgz | ||
| .huggingface | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| MODEL_LOCAL_DIR = "/workspace/models/" | ||
kerthcet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| HUB_HUGGING_FACE = "Huggingface" | ||
| HUB_MODEL_SCOPE = "ModelScope" | ||
|
|
||
| ENV_HUB_MODEL_SOURCE_TYPE = "MODEL_SOURCE_TYPE" | ||
| ENV_HUB_MODEL_HUB_NAME = "MODEL_HUB_NAME" | ||
| ENV_HUB_REVISION = "REVISION" | ||
| ENV_HUB_MODEL_ID = "MODEL_ID" | ||
| ENV_HUB_MODEL_FILENAME = "MODEL_FILENAME" | ||
| ENV_HUB_MODEL_ALLOW_PATTERNS = "MODEL_ALLOW_PATTERNS" | ||
| ENV_HUB_MODEL_IGNORE_PATTERNS = "MODEL_IGNORE_PATTERNS" | ||
|
|
||
| ENV_OBJ_PROVIDER = "PROVIDER" | ||
| ENV_OBJ_ENDPOINT = "ENDPOINT" | ||
| ENV_OBJ_BUCKET = "BUCKET" | ||
| ENV_OBJ_MODEL_PATH = "MODEL_PATH" | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,69 +17,51 @@ | |
| import concurrent.futures | ||
| import os | ||
|
|
||
| from huggingface_hub import hf_hub_download, list_repo_files | ||
| from huggingface_hub import snapshot_download | ||
|
|
||
| from llmaz.model_loader.defaults import MODEL_LOCAL_DIR | ||
| from llmaz.model_loader.constant import MODEL_LOCAL_DIR, HUB_HUGGING_FACE | ||
| from llmaz.model_loader.model_hub.model_hub import ( | ||
| HUGGING_FACE, | ||
| MAX_WORKERS, | ||
| ModelHub, | ||
| ) | ||
| from llmaz.util.logger import Logger | ||
| from llmaz.model_loader.model_hub.util import get_folder_total_size | ||
|
|
||
| from typing import Optional | ||
| from typing import Optional, List | ||
|
|
||
|
|
||
| class Huggingface(ModelHub): | ||
| @classmethod | ||
| def name(cls) -> str: | ||
| return HUGGING_FACE | ||
| return HUB_HUGGING_FACE | ||
|
|
||
| @classmethod | ||
| def load_model( | ||
| cls, model_id: str, filename: Optional[str], revision: Optional[str] | ||
| cls, | ||
| model_id: str, | ||
| filename: Optional[str], | ||
| revision: Optional[str], | ||
| allow_patterns: Optional[List[str]], | ||
| ignore_patterns: Optional[List[str]], | ||
| ) -> None: | ||
| Logger.info( | ||
| f"Start to download, model_id: {model_id}, filename: {filename}, revision: {revision}" | ||
| ) | ||
|
|
||
| if filename: | ||
| hf_hub_download( | ||
| repo_id=model_id, | ||
| filename=filename, | ||
| local_dir=MODEL_LOCAL_DIR, | ||
| revision=revision, | ||
| ) | ||
| file_size = os.path.getsize(MODEL_LOCAL_DIR + filename) / (1024**3) | ||
| Logger.info( | ||
| f"The total size of {MODEL_LOCAL_DIR + filename} is {file_size: .2f} GB" | ||
| ) | ||
| return | ||
|
|
||
| local_dir = os.path.join( | ||
| MODEL_LOCAL_DIR, f"models--{model_id.replace('/','--')}" | ||
| MODEL_LOCAL_DIR, f"models--{model_id.replace('/', '--')}" | ||
| ) | ||
|
|
||
| # # TODO: Should we verify the download is finished? | ||
| with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor: | ||
| futures = [] | ||
| for file in list_repo_files(repo_id=model_id): | ||
| # TODO: support version management, right now we didn't distinguish with them. | ||
| futures.append( | ||
| executor.submit( | ||
| hf_hub_download, | ||
| repo_id=model_id, | ||
| filename=file, | ||
| local_dir=local_dir, | ||
| revision=revision, | ||
| ).add_done_callback(handle_completion) | ||
| ) | ||
| if filename: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's be more simple here, if filename, the allow_patterns will be the filename. Actually, In OP is not that accurate, we may have pattern like And we should add a validation in the webhook as |
||
| allow_patterns.append(filename) | ||
| local_dir = MODEL_LOCAL_DIR | ||
|
|
||
| snapshot_download( | ||
| repo_id=model_id, | ||
| revision=revision, | ||
| local_dir=local_dir, | ||
| allow_patterns=allow_patterns, | ||
| ignore_patterns=ignore_patterns, | ||
| ) | ||
|
|
||
| total_size = get_folder_total_size(local_dir) | ||
| Logger.info(f"The total size of {local_dir} is {total_size: .2f} GB") | ||
|
|
||
|
|
||
| def handle_completion(future): | ||
| filename = future.result() | ||
| Logger.info(f"Download completed for {filename}") | ||
| Logger.info(f"The total size of {local_dir} is {total_size: .2f} GB") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update the comment of Filename as well,