英文

此模型是通过在 Dahoas/synthetic-instruct-gptj-pairwise 上进行 EleutherAI/pythia-2.8b-deduped 而创建的。

您可以尝试在 Lambda Cloud 上托管的该模型的 demo

模型详情

先决条件

使用该模型进行推理需要约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|>

训练

该模型是在 Dahoas/synthetic-instruct-gptj-pairwise 上进行训练的。我们将原始数据集分为训练集(前32000个示例)和验证集(剩余的1144个示例)。

我们将模型进行了4个时期的微调。这花费了8xA100 80GB 5小时,其中我们将 batch_size_per_gpu 设置为2(因此全局batch大小为16),学习率设置为0.00001(在最后一个训练步骤中线性衰减到零)。您可以在Weights and Biases记录 here 中找到。