forked from NovaSky-AI/SkyThought
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
From https://github.com/lm-sys/FastChat/ | ||
Upload weights to huggingface. | ||
Usage: | ||
python upload_hub.py --model-path ~/model_weights/Sky-T1 --hub-repo-id NovaSky-AI/Sky-T1 --private | ||
""" | ||
import argparse | ||
import tempfile | ||
|
||
import torch | ||
from transformers import AutoTokenizer, AutoModelForCausalLM | ||
|
||
def upload_hub(model_path, hub_repo_id, component, private): | ||
if component == "all": | ||
components = ["model", "tokenizer"] | ||
else: | ||
components = [component] | ||
|
||
kwargs = {"push_to_hub": True, "repo_id": hub_repo_id, "private": args.private} | ||
|
||
if "model" in components: | ||
model = AutoModelForCausalLM.from_pretrained( | ||
model_path, torch_dtype=torch.float16, low_cpu_mem_usage=True | ||
) | ||
with tempfile.TemporaryDirectory() as tmp_path: | ||
model.save_pretrained(tmp_path, **kwargs) | ||
|
||
if "tokenizer" in components: | ||
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False) | ||
with tempfile.TemporaryDirectory() as tmp_path: | ||
tokenizer.save_pretrained(tmp_path, **kwargs) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--model-path", type=str, required=True) | ||
parser.add_argument("--hub-repo-id", type=str, required=True) | ||
parser.add_argument( | ||
"--component", type=str, choices=["all", "model", "tokenizer"], default="all" | ||
) | ||
parser.add_argument("--private", action="store_true") | ||
args = parser.parse_args() | ||
|
||
upload_hub(args.model_path, args.hub_repo_id, args.component, args.private) |
This file contains 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