cd Baichuan-13B
python cli_demo.py
cd Baichuan-13B
streamlit run web_demo.py
Baichuan-13B/
├── LICENSE
├── README.md
├── README_EN.md
├── cli_demo.py
├── requirements.txt
├── web_demo.py
└── ...
python cli_demo.py
git clone https://github.com/baichuan-inc/Baichuan-13B.git
pip install -r requirements.txt
README.md
文件。以下是使用 Baichuan-13B 模型的示例代码:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation.utils import GenerationConfig
# 加载 tokenizer 和模型
tokenizer = AutoTokenizer.from_pretrained(baichuan-inc/Baichuan-13B-Chat, use_fast=False, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(baichuan-inc/Baichuan-13B-Chat, device_map=auto, torch_dtype=torch.float16, trust_remote_code=True)
# 设置生成配置
model.generation_config = GenerationConfig.from_pretrained(baichuan-inc/Baichuan-13B-Chat)
# 创建消息列表
messages = []
messages.append({role: user, content: 世界上第二高的山峰是哪座})
# 获取模型响应
response = model.chat(tokenizer, messages)
# 打印响应
print(response)
乔戈里峰。世界第二高峰———乔戈里峰西方登山者称其为k2峰,海拔高度是8611米,位于喀喇昆仑山脉的中巴边境上。
使用此文档可以快速上手 Baichuan-13B 项目,进行模型的调用和交互。