🚀 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