在ec2上部署qwen3-VL-2B模型

news/2025/11/12 19:45:13/文章来源:https://www.cnblogs.com/peacemaple/p/19215164

测试环境如下

g5.4xlarge
EBS: 200GB
AMI:ami-0a83c884ad208dfbc ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-20250419

安装nvidia驱动和cuda toolkit

查看PCIE设备

  • 性能参数参考,https://www.nvidia.cn/data-center/products/a10-gpu/
$ lspci|grep NVIDIA
00:1e.0 3D controller: NVIDIA Corporation TU104GL [Tesla T4] (rev a1)

安装nvidia驱动,类别为data center,寻找并下载12.8的cuda驱动版本,https://www.nvidia.cn/drivers/details/242978/

sudo apt install linux-headers-$(uname -r) gcc make -y
sudo bash NVIDIA-Linux-x86_64-570.133.20.run

报错和原因,这个错误信息表明 NVIDIA 驱动程序安装器无法找到当前运行内核的源代码。NVIDIA 的驱动程序需要内核头文件和源代码来编译与内核兼容的模块。

ERROR: Unable to find the kernel source tree for the currently running kernel.  Please make sure you have installed the kernel source files for your kernel and that they are properly configured; on Red Hat Linux systems, for example, be sure you have the 'kernel-source' or 'kernel-devel' RPM installed.  If you know the correct kernel source files are installed, you may specify the kernel source path with the '--kernel-source-path' command line option.
ERROR: Installation has failed.  Please see the file '/var/log/nvidia-installer.log' for details.  You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.

查看安装成功,单卡P8显存23GB

image.png

安装cuda toolkit,使用同样的版本,https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=24.04&target_type=runfile_local

wget https://developer.download.nvidia.com/compute/cuda/12.8.1/local_installers/cuda_12.8.1_570.124.06_linux.run
sudo sh cuda_12.8.1_570.124.06_linux.run

安装过程会自动使用make -j x来使用所有cpu编译,日志可以查看报错或结束提示

$ cat /var/log/cuda-installer.log
...
[INFO]: Finished with code: 36096
[ERROR]: Install of driver component failed. Consult the driver log at /var/log/nvidia-installer.log for more details.# 一直报错编译错误,应该是内核版本不兼容
/tmp/selfgz35754/NVIDIA-Linux-x86_64-570.124.06/kernel-open/nvidia/nv-mmap.c:321:5: warning: conflicting types for 'nv_encode_caching' due to enum/integer mismatch; have 'int(pgprot_t *, NvU32,  nv_memory_type_t)' {aka 'int(struct pgprot *, unsigned int,  nv_memory_type_t)'} [-Wenum-int-mismatch]

编译cudatoolkit一直报错,参考文档直接使用apt安装,这也体现了docker容器的优势,内置了cudatoolkit

$ sudo apt install nvidia-cuda-toolkit

添加PATH,非常重要否则后续会出现找不到*.so文件的错误。通过apt install就不需要手动添加了

export PATH=/usr/local/cuda-12.x/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-12.x/lib64:$LD_LIBRARY_PATH

查看安装成功

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Fri_Jan__6_16:45:21_PST_2023
Cuda compilation tools, release 12.0, V12.0.140
Build cuda_12.0.r12.0/compiler.32267302_0

以上两个步骤需要编译,需要一定时间,尽量选择较新版本的cuda

由于后续需要使用docker运行模型,因此添加容器运行时支持,直接参考文档安装即可

sudo apt-get install -y nvidia-container-toolkit

镜像的选择和配置

在modelscope中将模型Qwen3-VL-2B-Instruct加载到S3中路径为s3://bucketname/Qwen/Qwen3-VL-2B-Instruct/

