https://github.com/jzhang38/TinyLlama
TinyLlama项目旨在预训练一个基于3万亿tokens的1.1B Llama模型。通过适当的优化,我们仅需16块A100-40G GPU,在“短短”90天内即可完成这一目标🚀🚀。训练已于2023年9月1日正式启动。
我们采用了与Llama 2完全相同的架构和分词器。这意味着TinyLlama可以直接应用于许多基于Llama构建的开源项目中,实现即插即用。此外,TinyLlama仅有1.1B参数,非常轻量。这种轻量特性使其能够满足多种对计算和内存资源有严格限制的应用场景。
此模型是在TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T基础上微调得到的对话模型。我们遵循HF's Zephyr的训练方案。 该模型“首先在UltraChat数据集的一个变体上进行微调,该数据集包含由ChatGPT生成的各种合成对话。
然后,我们使用🤗 TRL's的DPOTrainer在openbmb/UltraFeedback数据集上进一步对齐模型,该数据集包含64k个提示以及由GPT-4评分的模型补全内容。”
您需要安装transformers>=4.34版本。 更多信息请查看TinyLlama GitHub页面。
# Install transformers from source - only needed for versions <= v4.34
# pip install git+https://github.com/huggingface/transformers.git
# pip install accelerate
from mindnlp.transformers import pipeline
pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", device_map="auto")
# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
messages = [
{
"role": "system",
"content": "You are a friendly chatbot who always responds in the style of a pirate",
},
{"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
]
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
print(outputs[0]["generated_text"])
# <|system|>
# You are a friendly chatbot who always responds in the style of a pirate.</s>
# <|user|>
# How many helicopters can a human eat in one sitting?</s>
# <|assistant|>
# ...