GPT中文GPT中文论坛社区AI工具软件大全 GPT.CC Claude Fable 5 · GPT-5.6 直连,不用连国际网 去看看 →
AI工具软件大全
首页 / 文章 / 百川智能 快速上手教程(GitHub README 中文整理)
📖 教程 · 6 分钟读完 · 2026-07-24

百川智能 快速上手教程(GitHub README 中文整理)

从 百川智能 官方 GitHub README 翻译整理的快速上手指南。

百川智能 Baichuan 2 快速上手

是什么

Baichuan 2 是百川智能推出的新一代开源大语言模型,使用 2.6 万亿 Tokens 的高质量语料训练而成。本次开源包含 7B13B 两个尺寸的 Base(基座)和 Chat(对话)版本,Chat 版本还提供了 4bits 量化版本,方便在资源有限的设备上运行。

所有版本对学术研究完全开放。开发者通过邮件申请并获得官方商用许可后,可免费商用

能干什么

Baichuan 2 在多个权威的中文、英文和多语言 benchmark 上取得了同尺寸最佳效果,覆盖以下领域:

以 7B Base 模型为例,在 C-Eval(5-shot)上得分 54.00,MMLU(5-shot)得分 54.16,均超越同尺寸的 LLaMA2-7B、ChatGLM2-6B 等模型。

怎么装

环境要求

安装依赖

pip install torch transformers sentencepiece accelerate

下载模型

模型托管在 Hugging Face 和 ModelScope 平台,国内用户推荐使用 ModelScope 镜像加速下载:

# 以 Baichuan2-7B-Chat 为例
from modelscope import snapshot_download
model_dir = snapshot_download('baichuan-inc/Baichuan2-7B-Chat')

怎么用第一个例子

以下是一个完整的对话推理示例,使用 Baichuan2-7B-Chat 模型:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation.utils import GenerationConfig

# 加载模型和分词器
tokenizer = AutoTokenizer.from_pretrained(
    "baichuan-inc/Baichuan2-7B-Chat", 
    trust_remote_code=True
)
model = AutoModelForCausalLM.from_pretrained(
    "baichuan-inc/Baichuan2-7B-Chat",
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)
model.generation_config = GenerationConfig.from_pretrained(
    "baichuan-inc/Baichuan2-7B-Chat"
)

# 开始对话
messages = []
messages.append({"role": "user", "content": "解释一下什么是大语言模型"})
response = model.chat(tokenizer, messages)
print(response)

如果显存有限,可以使用 4bits 量化版本:

model = AutoModelForCausalLM.from_pretrained(
    "baichuan-inc/Baichuan2-7B-Chat-4bits",
    device_map="auto",
    trust_remote_code=True
)

社区资源


翻译整理自 GitHub README,原文:https://github.com/baichuan-inc/Baichuan2

01

本文涉及的工具

02

相关阅读