Qwen3快速部署 Qwen3-0.6B、Qwen3-8B、Qwen3-14B,Think Deeper

0 Qwen3

今天,通义千问Qwen团队正式开源推出 Qwen3,这是 Qwen 系列大型语言模型的最新成员。最新的Qwen3系列模型具备双模推理能力(深入思考/快速响应)、支持119种语言及方言,并强化了Agent功能与代码执行能力,全面满足复杂问题处理与全球化应用需求。

Github: https://github.com/QwenLM/Qwen3

Blog:https://qwenlm.github.io/zh/blog/qwen3/

模型合集:https://www.modelscope.cn/collections/Qwen3-9743180bdc6b48
在这里插入图片描述

b站视频:https://www.bilibili.com/video/BV1spG1zEEYR

1 平台与环境安装

使用GPU平台: https://www.autodl.com/home

在这里插入图片描述
PyTorch / 2.3.0 / 3.12(ubuntu22.04) / 12.1

安装transformers、accelerate

source /etc/network_turbo

pip install transformers

pip install accelerate

1 模型下载

Qwen3 模型广场:https://bailian.console.aliyun.com/?tab=model#/model-market
在这里插入图片描述
通过魔塔社区下载模型:https://www.modelscope.cn/collections/Qwen3-9743180bdc6b48
在这里插入图片描述

选择一个模型Qwen3-0.6B:https://www.modelscope.cn/models/Qwen/Qwen3-0.6B/files
在这里插入图片描述

使用SDK下载下载:

开始前安装

source /etc/network_turbo

pip install modelscope
# source /etc/network_turbo
from modelscope import snapshot_download

# 指定模型的下载路径
cache_dir = '/root/autodl-tmp'
# 调用 snapshot_download 函数下载模型
model_dir = snapshot_download('Qwen/Qwen3-0.6B', cache_dir=cache_dir)
# model_dir = snapshot_download('Qwen/Qwen3-8B', cache_dir=cache_dir)
# model_dir = snapshot_download('Qwen/Qwen3-14B', cache_dir=cache_dir)

print(f"模型已下载到: {model_dir}")

或者:

modelscope download --model Qwen/Qwen3-0.6B

mv /root/.cache/modelscope/hub/models/Qwen/ /root/autodl-tmp/Qwen

2 模型测试

from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Qwen/Qwen3-0.6B"
# model_name = "Qwen/Qwen3-8B"
# model_name = "Qwen/Qwen3-14B"

# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)

# prepare the model input
prompt = "Give me a short introduction to large language models."
messages = [
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True,
    enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

# conduct text completion
generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=32768
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist() 

# the result will begin with thinking content in <think></think> tags, followed by the actual response
print(tokenizer.decode(output_ids, skip_special_tokens=True))

enable_thinking=True的结果
在这里插入图片描述
enable_thinking=False的结果
在这里插入图片描述

### 如何部署 Qwen2.5-3B-Instruct 模型 尽管当前提供的参考资料主要围绕 **Qwen2.5-VL-7B-Instruct** 的部署方法,但可以推测 **Qwen2.5-3B-Instruct** 的部署流程与其相似。以下是基于现有资料整理的通用部署方案: #### 1. 下载模型权重 为了高效获取模型权重,建议使用国内镜像站点 `https://hf-mirror.com` 进行下载[^3]。具体步骤如下: - 访问该网站并搜索目标模型名称(即 Qwen2.5-3B-Instruct)。 - 确认找到对应的版本后,按照提示完成权重文件的下载。 #### 2. 使用 vLLM 加速推理 vLLM 是一种高效的大型语言模型推理框架,适用于多种规模的语言模型。对于 Qwen2.5-3B-Instruct 的部署,可以通过以下方式集成 vLLM: - 安装 vLLM 库:访问官方 GitHub 仓库以获取最新安装说明[^1]。 - 准备配置文件:定义模型路径、硬件资源分配以及其他必要的参数设置。 ```bash pip install vllm ``` 随后加载模型并启动服务端口以便后续调用: ```python from vllm import LLM, SamplingParams model_path = "/path/to/Qwen2.5-3B-Instruct" llm = LLM(model=model_path) sampling_params = SamplingParams(temperature=0.8, top_p=0.95) prompts = ["请描述一下如何部署 Qwen2.5-3B-Instruct?"] outputs = llm.generate(prompts, sampling_params=sampling_params) for output in outputs: prompt = output.prompt generated_text = output.outputs[0].text print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") ``` 此脚本展示了基本的功能实现逻辑,实际应用中可能还需要调整超参来满足特定需求。 #### 3. 测试与优化 在完成上述两步之后,需对已部署的服务进行全面测试,验证其性能表现是否达到预期水平。如果发现任何瓶颈,则应考虑引入更多计算资源或者重新设计某些环节以提高效率[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

CSPhD-winston-杨帆

给我饭钱

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

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

打赏作者

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

抵扣说明:

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

余额充值