Comments (3)
The following script merges the peft adapter with the base model and uploads the result to HF:
# Example usage:
# python merge_peft.py --base_model=meta-llama/Llama-2-7b-hf --peft_model=./qlora-out --hub_id=alpaca-qlora
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
import os
import argparse
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("--base_model", type=str)
parser.add_argument("--peft_model", type=str)
parser.add_argument("--hub_id", type=str)
return parser.parse_args()
def main():
args = get_args()
print(f"[1/5] Loading base model: {args.base_model}")
base_model = AutoModelForCausalLM.from_pretrained(
args.base_model,
return_dict=True,
torch_dtype=torch.float16,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained(args.base_model)
print(f"[2/5] Loading adapter: {args.peft_model}")
model = PeftModel.from_pretrained(base_model, args.peft_model, device_map="auto")
print("[3/5] Merge base model and adapter")
model = model.merge_and_unload()
print(f"[4/5] Saving model and tokenizer in {args.hub_id}")
model.save_pretrained(f"{args.hub_id}")
tokenizer.save_pretrained(f"{args.hub_id}")
print(f"[5/5] Uploading to Hugging Face Hub: {args.hub_id}")
model.push_to_hub(f"{args.hub_id}", use_temp_dir=False)
tokenizer.push_to_hub(f"{args.hub_id}", use_temp_dir=False)
print("Merged model uploaded to Hugging Face Hub!")
if __name__ == "__main__" :
main()
from llama2lang.
We will have to check what to do with these, for now we will focus on LoRA. As for OASST2, might be useful to make it optional to use indeed but it is about 50% bigger so that also means an even longer runtime.
from llama2lang.
Yes seems about right, we already unload in inference. Care to make a PR, also supporting loading from and saving to disk?
from llama2lang.
Related Issues (20)
- English folder is empty when translated the dataset to english HOT 1
- Question or bug HOT 5
- Feature request: ChatML support
- Madlad: unrecognized arguments: --model_size 7b HOT 2
- Got this error during finetuning HOT 3
- Support finetuning from local disk too
- Issue with THREAD_TEMPLATE HOT 3
- Sample Example for finetuning
- Feedback on the hindi fientuned model HOT 7
- SeamlessM4T-v2 default (medium) model removed from huggingface HOT 1
- nllb.py and madlad.py points to the incorrect HF repositories HOT 9
- error running benchmark.py with seamless HOT 2
- Dataset chat format independent HOT 2
- problem with run_inference.py HOT 4
- Best translation model for turkish HOT 2
- Translating takes too long (How to finetuning with QLoRA?) HOT 2
- Question: How would I do this with Phi 2? HOT 1
- Question: translating a monolingual HF Dataset HOT 2
- Can you make a dataset of LLaMa3-8B translated into Japanese? HOT 2
- [Question] What framework is able to load this adapter and serve the resulting model as an OpenAI endpoint? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llama2lang.