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 download script for tinyllamas #163

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Then login with `huggingface-cli login`
## Downloading Weights
Models tested/supported
```text
tinyllamas/stories{15,42,100}
tinyllamas/stories{15M,42M,100M}
openlm-research/open_llama_7b
meta-llama/Llama-2-7b-chat-hf
meta-llama/Llama-2-13b-chat-hf
Expand Down
3 changes: 3 additions & 0 deletions scripts/convert_hf_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def convert_hf_checkpoint(
checkpoint_dir: Path = Path("checkpoints/meta-Transformer/Transformer-2-7b-chat-hf"),
model_name: Optional[str] = None,
) -> None:
if "stories" in checkpoint_dir.name:
# No need to convert tinyllamas
return
if model_name is None:
model_name = checkpoint_dir.name

Expand Down
17 changes: 17 additions & 0 deletions scripts/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@
from typing import Optional

from requests.exceptions import HTTPError
import subprocess

def download_tinyllamas(repo_id: str, local_dir: str) -> None:
try:
model_name = repo_id.split("/")[-1]
# Download model weight
weight_url = "https://huggingface.co/karpathy/tinyllamas/resolve/main/" + model_name + ".pt"
weight_dst_path = os.path.join(local_dir, "model.pth")
subprocess.run(["wget", weight_url, "-O", weight_dst_path], check=True)
# Download tokenizer model
tokenizer_url = "https://github.com/karpathy/llama2.c/blob/master/tokenizer.model"
yiliu30 marked this conversation as resolved.
Show resolved Hide resolved
tokenizer_dst_path: str = os.path.join(local_dir, "tokenizer.model")
subprocess.run(["wget", tokenizer_url, "-O", tokenizer_dst_path], check=True)
except subprocess.CalledProcessError as e:
print(f"Failed to download {repo_id}: {e}")

def hf_download(repo_id: Optional[str] = None, hf_token: Optional[str] = None) -> None:
from huggingface_hub import snapshot_download
os.makedirs(f"checkpoints/{repo_id}", exist_ok=True)
if "stories" in repo_id:
download_tinyllamas(repo_id, f"checkpoints/{repo_id}")
return
try:
snapshot_download(repo_id, local_dir=f"checkpoints/{repo_id}", local_dir_use_symlinks=False, token=hf_token)
except HTTPError as e:
Expand Down