Qwen3.5-27B API调用指南:多模态请求与文本生成的实用示例
Qwen3.5-27B API调用指南:多模态请求与文本生成的实用示例
【免费下载链接】Qwen3.5-27B 项目地址: https://ai.gitcode.com/hf_mirrors/vLLM_Ascend/Qwen3.5-27B
Qwen3.5-27B是一款基于MoE架构的高性能多模态大模型,支持图文融合的原生多模态能力和高效文本生成。本指南将为您提供从环境准备到API调用的完整流程,帮助您快速上手这款强大的AI模型。
快速环境搭建:两种部署方案
官方Docker镜像一键启动
通过预构建的Docker镜像可以快速部署Qwen3.5-27B环境,特别适合新手用户:
# 加载镜像(以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
# 启动容器(需提前下载模型权重至/root/.cache)
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
源码构建完整指南
如果需要自定义配置或开发扩展功能,可以选择源码构建方式:
- 确保环境已安装CANN 8.5.0
- 从源码安装vllm-ascend:
# 升级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 .
# 升级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 .
# 重新安装transformers
git clone https://github.com/huggingface/transformers.git
cd transformers
git reset --hard fc9137225880a9d03f130634c20f9dbe36a7b8bf
pip install .
启动模型服务:单节点部署教程
在A3系列硬件上部署Qwen3.5-27B的步骤如下:
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
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}'
文本生成API调用:基础示例
使用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.'
多模态请求调用:图文结合示例
Qwen3.5-27B的强大之处在于其原生多模态能力,以下是发送图文混合请求的示例:
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?"}
]}
]
}'
模型将返回图片中的文本识别结果:
{"id":"chatcmpl-9dab99d55addd8c0","object":"chat.completion","created":1771060145,"model":"qwen3.5","choices":[{"index":0,"message":{"role":"assistant","content":"TONGYI Qwen","refusal":null,"annotations":null,"audio":null,"function_call":null,"tool_calls":[],"reasoning":null},"logprobs":null,"finish_reason":"stop","stop_reason":null,"token_ids":null}],"service_tier":null,"system_fingerprint":null,"usage":{"prompt_tokens":112,"total_tokens":119,"completion_tokens":7,"prompt_tokens_details":null},"prompt_logprobs":null,"prompt_token_ids":null,"kv_transfer_params":null}
模型性能与特性支持
Qwen3.5-27B在A3硬件上支持多种高级特性,包括:
- 混合注意力机制(Full Attention与Linear-Attention交替)
- MTP多Token预测分支
- 高性能MoE专家路由与共享专家机制
- 异步调度(Async Scheduling)
- 张量并行(Tensor Parallel)
- 数据并行(Data Parallel)
- 最大模型长度256K tokens
精度与性能评估方法
使用AISBench进行评估
AISBench是评估模型性能的推荐工具,详细步骤请参阅官方文档中的使用AISBench进行精度评估和使用AISBench进行性能评估部分。
vLLM基准测试工具
您也可以使用vLLM自带的基准测试工具,更多信息请参考vLLM基准测试文档。
总结与注意事项
Qwen3.5-27B作为一款高性能多模态大模型,为开发者提供了强大的API接口来实现文本生成和图文理解功能。在使用过程中,请注意:
- 当前版本仍在性能优化中,属于尝鲜体验阶段
- 模型权重需从官方渠道获取并遵守相应的License协议
- 多节点部署和PD分离功能目前尚未完全测试支持
通过本指南,您已经掌握了Qwen3.5-27B的API调用方法和基础部署流程。如需进一步了解模型特性和高级配置,请参考特性指南和官方文档。
【免费下载链接】Qwen3.5-27B 项目地址: https://ai.gitcode.com/hf_mirrors/vLLM_Ascend/Qwen3.5-27B
更多推荐
所有评论(0)