🚀 peft
本项目是一个针对Meta的Llama 2 7B模型的适配器,经过微调后可将法语文本翻译成英语,为法语到英语的翻译任务提供了有效的解决方案。
🚀 快速开始
此适配器必须加载在Llama 2 7B之上,并且使用QLoRA进行了微调。为获得最佳效果,基础模型必须使用微调期间的完全相同配置进行加载。
你可以使用以下代码加载模型:
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import torch
from peft import PeftModel
base_model = "meta-llama/Llama-2-7b-hf"
compute_dtype = getattr(torch, "float16")
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=compute_dtype,
bnb_4bit_use_double_quant=True,
)
model = AutoModelForCausalLM.from_pretrained(
original_model_directory, device_map={"": 0}, quantization_config=bnb_config
)
tokenizer = AutoTokenizer.from_pretrained(base_model, use_fast=True)
model = PeftModel.from_pretrained(model, "kaitchup/Llama-2-7b-mt-French-to-English")
然后,按如下方式运行模型:
my_text = ""
prompt = my_text+" ###>"
tokenized_input = tokenizer(prompt, return_tensors="pt")
input_ids = tokenized_input["input_ids"].cuda()
generation_output = model.generate(
input_ids=input_ids,
num_beams=10,
return_dict_in_generate=True,
output_scores=True,
max_new_tokens=130
)
for seq in generation_output.sequences:
output = tokenizer.decode(seq, skip_special_tokens=True)
print(output.split("###>")[1].strip())
✨ 主要特性
- 专为Meta的Llama 2 7B模型设计的适配器,可实现法语到英语的翻译。
- 使用QLoRA进行微调,确保翻译效果。
📚 详细文档
模型详情
模型描述
- 开发者:The Kaitchup
- 模型类型:Llama 2 7B的LoRA适配器
- 语言(NLP):法语、英语
- 许可证:MIT许可证
📄 许可证
本模型采用MIT许可证。
📦 模型卡片联系方式
The Kaitchup