语言:
- 中文
- 英文
标签:
- 通义千问
任务类型: 文本生成
推理支持: 否
通义千问-7B对话模型
通义千问-7B基础模型 🤖 | 🤗  | 通义千问-7B对话模型 🤖 | 🤗  |  演示平台  |  技术报告
模型介绍
**通义千问-7B(Qwen-7B)**是阿里云研发的70亿参数规模大语言模型。该模型基于Transformer架构,在海量多样化预训练数据(包括网络文本、专业书籍和代码等)上训练而成。基于Qwen-7B,我们通过对齐机制开发了AI助手Qwen-7B-Chat。本仓库为对话模型版本。
更多技术细节请参阅GitHub代码库。
Qwen-7B is the 7B-parameter version of Alibaba Cloud's large language model series. Pretrained on diverse data including web texts, books and codes, this Transformer-based model also has its aligned assistant version Qwen-7B-Chat in this repository.
For technical details, please refer to the GitHub repository.
系统要求
- Python 3.8及以上
- PyTorch 1.12及以上(推荐2.0+)
- 建议CUDA 11.4+(GPU用户需注意)
- Python 3.8+
- PyTorch 1.12+ (2.0+ recommended)
- CUDA 11.4+ recommended (for GPU users)
安装依赖
运行前请执行以下命令安装依赖库:
To run the model, please install dependencies via:
pip install transformers==4.31.0 accelerate tiktoken einops
推荐额外安装flash-attention
以提升效率:
For better efficiency, install flash-attention
:
git clone -b v1.0.8 https://github.com/Dao-AILab/flash-attention
cd flash-attention && pip install .
pip install csrc/layer_norm
pip install csrc/rotary
快速开始
以下是多轮对话示例:
Multi-turn interaction example:
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation import GenerationConfig
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B-Chat", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B-Chat", device_map="auto", trust_remote_code=True).eval()
model.generation_config = GenerationConfig.from_pretrained("Qwen/Qwen-7B-Chat", trust_remote_code=True)
response, history = model.chat(tokenizer, "你好", history=None)
print(response)
response, history = model.chat(tokenizer, "给我讲一个年轻人奋斗创业最终取得成功的故事。", history=history)
print(response)
response, history = model.chat(tokenizer, "给这个故事起一个标题", history=history)
print(response)
更多用法请参考GitHub仓库。
分词说明
基于tiktoken的分词器在微调时需要特别注意特殊token的使用。详见技术文档。
Our tiktoken-based tokenizer requires special attention during fine-tuning. See documentation.
模型架构
核心参数配置:
超参数 |
值 |
层数 |
32 |
注意力头数 |
32 |
模型维度 |
4096 |
词表大小 |
151851 |
序列长度 |
2048 |
关键技术:
- RoPE相对位置编码
- SwiGLU激活函数
- RMSNorm(可搭配flash-attention加速)
- 优化过的15万token词表,支持中英代码高效编码
- 数字按位切分
- 基于tiktoken的高效分词
性能评估
中文能力
C-Eval验证集
模型 |
平均准确率 |
Qwen-7B-Chat |
54.2 |
C-Eval测试集
模型 |
平均 |
理工 |
社科 |
人文 |
其他 |
Qwen-7B-Chat |
54.6 |
47.8 |
67.6 |
59.3 |
50.6 |
英文能力
MMLU
模型 |
平均准确率 |
Qwen-7B-Chat |
53.9 |
代码能力
HumanEval
模型 |
Pass@1 |
Qwen-7B-Chat |
24.4 |
数学能力
GSM8K
模型 |
零样本 |
四样本 |
Qwen-7B-Chat |
41.1 |
43.5 |
长文本理解
VCSUM
模型 |
中文长文摘要 |
Qwen-7B-Chat |
16.6 |
工具调用
ReAct提示
模型 |
工具选择 |
参数质量 |
误触发率 |
Qwen-7B-Chat |
99% |
0.89 |
9.7% |
HuggingFace Agent
模型 |
工具选择 |
工具使用 |
代码质量 |
Qwen-7B-Chat |
90.74 |
92.59 |
74.07 |
量化部署
支持4比特(NF4)和8比特(Int8)量化:
from transformers import BitsAndBytesConfig
quant_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type='nf4',
bnb_4bit_compute_dtype=torch.bfloat16
)
quant_config = BitsAndBytesConfig(load_in_8bit=True)
量化性能对比:
精度 |
MMLU |
显存占用 |
BF16 |
56.7 |
16.2G |
Int8 |
52.8 |
10.1G |
NF4 |
48.9 |
7.4G |
许可协议
代码和模型权重对学术研究和商业应用开放,详见LICENSE文件。
联系我们
欢迎发送邮件至qianwen_opensource@alibabacloud.com与我们交流。