从 零一万物 Yi 官方 GitHub README 翻译整理的快速上手指南。
Yi 系列模型是 01.AI(零一万物)从头训练的新一代开源双语大语言模型。基于 Transformer 架构,在 3T 多语言语料上训练,支持中文和英文。模型架构与 Llama 相同,但不是 Llama 的衍生品。
Yi 模型在语言理解、常识推理、阅读理解等任务上表现出色:
提供两类模型:
方式一:pip 安装
pip install transformers
方式二:Docker
docker pull 01ai/yi:latest
方式三:llama.cpp(适合 CPU 推理)
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make
# 下载 GGUF 格式模型后使用
./main -m yi-34b-chat.gguf -p "你好"
模型托管在 Hugging Face 和 ModelScope(国内推荐):
| 模型 | 参数 | 下载地址 |
|---|---|---|
| Yi-6B-Chat | 6B | 01-ai/Yi-6B-Chat |
| Yi-34B-Chat | 34B | 01-ai/Yi-34B-Chat |
| Yi-6B | 6B (base) | 01-ai/Yi-6B |
| Yi-34B | 34B (base) | 01-ai/Yi-34B |
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "01-ai/Yi-6B-Chat" # 也可换为 Yi-34B-Chat
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
trust_remote_code=True
)
messages = [
{"role": "user", "content": "你好,请介绍一下你自己"}
]
input_ids = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt"
).to(model.device)
outputs = model.generate(
input_ids,
max_new_tokens=512,
do_sample=True,
temperature=0.7
)
response = tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=True)
print(response)
# 安装 gradio
pip install gradio
# 运行官方 Web demo
python web_demo.py --model 01-ai/Yi-6B-Chat
翻译整理自 GitHub README,原文:https://github.com/01-ai/Yi