-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Optional | ||
|
||
from huggingface_hub import HfApi | ||
|
||
from lorax_server.utils.sources import HUB, PBASE, S3, get_model_source, map_pbase_model_id_to_s3 | ||
from lorax_server.utils.weights import download_weights | ||
|
||
|
||
def download_adapter( | ||
adapter_id: str, | ||
adapter_source: str, | ||
api_token: Optional[str] = None, | ||
) -> int: | ||
if adapter_source == PBASE: | ||
adapter_id = map_pbase_model_id_to_s3(adapter_id, api_token) | ||
adapter_source = S3 | ||
|
||
if adapter_source == HUB: | ||
# Quick auth check on the repo against the token | ||
HfApi(token=api_token).model_info(adapter_id, revision=None) | ||
|
||
# fail fast if ID is not an adapter (i.e. it is a full model) | ||
source = get_model_source(adapter_source, adapter_id, extension=".safetensors", api_token=api_token) | ||
source.load_config() | ||
|
||
download_weights( | ||
adapter_id, source=adapter_source, api_token=api_token | ||
) | ||
|
||
# Calculate size of adapter to be loaded | ||
return source.get_weight_bytes() |