Downloads · 30 days
21
2% of all-time downloads
weiren119/traditional_chinese_qlora_llama2
traditional_chinese_qlora_llama2 is a machine learning model from weiren119. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as apache-2.0.
- github repo: https://github.com/MIBlue119/traditionalchinesellama2/ - Practice to finetune Llama2 on traditional chinese instruction dataset at Llama2 chat model. I use qlora and the alpaca translated dataset to fin…
Downloads · 30 days
21
2% of all-time downloads
All-time downloads
1.2K
Public
Repo size
134 MB
Likes
2
Public
Click a slice to open those files.
.bin134 MB · 100%
From the Hugging Face model README
Thanks for these references:
the repois model adpater if you want to use the merged checkpoint(adapter+original model) repo: https://huggingface.co/weiren119/traditional_chinese_qlora_llama2_merged
The following bitsandbytes quantization config was used during training:
$pip install transformers torch peft
import transformers
import torch
from transformers import AutoTokenizer, TextStreamer
from peft import AutoPeftModelForCausalLM
# Use the same tokenizer from the source model
original_model_path="NousResearch/Llama-2-7b-chat-hf"
tokenizer = AutoTokenizer.from_pretrained(original_model_path, use_fast=False)
# Load qlora fine-tuned model, you can replace this with your own model
qlora_model_path = "weiren119/traditional_chinese_qlora_llama2"
model = AutoPeftModelForCausalLM.from_pretrained(
qlora_model_path,
load_in_4bit=qlora_model_path.endswith("4bit"),
torch_dtype=torch.float16,
device_map='auto'
)
system_prompt = """You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information."""
def get_prompt(message: str, chat_history: list[tuple[str, str]]) -> str:
texts = [f'[INST] <<SYS>>\n{system_prompt}\n<</SYS>>\n\n']
for user_input, response in chat_history:
texts.append(f'{user_input.strip()} [/INST] {response.strip()} </s><s> [INST] ')
texts.append(f'{message.strip()} [/INST]')
return ''.join(texts)
print ("="*100)
print ("-"*80)
print ("Have a try!")
s = ''
chat_history = []
while True:
s = input("User: ")
if s != '':
prompt = get_prompt(s, chat_history)
print ('Answer:')
tokens = tokenizer(prompt, return_tensors='pt').input_ids
#generate_ids = model.generate(tokens.cuda(), max_new_tokens=4096, streamer=streamer)
generate_ids = model.generate(input_ids=tokens.cuda(), max_new_tokens=4096, streamer=streamer)
output = tokenizer.decode(generate_ids[0, len(tokens[0]):-1]).strip()
chat_history.append([s, output])
print ('-'*80)