🚀 合成指令微调Pythia 2.8B模型
本项目基于预训练模型进行微调,得到了一个强大的语言模型。该模型在特定数据集上进行训练,能够在多种自然语言处理任务中表现出色,为用户提供高质量的文本生成服务。
🚀 快速开始
运行环境
运行该模型推理大约需要7GB的GPU内存。
代码示例
import torch
from transformers import AutoTokenizer, pipeline, StoppingCriteria, StoppingCriteriaList
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
model_name = "lambdalabs/pythia-2.8b-deduped-synthetic-instruct"
max_new_tokens = 2048
stop_token = "<|stop|>"
class KeywordsStoppingCriteria(StoppingCriteria):
def __init__(self, keywords_ids: list):
self.keywords = keywords_ids
def __call__(
self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs
) -> bool:
if input_ids[0][-1] in self.keywords:
return True
return False
tokenizer = AutoTokenizer.from_pretrained(
model_name,
)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.add_tokens([stop_token])
stop_ids = [tokenizer.encode(w)[0] for w in [stop_token]]
stop_criteria = KeywordsStoppingCriteria(stop_ids)
generator = pipeline(
"text-generation",
model=model_name,
device=device,
max_new_tokens=max_new_tokens,
torch_dtype=torch.float16,
stopping_criteria=StoppingCriteriaList([stop_criteria]),
)
example = "How can I make an omelette."
text = "Question: {}\nAnswer:".format(example)
result = generator(
text,
num_return_sequences=1,
)
output = result[0]["generated_text"]
print(output)
输出示例
Question: How can I make an omelette.
Answer:To make an omelette, start by cracking two eggs into a bowl and whisking them together. Add a splash of milk and a pinch of salt and pepper. Heat a non-stick pan over medium-high heat and add a tablespoon of butter. Once the butter has melted, pour in the egg mixture. As the eggs set, use a spatula to lift the edges and let the uncooked egg run underneath. When the eggs are cooked through and no visible liquid egg remains, top with your desired fillings and fold the omelette in half before sliding it onto a plate.<|stop|>
✨ 主要特性
- 基于Transformer架构,在自然语言处理任务中具有强大的性能。
- 在特定数据集上进行微调,能够生成高质量的文本。
📦 安装指南
文档未提及具体安装步骤,故跳过该章节。
📚 详细文档
模型详情
训练详情
该模型在Dahoas/synthetic-instruct-gptj-pairwise
数据集上进行训练。我们将原始数据集划分为训练集(前32000个示例)和验证集(剩余1144个示例)。
我们对模型进行了4个轮次的微调。这一过程使用8张A100 80GB GPU,耗时5小时,其中batch_size_per_gpu
设置为2
(全局批量大小为16),学习率设置为0.00001
(在最后一个训练步骤线性衰减至零)。你可以在这里查看Weights and Biases记录。
📄 许可证
本模型使用的许可证为Apache 2.0。你可以通过以下链接尝试该模型的演示,演示由Lambda Cloud提供。