How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-generation", model="niwz/Mini-Chinese-Phi3")
messages = [
    {"role": "user", "content": "Who are you?"},
]
pipe(messages)
# Load model directly
from transformers import AutoTokenizer, MiniPhi3

tokenizer = AutoTokenizer.from_pretrained("niwz/Mini-Chinese-Phi3")
model = MiniPhi3.from_pretrained("niwz/Mini-Chinese-Phi3", device_map="auto")
messages = [
    {"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
	messages,
	add_generation_prompt=True,
	tokenize=True,
	return_dict=True,
	return_tensors="pt",
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
Quick Links

Mini Chinese Phi3

Mini-Chinese-Phi3是一个基于phi3模型结构的小型对话模型,总参数量约0.13B,使用常见的中文语料进行预训练和微调。主要内容包括了

  • 数据集的整理与简单清洗
  • 中文词表预训练
  • 基于phi3结构的模型预训练
  • 基于预训练模型的指令微调(SFT),包括了全量微调和LoRA微调
  • 基于指令微调模型的直接偏好优化(DPO)
  • 模型评测 (待做)

项目中的所有训练过程均在两张3090显卡上进行,使用DeepSpeed框架和Flash Attention 2进行加速,预训练用时约40小时,SFT和DPO微调共用时约8小时。本项目是我在学习LLM过程中的一个简单实践,同时也希望能够帮助到同样初学大模型的小伙伴。

项目训练细节等已在Github上开源,欢迎大家提出宝贵意见和建议。项目地址

Downloads last month
11
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Datasets used to train niwz/Mini-Chinese-Phi3