-
Notifications
You must be signed in to change notification settings - Fork 754
Download checkpoints from HuggingFace #9538
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6afd1c0
Rename phi-4-mini to phi_4_mini
jackzhxng 3de41ce
Download checkpoint from HuggingFace
jackzhxng 2c6609a
Tarun pr review
jackzhxng 7990574
Merge branch 'main' into jz/hf-download
jackzhxng 4db8f07
Support smollm2
jackzhxng 85d85c7
Merge branch 'main' into jz/hf-download
jackzhxng ed0c43d
Merge branch 'main' into jz/hf-download
jackzhxng 19cda10
Lint
jackzhxng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,9 +95,13 @@ | |
| "llama3_2", | ||
| "static_llama", | ||
| "qwen2_5", | ||
| "phi-4-mini", | ||
| "phi_4_mini", | ||
| ] | ||
| TORCHTUNE_DEFINED_MODELS = ["llama3_2_vision"] | ||
| HUGGING_FACE_REPO_IDS = { | ||
| "qwen2_5": "Qwen/Qwen2.5-1.5B", | ||
| "phi_4_mini": "microsoft/Phi-4-mini-instruct", | ||
| } | ||
|
|
||
|
|
||
| class WeightType(Enum): | ||
|
|
@@ -519,7 +523,53 @@ def canonical_path(path: Union[str, Path], *, dir: bool = False) -> str: | |
| return return_val | ||
|
|
||
|
|
||
| def download_and_convert_hf_checkpoint(modelname: str) -> str: | ||
| """ | ||
| Downloads and converts to Meta format a HuggingFace checkpoint. | ||
| """ | ||
| # Build cache path. | ||
| cache_subdir = "meta_checkpoints" | ||
| cache_dir = Path.home() / ".cache" / cache_subdir | ||
| cache_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| # Use repo name to name the converted file. | ||
| repo_id = HUGGING_FACE_REPO_IDS[modelname] | ||
| model_name = repo_id.replace( | ||
| "/", "_" | ||
| ) | ||
| converted_path = cache_dir / f"{model_name}.pth" | ||
|
|
||
| if converted_path.exists(): | ||
| print(f"✔ Using cached converted model: {converted_path}") | ||
| return converted_path | ||
|
|
||
| # 1. Download weights from Hugging Face. | ||
| print("⬇ Downloading and converting checkpoint...") | ||
| from huggingface_hub import snapshot_download | ||
|
|
||
| checkpoint_path = snapshot_download( | ||
| repo_id=repo_id, | ||
| ) | ||
|
|
||
| # 2. Convert weights to Meta format. | ||
| if modelname == "qwen2_5": | ||
| from executorch.examples.models.qwen2_5 import convert_weights | ||
|
|
||
| convert_weights(checkpoint_path, converted_path) | ||
| elif modelname == "phi_4_mini": | ||
| from executorch.examples.models.phi_4_mini import convert_weights | ||
|
|
||
| convert_weights(checkpoint_path, converted_path) | ||
| elif modelname == "smollm2": | ||
| pass | ||
|
||
|
|
||
| return converted_path | ||
|
|
||
|
|
||
| def export_llama(args) -> str: | ||
| if not args.checkpoint and args.model in HUGGING_FACE_REPO_IDS: | ||
| args.checkpoint = download_and_convert_hf_checkpoint(args.model) | ||
|
|
||
| if args.profile_path is not None: | ||
| try: | ||
| from executorch.util.python_profiler import CProfilerFlameGraph | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this in a separate util file? I think it'll be useful elsewhere too potentially and also this file is getting quite bloated too i think.