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 buck target for hf_download #9603

Merged
merged 1 commit into from
Mar 26, 2025
Merged
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
11 changes: 11 additions & 0 deletions examples/models/llama/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ runtime.python_library(
],
)

runtime.python_library(
name = "hf_download",
srcs = [
"hf_download.py",
],
deps = [
"fbsource//third-party/pypi/huggingface-hub:huggingface-hub",
]
)

runtime.python_library(
name = "export_library",
srcs = [
Expand All @@ -134,6 +144,7 @@ runtime.python_library(
"@EXECUTORCH_CLIENTS",
],
deps = [
":hf_download",
":source_transformation",
"//ai_codesign/gen_ai/fast_hadamard_transform:fast_hadamard_transform",
"//caffe2:torch",
Expand Down
12 changes: 9 additions & 3 deletions examples/models/llama/export_llama_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,17 @@ def export_llama(args) -> str:
if not args.checkpoint and args.model in HUGGING_FACE_REPO_IDS:
repo_id = HUGGING_FACE_REPO_IDS[args.model]
if args.model == "qwen2_5":
from executorch.examples.models.qwen2_5 import convert_weights
from executorch.examples.models.qwen2_5 import ( # pyre-ignore[21]
convert_weights,
)
elif args.model == "phi_4_mini":
from executorch.examples.models.phi_4_mini import convert_weights
from executorch.examples.models.phi_4_mini import ( # pyre-ignore[21]
convert_weights,
)
elif args.model == "smollm2":
from executorch.examples.models.smollm2 import convert_weights
from executorch.examples.models.smollm2 import ( # pyre-ignore[21]
convert_weights,
)
else:
raise ValueError(
f"Converting weights to meta format for {args.model} is not yet supported"
Expand Down
8 changes: 4 additions & 4 deletions examples/models/llama/hf_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def download_and_convert_hf_checkpoint(
converted_path = cache_dir / f"{model_name}.pth"

if converted_path.exists():
print(f"✔ Using cached converted model: {converted_path}")
return converted_path
print(f"✔ Using cached converted model: {str(converted_path)}")
return str(converted_path)

# 1. Download weights from Hugging Face.
print("⬇ Downloading and converting checkpoint...")
Expand All @@ -46,5 +46,5 @@ def download_and_convert_hf_checkpoint(
)

# 2. Convert weights to Meta format.
convert_weights(checkpoint_path, converted_path)
return converted_path
convert_weights(checkpoint_path, str(converted_path))
return str(converted_path)
Loading