Mathmate-7B-DELLA-ORPO-D 是基于 Haleshot/Mathmate-7B-DELLA-ORPO 通过 ORPO 方法微调得到的版本,并结合了在日常对话数据上训练的 LoRA 适配器。
该模型使用 HuggingFaceTB/everyday-conversations-llama3.1-2k 数据集进行训练,该数据集专注于日常对话和闲聊内容。
from openmind import pipeline, is_torch_npu_available
from openmind_hub import snapshot_download
import torch.nn.functional as F
from torch import Tensor
import openmind
import torch
import argparse
import time
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_name_or_path",
type=str,
help="Path to model",
default="jeffding/Mathmate-7B-DELLA-ORPO-D-openmind",
)
args = parser.parse_args()
return args
def main():
args = parse_args()
model_path = args.model_name_or_path
if is_torch_npu_available():
device = "npu:0"
else:
device = "cpu"
start_time = time.time()
pipe = pipeline("text-generation", model=model_path, torch_dtype=torch.bfloat16, device_map=device)
messages = [
{
"role": "system",
"content": "You are a friendly chatbot who always responds in the style of a pirate",
},
{"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
]
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
print(outputs[0]["generated_text"])
end_time = time.time()
print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
if __name__ == "__main__":
main()以下是使用该模型的示例:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_name = "Haleshot/Mathmate-7B-DELLA-ORPO-ORPO-D"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
def generate_response(prompt, max_length=512):
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_length=max_length, num_return_sequences=1, do_sample=True, temperature=0.7)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
prompt = "Let's have a casual conversation about weekend plans."
response = generate_response(prompt)
print(response)感谢 HuggingFaceTB 团队提供本微调过程中使用的日常对话数据集。