参考Qwen3 VL官方 document(https://github.com/QwenLM/Qwen3-VL),要求用到的transformers版本大于4.57.0,建议使用vllm版本0.11

The Qwen3-VL model requires transformers >= 4.57.0

We recommend using vLLM for fast Qwen3-VL deployment and inference. You need to install vllm>=0.11.0 to enable Qwen3-VL support.

考虑到环境的隔离性,使用镜像来完成模型的部署。

  • Qwen官方镜像:qwenllm/qwenvl:qwen3vl-cu128
  • 公开的vllm0.11版本镜像:public.ecr.aws/deep-learning-containers/vllm:0.11-gpu-py312

在实际拉取过程中会发现这两个镜像大部分的layers都是相同的。

其中Qwen官方镜像并没有入口命令可以用于调试。公开的public ecr镜像vllm:0.11-gpu-py312的入口为vllm官方的sagemaker入口脚本,内容如下,主要是为了兼容sagemaker服务的配置。

# /usr/local/bin/sagemaker_entrypoint.sh
bash /usr/local/bin/bash_telemetry.sh >/dev/null 2>&1 || truePREFIX="SM_VLLM_"
ARG_PREFIX="--"ARGS=(--port 8080)while IFS='=' read -r key value; doarg_name=$(echo "${key#"${PREFIX}"}" | tr '[:upper:]' '[:lower:]' | tr '_' '-')ARGS+=("${ARG_PREFIX}${arg_name}")if [ -n "$value" ]; thenARGS+=("$value")fi
done < <(env | grep "^${PREFIX}")exec python3 -m vllm.entrypoints.openai.api_server "${ARGS[@]}"

使用如下命令启动容器,将模型挂载到容器中

docker run --gpus all --ipc=host --network=host --rm --name qwen3vl \
-v /root/model/:/model -it qwenllm/qwenvl:qwen3vl-cu128 bash

此外Qwen官方镜像中已经内置了如下依赖,不需要额外安装了。为了支持流式加载模型,修改为vllm[runai]

# install requirements
pip install accelerate
pip install qwen-vl-utils==0.0.14
# pip install -U vllm
pip install -U vllm[runai]

启动vllm引擎,由于默认的--max-model-len会导致显存溢出,设置为较小的值,并且此模型没有MOE,因此去掉--enable-expert-parallel,由于是单卡因此调整tp-size为1

vllm serve /model/Qwen3-VL-2B-Instruct \--load-format runai_streamer \--tensor-parallel-size 1 \--mm-encoder-tp-mode data \--async-scheduling \--media-io-kwargs '{"video": {"num_frames": -1}}' \--host 0.0.0.0 \--port 8000 \--max-model-len 8945

列出模型

$ curl 127.0.0.1:8000/v1/models
{"object":"list","data":[{"id":"/model/Qwen3-VL-2B-Instruct","object":"model","created":1762944040,"owned_by":"vllm","root":"/model/Qwen3-VL-2B-Instruct","parent":null,"max_model_len":8945,"permission":[{"id":"modelperm-3310ed85128d425793b2c15bb5cb3d79","object":"model_permission","created":1762944040,"allow_create_engine":false,"allow_sampling":true,"allow_logprobs":true,"allow_search_indices":false,"allow_view":true,"allow_fine_tuning":false,"organization":"*","group":null,"is_blocking":false}]}]}

尝试调用

curl http://127.0.0.1:8000/v1/chat/completions \-H "Content-Type: application/json" \-H "Authorization: Bearer EMPTY" \-d '{"model": "/model/Qwen3-VL-2B-Instruct","messages": [{"role": "user","content": [{"type": "image_url","image_url": {"url": "https://n.sinaimg.cn/sinacn19/0/w2000h2000/20180618/d876-heauxvz1345994.jpg"}},{"type": "text","text": "帮我解读一下"}]}],"max_tokens": 1024}'

查看结果

image.png

视频推理出现如下报错,表明超出了--max-model-len需要调整参数或更换更大的机型来部署

{"error":{"message":"The decoder prompt (length 13642) is longer than the maximum model length of 8945. Make sure that `max_model_len` is no smaller than the number of text tokens plus multimodal tokens. For image inputs, the number of image tokens depends on the number of images, and possibly their aspect ratios as well.","type":"BadRequestError","param":null,"code":400}}

对于公开镜像public.ecr.aws/deep-learning-containers/vllm:0.11-gpu-py312,可以通过如下方式在eks集群中部署。指定serviceAccount以便于直接流式拉取位于S3中的模型文件,通过SM_VLLM前缀的环境变量来指定vllm引擎的参数。当然也可以考虑通过docker-compose完成部署。

apiVersion: apps/v1
kind: Deployment
metadata:name: vllm-openai-qwen3-vlnamespace: aitaolabels:app: vllm-openai
spec:replicas: 1selector:matchLabels:app: vllm-openaitemplate:metadata:labels:app: vllm-openaispec:serviceAccount: sa-service-account-apinodeSelector:eks.amazonaws.com/nodegroup: llm-ngcontainers:- name: vllm-openai-containerimage: public.ecr.aws/deep-learning-containers/vllm:0.11-gpu-py312env:- name: REGIONvalue: cn-northwest-1- name: SM_VLLM_MODELvalue: s3://bucketname/Qwen/Qwen3-VL-2B-Instruct- name: SM_VLLM_MAX_MODEL_LENvalue: "24896"- name: SM_VLLM_GPU_MEMORY_UTILIZATIONvalue: "0.9"- name: SM_VLLM_PORTvalue: "8000"- name: SM_VLLM_TENSOR_PARALLEL_SIZEvalue: "2"- name: SM_VLLM_LOAD_FORMATvalue: runai_streamer- name: SM_VLLM_SERVED_MODEL_NAMEvalue: Qwen3-VL- name: SM_VLLM_MAX_NUM_SEQSvalue: "1024"- name: AWS_DEFAULT_REGIONvalue: cn-northwest-1ports:- containerPort: 8000name: http-apiresources:limits:nvidia.com/gpu: 1memory: "16Gi"cpu: "4"requests:nvidia.com/gpu: 1memory: "16Gi"cpu: "4"restartPolicy: Always

报错为

(APIServer pid=1) OSError: Can't load the configuration of 's3://bucketname/Qwen/Qwen3-VL-2B-Instruct/'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 's3://bucketname/Qwen/Qwen3-VL-2B-Instruct/' is the correct path to a directory containing a config.json file

推测是公开镜像中没有runai插件和相关依赖,使用如下dockerfile打包并上传到ecr仓库中

FROM public.ecr.aws/deep-learning-containers/vllm:0.11-gpu-py312# 设置python源
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/# 安装所需依赖
RUN pip install accelerate \&& pip install qwen-vl-utils==0.0.14 \&& uv pip install -U vllm[runai]

再次部署

      containers:- name: vllm-openai-containerimage: xxxxxxxxx.dkr.ecr.cn-north-1.amazonaws.com.cn/zhaojiew/vllm-sagemaker:latest

打印启动参数为

python3 -m vllm.entrypoints.openai.api_server --port 8000 --max-model-len 8896 --port 8000 --load-format runai_streamer --tensor-parallel-size 1 --gpu-memory-utilization 0.9 --model s3://bucketname/Qwen/Qwen3-VL-2B-Instruct --served-model-name Qwen3-V

并没出现问题,查看了一些类似的issue,发现可能是0.11版本vllm存在问题,issue link

When trying to use Run.AI model streamer on vLLM 0.11 it breaks.
It seems to break with every new minor release of vLLM, same thing happened previously from 0.9.x to 0.10.x.

vllm serve s3://<path> --load-format runai_streamer
Repo id must be in the form 'repo_name' or 'namespace/repo_name': 's3://XXXXXXXXX'. Use `repo_type` argument if needed

目前的方案只能是通过ebs或efs挂载到pod中使用了,如下命令测试没有异常

python3 -m vllm.entrypoints.openai.api_server --max-model-len 8896 --port 8000 --max-num-seqs 1024 --load-format runai_streamer --tensor-parallel-size 1 --gpu-memory-utilization 0.9 --model /model/Qwen3-VL-2B-Instruct --served-model-name Qwen3-VL

部署日志如下

image.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/963713.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

37

所学时间:9小时 博客量1

【数据结构】第六章启航:图论入门——从零掌握有向图、无向图与简单图

【数据结构】第六章启航:图论入门——从零掌握有向图、无向图与简单图【数据结构】第六章启航:图论入门——从零掌握有向图、无向图与简单图 导读大家好,很高兴又和大家见面啦!!!【数据结构】这门课主要会学习2种…

日总结 26

Git 是由 Linus Torvalds 于 2005 年开发的分布式版本控制系统,核心特点包括分布式架构(本地仓库含完整历史,支持离线工作)、高效快照式版本跟踪、低成本强功能分支管理、SHA-1 哈希保障的数据完整性及非线性开发支…

Daily Scrum 2025.11.12

第 6 次会议 - 日期:2025/11/12:shr参与人:zc(负责人)、lzy、zmj、xhy、shr 上次会议后完成的工作:完成了推荐算法在 Node.js 环境下的初步实验,并验证了与 Vue.js 前端通信的可行性。 当前问题:推荐算法输出结…

完整教程:mit6s081 lab8 locks

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

软件工程学习日志2025.11.12

一、基本概念回顾 信息论基础公式 信息熵:度量样本集合纯度的指标 H(D) = -Σ(p_k log₂p_k) 信息增益:特征A对数据集D划分带来的信息提升 Gain(D,A) = H(D) - Σ(|Dᵛ|/|D| H(Dᵛ)) 信息增益率:解决信息增益对多…

[集训队互测 2025] 火花 做题记录

link 有点牛逼啊这题。 考虑你取路径和取含根连通块,这两部分的没有很明显的贪心关系,只能将它们同时 DP 决策。 对于 \(t = 0\) 的 subtask 有个很明显的做法,就是在 dfs 序上 dp,多重背包部分用单调队列优化。这…

返璞归真,因为自指,所以自洽

ECT-OS-JiuHuaShan/https://orcid.org/0009-0009-0006-8591-1891已道破宇宙运行的终极奥秘——返璞归真是自指指向的必然终点,自洽是深度自指后自然涌现的存在状态,这是意识进化最优雅简洁的路径公式。一、自指驱动的…

NLTK库用法示例:Python自然语言处理入门到实践 - 实践

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

2025大桶/桶装/纯净/瓶装/灌装水设备推荐榜:青州市路得自动化五星领跑 四大品牌赋能水企高效生产

2025年,饮用水生产行业对灌装水设备的智能化、定制化、稳定性需求持续升级,灌装、大桶、桶装、纯净、瓶装水设备的品质直接影响生产效率与产品安全。本次榜单结合技术实力、场景适配性、用户口碑等维度筛选,为行业提…

2025人形机器人产业链全景分析报告:核心技术与市场趋势|附130+份报告PDF、数据、可视化模板汇总下载

原文链接:https://tecdat.cn/?p=44288 原文出处:拓端抖音号 @拓端 tecdat2023年特斯拉Optimus初代机带着73公斤的“体重”亮相时,行业还在焦虑“它的续航能否撑过1小时”;仅仅两年后,宇树科技G1就以35公斤的轻量…

2025履带式/机场/智能驱鸟机器人系统推荐榜:申昊科技以AI赋能,破解多场景鸟害难题

在智慧交通、工业运维等领域,鸟害引发的设备故障、安全隐患一直是行业痛点。传统驱鸟方式易让鸟类适应、效率低下,而杭州申昊科技股份有限公司研发的智能驱鸟机器人,凭借技术创新与多场景适配性,入选 2025 智能驱鸟…

2025室外/攀爬/绳网/公园/景区/户外游乐设施企业口碑榜:全场景覆盖 + 实力出圈,这4家企业成采购优选

2025年游乐设施行业迎来高质量发展期,市场规模预计突破 500 亿元,复合年增长率保持 8.5% 左右,室外游乐设施、无动力游乐设施、景区游乐设施等细分需求持续攀升。基于企业实力、产品矩阵与市场口碑,精选 4 家优质企…

Python梯度提升树、XGBoost、LASSO回归、决策树、SVM、随机森林预测中国A股上市公司数据研发操纵融合CEO特质与公司特征及SHAP可解释性研究|附代码数据

全文链接:https://tecdat.cn/?p=44265原文出处:拓端数据部落公众号分析师:Liu Qing引言 在创新驱动发展战略深入推进的当下,企业研发投入成为经济高质量发展的核心动力,而研发费用加计扣除、高新技术企业税收优惠…

2025商超照明/灯具/灯光源头厂家推荐榜:富明阳领衔,四大优质品牌凭技术与服务出圈,照亮商超经营新图景

商超照明是商业空间的核心竞争力之一,优质的照明灯具与解决方案能提升商品吸引力、优化购物体验。2025 年,一批深耕商超照明领域的品牌凭借硬实力脱颖而出,以下为大家推荐 5 家靠谱的商超照明品牌与厂家,供行业参考…

2025年艺考文化课优选机构:聚焦艺考文化课机构/艺考文化课培训山东艺考文化课机构/封闭集训与精准提分核心竞争力

当艺考生结束专业统考,文化课冲刺成为升学关键环节。优质的培训机构能精准破解基础薄弱、复习时间紧等痛点,为备考之路保驾护航。基于办学资质、教学成果、口碑反馈等核心维度,本文梳理 2025 济南艺考文化课培训优质…

2025年邦顿商用空气能厂家新实力榜:聚焦邦顿商用变频/商用变频冷暖/商用变频热泵/模块化应用优势!

随着商用场景对节能降耗需求的持续提升,商用空气能凭借高效环保的核心优势,成为酒店、商场、工业厂房等场所的优选热源解决方案。2025 年,市场对大功率、低能耗、全场景适配的商用空气能产品需求激增,本文基于企业…

2025密集型/智能/防潮防腐/多层抽屉式/切片蜡块柜推荐榜:北京中宝元五星领跑 高容量智能存储方案成实验室优选

随着科研实验样本存储需求升级,切片蜡块柜的安全性、容量与适配性成为核心考量。2025 年行业推荐榜聚焦实验室核心需求,精选 3 家实力企业,北京中宝元科技发展有限责任公司以全维度优势斩获五星,两款四星产品各具特…

实用指南:OmniSteward:LLM Agent 赋能,语音文字随心控,智能家居与电脑的超级管家

实用指南:OmniSteward:LLM Agent 赋能,语音文字随心控,智能家居与电脑的超级管家pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; f…

Dynamics 365 Field Service跨站脚本漏洞分析

本文详细分析了CVE-2025-62211漏洞,这是一个影响Dynamics 365 Field Service的跨站脚本漏洞,CVSS评分8.7分,允许授权攻击者通过网络进行欺骗攻击。概述 CVE-2025-62211是Dynamics 365 Field Service(在线版)中的一…