|
|
|
|
|
|
|
import modal |
|
|
|
MODELS_DIR = "/llamas" |
|
|
|
DEFAULT_NAME = "meta-llama/Meta-Llama-3.1-8B-Instruct" |
|
DEFAULT_REVISION = "8c22764a7e3675c50d4c7c9a4edb474456022b16" |
|
|
|
volume = modal.Volume.from_name("llamas", create_if_missing=True) |
|
|
|
image = ( |
|
modal.Image.debian_slim(python_version="3.10") |
|
.pip_install( |
|
[ |
|
"huggingface_hub", |
|
"hf-transfer", |
|
] |
|
) |
|
.env({"HF_HUB_ENABLE_HF_TRANSFER": "1"}) |
|
) |
|
|
|
|
|
MINUTES = 60 |
|
HOURS = 60 * MINUTES |
|
|
|
|
|
app = modal.App( |
|
image=image, secrets=[modal.Secret.from_name("huggingface-secret")] |
|
) |
|
|
|
|
|
@app.function(volumes={MODELS_DIR: volume}, timeout=4 * HOURS) |
|
def download_model(model_name, model_revision, force_download=False): |
|
from huggingface_hub import snapshot_download |
|
|
|
volume.reload() |
|
|
|
snapshot_download( |
|
model_name, |
|
local_dir=MODELS_DIR + "/" + model_name, |
|
ignore_patterns=[ |
|
"*.pt", |
|
"*.bin", |
|
"*.pth", |
|
"original/*", |
|
], |
|
revision=model_revision, |
|
force_download=force_download, |
|
) |
|
|
|
volume.commit() |
|
|
|
|
|
@app.local_entrypoint() |
|
def main( |
|
model_name: str = DEFAULT_NAME, |
|
model_revision: str = DEFAULT_REVISION, |
|
force_download: bool = False, |
|
): |
|
download_model.remote(model_name, model_revision, force_download) |