🚀 合成指令微調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提供。