Skip to content

Commit

Permalink
Added missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
tgaddair committed Apr 2, 2024
1 parent 24409d1 commit 514eae6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions server/lorax_server/adapters/utils.py
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()

0 comments on commit 514eae6

Please sign in to comment.