-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨Style Transfer: the model is serve in a separate file
- Loading branch information
1 parent
d526de8
commit 07e92aa
Showing
3 changed files
with
64 additions
and
46 deletions.
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
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
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,37 @@ | ||
import logging | ||
|
||
import mii | ||
import torch | ||
import wandb | ||
import yaml | ||
from omegaconf import omegaconf | ||
from peft import AutoPeftModelForCausalLM | ||
from transformers import AutoTokenizer | ||
|
||
with open("configs/default.yaml", "r") as f: | ||
cfg = omegaconf.OmegaConf.create(yaml.safe_load(f)) | ||
with open("configs/gen.yaml", "r") as f: | ||
cfg = omegaconf.OmegaConf.merge(cfg, omegaconf.OmegaConf.create(yaml.safe_load(f))) | ||
|
||
api = wandb.Api() | ||
model_artifact = api.artifact(cfg.checkpoint) | ||
model_dir = model_artifact.download() | ||
model = AutoPeftModelForCausalLM.from_pretrained( | ||
pretrained_model_name_or_path=model_dir, | ||
torch_dtype=torch.bfloat16, | ||
device_map="auto", | ||
) | ||
model = model.merge_and_unload() | ||
model.save_pretrained("models/merged/") | ||
tokenizer = AutoTokenizer.from_pretrained(cfg.model) | ||
tokenizer.save_pretrained("models/merged/") | ||
del model | ||
del tokenizer | ||
logging.info("Model + Tokenizer saved at models/merged/") | ||
logging.info("Loading model to pipeline 🐉 ...") | ||
client = mii.serve( | ||
"models/merged/", | ||
tensor_parallel=4, | ||
deployment_name=cfg.checkpoint, | ||
) | ||
logging.info("Model loaded to pipeline ! 🎉") |