CodeQwen1.5 是 Qwen1.5 的代码专用版本。它是一个基于变换器的仅解码器语言模型,预训练于大量代码数据之上。
CodeQwen1.5 基于 Qwen1.5,这是一个包含不同大小模型解码器语言模型的系列。它在 3 万亿代码记号数据上进行训练,并引入了群体查询注意力(GQA)以实现高效推理。
Qwen1.5 的代码已经集成到最新的 Hugging face 变换器中,我们建议您安装 transformers>=4.37.0,否则可能会遇到以下错误:
KeyError: 'qwen2'.此外,您需要安装 AutoAWQ 以支持 AWQ 功能。
以下提供了一个使用 apply_chat_template 的代码片段,向您展示如何加载分词器和模型以及如何生成内容。
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained(
"Qwen/CodeQwen1.5-7B-Chat-AWQ",
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/CodeQwen1.5-7B-Chat-AWQ")
prompt = "Write a quicksort algorithm in python."
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]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}
}由于您未提供需要翻译的英文文本,我无法为您执行翻译任务。如果您提供了英文文本,我会很乐意将它翻译成中文,并保留原始的 Markdown 格式。请您提供需要翻译的内容。