Skip to content
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

Add llama download support for multiple models with comma-separated list #243

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/cli_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,26 @@ llama download --source meta --model-id Llama3.2-11B-Vision-Instruct --meta-url
# safety models -- Llama-Guard and Prompt-Guard
llama download --source meta --model-id Prompt-Guard-86M --meta-url META_URL
llama download --source meta --model-id Llama-Guard-3-1B --meta-url META_URL

# Download multiple models with a single command
llama download --source meta --model-ids Llama3.2-3B-Instruct,Llama3.2-11B-Vision-Instruct --meta-url META_URL_1,META_URL_2
```


#### Downloading from [Hugging Face](https://huggingface.co/meta-llama)

Essentially, the same commands above work, just replace `--source meta` with `--source huggingface`.

```bash
llama download --source huggingface --model-id Llama3.1-8B-Instruct --hf-token <HF_TOKEN>
llama download --source huggingface --model-id Llama3.1-8B-Instruct --hf-token <HF_TOKEN>

llama download --source huggingface --model-id Llama3.1-70B-Instruct --hf-token <HF_TOKEN>

llama download --source huggingface --model-id Llama-Guard-3-1B --ignore-patterns *original*
llama download --source huggingface --model-id Prompt-Guard-86M --ignore-patterns *original*

# Download multiple models with a single command
llama download --source huggingface --model-ids Llama3.2-3B-Instruct,Llama3.2-11B-Vision-Instruct --hf-token <HF_TOKEN>
```

**Important:** Set your environment variable `HF_TOKEN` or pass in `--hf-token` to the command to validate your access. You can find your token at [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens).
Expand Down
59 changes: 38 additions & 21 deletions llama_stack/cli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def setup_download_parser(parser: argparse.ArgumentParser) -> None:
required=False,
help="See `llama model list` or `llama model list --show-all` for the list of available models",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just make this nargs='+' so you can provide it multiple times like --model-id A --model-id B?

)
parser.add_argument(
"--model-ids",
required=False,
help="Comma-separated list of model IDs to download. See `llama model list` or `llama model list --show-all` for the list of available models",
)
parser.add_argument(
"--hf-token",
type=str,
Expand Down Expand Up @@ -148,31 +153,43 @@ def run_download_cmd(args: argparse.Namespace, parser: argparse.ArgumentParser):
_download_from_manifest(args.manifest_file)
return

if args.model_id is None:
parser.error("Please provide a model id")
if args.model_ids:
model_ids = [model_id.strip() for model_id in args.model_ids.split(",")]
elif args.model_id:
model_ids = [args.model_id]
else:
parser.error("Please provide a model id or a list of model ids (--model-ids)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please provide a model using --model-id or --model-ids

return

prompt_guard = prompt_guard_model_sku()
if args.model_id == prompt_guard.model_id:
model = prompt_guard
info = prompt_guard_download_info()
else:
model = resolve_model(args.model_id)
if model is None:
parser.error(f"Model {args.model_id} not found")
return
info = llama_meta_net_info(model)
meta_urls = []
if args.meta_url:
meta_urls = [url.strip() for url in args.meta_url.split(",")]
if len(meta_urls) > 0 and len(meta_urls) != len(model_ids):
parser.error("The number of --meta-url values must match the number of --model-ids values.")

if args.source == "huggingface":
_hf_download(model, args.hf_token, args.ignore_patterns, parser)
else:
meta_url = args.meta_url
if not meta_url:
meta_url = input(
"Please provide the signed URL you received via email after visiting https://www.llama.com/llama-downloads/ (e.g., https://llama3-1.llamameta.net/*?Policy...): "
)
prompt_guard = prompt_guard_model_sku()
for idx, model_id in enumerate(model_ids):
if model_id == prompt_guard.model_id:
model = prompt_guard
info = prompt_guard_download_info()
else:
model = resolve_model(model_id)
if model is None:
parser.error(f"Model {model_id} not found")
return
info = llama_meta_net_info(model)

if args.source == "huggingface":
_hf_download(model, args.hf_token, args.ignore_patterns, parser)
else:
if len(meta_urls) > idx:
meta_url = meta_urls[idx]
else:
meta_url = input(
f"Please provide the signed URL for {model_id} you received via email after visiting https://www.llama.com/llama-downloads/ (e.g., https://llama3-1.llamameta.net/*?Policy...): "
)
assert meta_url is not None and "llamameta.net" in meta_url
_meta_download(model, meta_url, info)
_meta_download(model, meta_url, info)


class ModelEntry(BaseModel):
Expand Down
Loading