Qwen3.5-27B源码构建详解:从CANN环境配置到模型运行的完整流程

【免费下载链接】Qwen3.5-27B 【免费下载链接】Qwen3.5-27B 项目地址: https://ai.gitcode.com/hf_mirrors/vLLM_Ascend/Qwen3.5-27B

Qwen3.5-27B是Qwen系列最新的旗舰多模态模型,采用MoE(Mixture of Experts)架构,在保持极强模型能力的同时显著降低推理成本。本文将详细介绍从CANN环境配置到模型运行的完整流程,帮助新手用户快速掌握Qwen3.5-27B的源码构建方法。

一、Qwen3.5-27B核心特性解析

Qwen3.5-27B作为一款先进的多模态模型,具备以下核心特性:

  • 原生多模态能力:集成Vision Encoder与图文融合技术,实现图像与文本的深度交互
  • 混合注意力机制:Full Attention与Linear-Attention交替使用,平衡模型性能与计算效率
  • MTP多Token预测分支:提升生成任务的准确性和流畅度
  • 高性能MoE架构:采用专家路由与共享专家机制,优化资源利用率

该模型支持在Ascend A3硬件上运行,支持BF16精度、Tensor Parallel、Data Parallel等特性,最大模型长度可达256K,为长文本处理提供强大支持。

二、环境准备:从CANN安装到依赖配置

2.1 模型权重获取

Qwen3.5-27B(BF16版本)的模型权重可通过官方渠道获取。建议将模型权重下载至多节点共享目录,如/root/.cache/,以便多节点部署时共享使用。

2.2 两种安装方式选择

2.2.1 官方Docker镜像(推荐新手)

使用官方Docker镜像是最简便的部署方式,无需手动配置复杂依赖:

# 使用docker加载下载的镜像压缩包(以A3 arm为例)
docker load -i Vllm-ascend-Qwen3_5-A3-Ubuntu-v0.tar

# 定义环境变量
export IMAGE=vllm-ascend:qwen3_5-v0-a3
export NAME=vllm-ascend

# 运行容器
docker run --rm \
--name $NAME \
--net=host \
--shm-size=100g \
--device /dev/davinci0 \
--device /dev/davinci1 \
--device /dev/davinci2 \
--device /dev/davinci3 \
--device /dev/davinci4 \
--device /dev/davinci5 \
--device /dev/davinci6 \
--device /dev/davinci7 \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/Ascend/driver/tools/hccn_tool:/usr/local/Ascend/driver/tools/hccn_tool \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v /root/.cache:/root/.cache \
-it $IMAGE bash
2.2.2 源码构建(适合开发者)

如果需要进行二次开发或自定义配置,可以选择源码构建方式。首先确保环境中已成功安装CANN 8.5.0,然后执行以下步骤:

  1. 克隆并安装vllm:
git clone https://github.com/vllm-project/vllm.git
cd vllm
git checkout a75a5b54c7f76bc2e15d3025d6
git fetch origin pull/34521/head:pr-34521
git merge pr-34521
VLLM_TARGET_DEVICE=empty pip install -v .
  1. 安装vllm-ascend:
pip uninstall vllm-ascend -y
git clone https://github.com/vllm-project/vllm-ascend.git
cd vllm-ascend
git checkout c63b7a11888e9e1caeeff8
git fetch origin pull/6742/head:pr-6742
git merge pr-6742
pip install -v .
  1. 安装transformers:
git clone https://github.com/huggingface/transformers.git
cd transformers
git reset --hard fc9137225880a9d03f130634c20f9dbe36a7b8bf
pip install .

三、快速部署:单节点运行指南

3.1 A3系列单节点部署

在A3系列硬件上部署Qwen3.5-27B的步骤如下:

  1. 设置环境变量:
export PYTORCH_NPU_ALLOC_CONF="expandable_segments:True"
export HCCL_OP_EXPANSION_MODE="AIV"
export HCCL_BUFFSIZE=1024
export OMP_NUM_THREADS=1
export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libjemalloc.so.2:$LD_PRELOAD
export TASK_QUEUE_ENABLE=1
  1. 启动vllm服务:
vllm serve /root/.cache/modelscope/hub/models/vllm-ascend/Qwen3.5-27B/ \
    --served-model-name "qwen3.5" \
    --host 0.0.0.0 \
    --port 8010 \
    --data-parallel-size 1 \
    --tensor-parallel-size 4 \
    --max-model-len 5000 \
    --max-num-batched-tokens 16384 \
    --max-num-seqs 128 \
    --gpu-memory-utilization 0.94 \
    --trust-remote-code \
    --async-scheduling \
    --allowed-local-media-path / \
    --mm-processor-cache-gb 0 \
    --enforce-eager \
    --additional-config '{"enable_cpu_binding":true, "multistream_overlap_shared_expert": true}'

3.2 发送推理请求

服务启动后,可以通过curl命令发送推理请求:

文本推理请求:
curl http://localhost:8000/v1/completions \
  -H "Content-Type: application/json" \
  -d '{
        "prompt": "The future of AI is",
        "path": "/path/to/model/Qwen3.5-27B/",
        "max_tokens": 100,
        "temperature": 0
        }'

成功执行后,模型将返回如下响应:

Prompt: 'The future of AI is', Generated text: ' not just about building smarter machines, but about creating systems that can collaborate with humans in meaningful, ethical, and sustainable ways. As AI continues to evolve, it will increasingly shape how we live, work, and interact — and the decisions we make today will determine whether this future is one of shared prosperity or deepening inequality.'
多模态推理请求:
curl http://localhost:8000/v1/completions \
  -H "Content-Type: application/json" \
    -d '{
        "model": "qwen3.5",
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": [
                {"type": "image_url", "image_url": {"url": "https://modelscope.oss-cn-beijing.aliyuncs.com/resource/qwen.png"}},
                {"type": "text", "text": "What is the text in the illustrate?"}
            ]}
        ]
    }'

四、精度与性能评估方法

4.1 精度评估

Qwen3.5-27B提供两种精度评估方法:

  1. 使用AISBench:详细步骤请参阅官方文档中的使用AISBench进行精度评估

  2. 使用语言模型评估工具:目前该方法尚未经过测试,建议开发者参考相关工具文档进行尝试。

4.2 性能评估

性能评估同样可以通过AISBench或vLLM基准测试工具进行:

五、注意事项与声明

  1. 当前Qwen3.5-27B仍处于性能优化阶段,提供的是尝鲜体验版本。

  2. 代码仓中提到的数据集和模型仅作为示例,仅供非商业目的使用。使用时请遵守对应数据集和模型的License,如因使用数据集或模型而产生侵权纠纷,华为不承担任何责任。

  3. 如在使用过程中发现任何问题(包括但不限于功能问题、合规问题),请在代码仓提交issue,开发团队将及时审视并解答。

通过以上步骤,您可以顺利完成Qwen3.5-27B的源码构建与部署。无论是新手用户还是开发人员,都能根据自身需求选择合适的安装方式,快速体验这款强大的多模态模型。

【免费下载链接】Qwen3.5-27B 【免费下载链接】Qwen3.5-27B 项目地址: https://ai.gitcode.com/hf_mirrors/vLLM_Ascend/Qwen3.5-27B

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