Qwen1.5 是 Qwen2 的测试版,它是一款基于 Transformer 的仅解码器语言模型,在大规模数据上进行了预训练。与之前发布的 Qwen 相比,其改进包括:
trust_remote_code。Qwen1.5 是一个语言模型系列,包含不同规模的解码器语言模型。对于每种规模,我们都会发布基础语言模型和经过对齐的对话模型。该模型基于 Transformer 架构,采用 SwiGLU 激活函数、注意力 QKV 偏置、分组查询注意力(GQA)、滑动窗口注意力与全注意力混合等技术。此外,我们还改进了分词器,使其能够适配多种自然语言和代码。在测试版中,除 32B 模型外,暂未包含 GQA 以及滑动窗口注意力与全注意力的混合机制。
我们使用大规模数据对模型进行了预训练,并通过监督微调(SFT)和直接偏好优化(DPO)对模型进行了后训练。
Qwen1.5 的代码已集成到最新版的 Hugging Face Transformers 中,建议您安装 transformers>=4.37.0,否则可能会遇到以下错误:
KeyError: 'qwen2'这里提供了一个使用apply_chat_template的代码片段,向您展示如何加载分词器和模型以及如何生成内容。
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
import torch_npu
device = torch.device("npu:0") # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained(
"Qwen1.5-1.8B-Chat",
torch_dtype="auto"
).to(device)
tokenizer = AutoTokenizer.from_pretrained("Qwen1.5-1.8B-Chat")
prompt = "Give me a short introduction to large language model."
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)
generated_ids = model.generate(
model_inputs.input_ids,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]对于量化模型,我们建议您使用对应的 GPTQ、AWQ 和 GGUF 版本,即 Qwen1.5-1.8B-Chat-GPTQ-Int4、Qwen1.5-1.8B-Chat-GPTQ-Int8、Qwen1.5-1.8B-Chat-AWQ 和 Qwen1.5-1.8B-Chat-GGUF。
generation_config.json 中提供的超参数。如果您觉得我们的工作有帮助,欢迎引用我们的成果。
@article{qwen,
title={Qwen Technical Report},
author={Jinze Bai and Shuai Bai and Yunfei Chu and Zeyu Cui and Kai Dang and Xiaodong Deng and Yang Fan and Wenbin Ge and Yu Han and Fei Huang and Binyuan Hui and Luo Ji and Mei Li and Junyang Lin and Runji Lin and Dayiheng Liu and Gao Liu and Chengqiang Lu and Keming Lu and Jianxin Ma and Rui Men and Xingzhang Ren and Xuancheng Ren and Chuanqi Tan and Sinan Tan and Jianhong Tu and Peng Wang and Shijie Wang and Wei Wang and Shengguang Wu and Benfeng Xu and Jin Xu and An Yang and Hao Yang and Jian Yang and Shusheng Yang and Yang Yao and Bowen Yu and Hongyi Yuan and Zheng Yuan and Jianwei Zhang and Xingxuan Zhang and Yichang Zhang and Zhenru Zhang and Chang Zhou and Jingren Zhou and Xiaohuan Zhou and Tianhang Zhu},
journal={arXiv preprint arXiv:2309.16609},
year={2023}
}