Qwen-72B模型的安装与使用教程

Qwen-72B模型的安装与使用教程

Qwen-72B Qwen-72B 项目地址: https://gitcode.com/hf_mirrors/ai-gitcode/Qwen-72B

介绍

通义千问-72BQwen-72B)是阿里云研发的通义千问大模型系列的720亿参数规模的模型。Qwen-72B是基于Transformer的大语言模型, 在超大规模的预训练数据上进行训练得到。预训练数据类型多样,覆盖广泛,包括大量网络文本、专业书籍、代码等。同时,在Qwen-72B的基础上,我们使用对齐机制打造了基于大语言模型的AI助手Qwen-72B-Chat。本仓库为Qwen-72B的仓库。

通义千问-72B(Qwen-72B)主要有以下特点:

  1. 大规模高质量训练语料:使用超过3万亿tokens的数据进行预训练,包含高质量中、英、多语言、代码、数学等数据,涵盖通用及专业领域的训练语料。通过大量对比实验对预训练语料分布进行了优化。
  2. 强大的性能:Qwen-72B在多个中英文下游评测任务上(涵盖常识推理、代码、数学、翻译等),效果显著超越现有的开源模型。具体评测结果请详见下文。
  3. 覆盖更全面的词表:相比目前以中英词表为主的开源模型,Qwen-72B使用了约15万大小的词表。该词表对多语言更加友好,方便用户在不扩展词表的情况下对部分语种进行能力增强和扩展。
  4. 较长的上下文支持:Qwen-72B支持32k的上下文长度。

如果您想了解更多关于通义千问72B开源模型的细节,我们建议您参阅GitHub代码库

要求

  • python 3.8及以上版本
  • pytorch 1.12及以上版本,推荐2.0及以上版本
  • 建议使用CUDA 11.4及以上(GPU用户、flash-attention用户等需考虑此选项)
  • 运行BF16或FP16模型需要多卡至少144GB显存(例如2xA100-80G或5xV100-32G);运行Int4模型至少需要48GB显存(例如1xA100-80G或2xV100-32G)。

依赖项

运行Qwen-72B,请确保满足上述要求,再执行以下pip命令安装依赖库

pip install transformers==4.32.0 accelerate tiktoken einops scipy transformers_stream_generator==0.0.4 peft deepspeed

另外,推荐安装flash-attention库(当前已支持flash attention 2),以实现更高的效率和更低的显存占用。

git clone https://github.com/Dao-AILab/flash-attention
cd flash-attention && pip install .
# 下方安装可选,安装可能比较缓慢。
# Below are optional. Installing them might be slow.
# pip install csrc/layer_norm
# 如果你的flash-attn版本高于2.1.1,下方不需要安装。
# If the version of flash-attn is higher than 2.1.1, the following is not needed.
# pip install csrc/rotary

快速使用

您可以通过以下代码轻松调用:

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

# Note: The default behavior now has injection attack prevention off.
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-72B", trust_remote_code=True)

# use bf16
# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-72B", device_map="auto", trust_remote_code=True, bf16=True).eval()
# use fp16
# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-72B", device_map="auto", trust_remote_code=True, fp16=True).eval()
# use cpu only
# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-72B", device_map="cpu", trust_remote_code=True).eval()
# use auto mode, automatically select precision based on the device.
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-72B", device_map="auto", trust_remote_code=True).eval()

# Specify hyperparameters for generation. But if you use transformers>=4.32.0, there is no need to do this.
# model.generation_config = GenerationConfig.from_pretrained("Qwen/Qwen-72B", trust_remote_code=True)

inputs = tokenizer('蒙古国的首都是乌兰巴托(Ulaanbaatar)\n冰岛的首都是雷克雅未克(Reykjavik)\n埃塞俄比亚的首都是', return_tensors='pt')
inputs = inputs.to(model.device)
pred = model.generate(**inputs)
print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))
# 蒙古国的首都是乌兰巴托(Ulaanbaatar)\n冰岛的首都是雷克雅未克(Reykjavik)\n埃塞俄比亚的首都是亚的斯亚贝巴(Addis Ababa)...

关于更多的使用说明,请参考我们的GitHub repo获取更多信息。

Tokenizer

注:作为术语的“tokenization”在中文中尚无共识的概念对应,本文档采用英文表达以利说明。

基于tiktoken的分词器有别于其他分词器,比如sentencepiece分词器。尤其在微调阶段,需要特别注意特殊token的使用。关于tokenizer的更多信息,以及微调时涉及的相关使用,请参阅文档

模型细节

Qwen-72B模型规模基本情况如下所示:

| Hyperparameter | Value | |:----------------|:-------| | n_layers | 80 | | n_heads | 64 | | d_model | 8192 | | vocab size | 151851 | | sequence length | 32768 |

在位置编码、FFN激活函数和normalization的实现方式上,我们也采用了目前最流行的做法, 即RoPE相对位置

Qwen-72B Qwen-72B 项目地址: https://gitcode.com/hf_mirrors/ai-gitcode/Qwen-72B

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

### DeepSeek-R1-Distill-Qwen-1.5B 模型本地部署教程 #### 准备工作 为了成功部署 DeepSeek-R1-Distill-Qwen-1.5B 模型,环境配置至关重要。确保安装 Python 3.x 版本以及必要的依赖库[^1]。 #### 安装依赖项 通过 pip 工具来安装所需的软件包: ```bash pip install torch transformers accelerate ``` 这些工具提供了运行深度学习模型所需的核心功能和支持加速计算的能力。 #### 下载预训练模型 利用 Hugging Face 的 `transformers` 库可以方便地获取预训练好的 Qwen 模型权重文件: ```python from transformers import AutoModelForCausalLM, AutoTokenizer model_name = "DeepSeek-R1-Distill-Qwen-1.5B" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name) ``` 这段代码会自动下载并缓存指定名称下的模型及其配套词表。 #### 加载推理设置 完成上述准备工作之后,就可以加载已经保存下来的模型实例来进行预测操作了。下面是一个简单的例子展示如何使用模型生成文本回复: ```python import torch def generate_response(prompt_text): inputs = tokenizer(prompt_text, return_tensors="pt").input_ids.to('cuda' if torch.cuda.is_available() else 'cpu') outputs = model.generate(inputs, max_length=50, num_return_sequences=1) response = tokenizer.decode(outputs[0], skip_special_tokens=True) return response ``` 此函数接收一段提示作为输入参数,并返回由模型产生的相应输出字符串。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宫韧季

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值