当前位置: 首页 > news >正文

OpenShift AI - 用 ModelCar 构建容器化模型,提升模型弹性扩展速度

《OpenShift / RHEL / DevSecOps 汇总目录》
说明:本文已经在 OpenShift 4.18 + OpenShift AI 2.19 的环境中验证

文章目录

  • 什么是 ModelCar
  • 构建模型镜像
  • 在 OpenShift AI 使用模型镜像
    • 部署模型
    • 扩展速度对比
  • 参考

什么是 ModelCar

KServe 典型的模型初始化方法是从 S3 Bucket 获取模型。由于每次初始化都要下载模型文件,这一过程对于小型模型来说是可行的,但对于大型模型来说就成了性能瓶颈,因为在自动扩展的过程中会大大延迟启动时间。

ModelCar 是 KServe 为应对这一问题的方案,它具备以下突出优势:

  • 模型文件已放在容器镜像中,当镜像在节点中已被缓存的时候,可避免重复下载模型文件,从而可显著减少模型启动的延迟。
  • 因为在节点上运行相同模型的 pod 将访问同一镜像,无需在每个 pod 中下载模型数据,因此可减少本地磁盘空间的使用。

构建模型镜像

  1. 创建下载模型的文件 download_model.py。
$ cat > download_model.py << EOF
from huggingface_hub import snapshot_download# Specify the Hugging Face repository containing the model
model_repo = "Qwen/Qwen2.5-0.5B-Instruct"
snapshot_download(repo_id=model_repo,local_dir="/models",allow_patterns=["*.safetensors", "*.json", "*.txt"],
)
EOF
  1. 创建构建镜像的文件 Containerfile。
$ cat > Containerfile << EOF
FROM registry.access.redhat.com/ubi9/python-311:latest as baseUSER rootRUN pip install huggingface-hub# Download the model file from hugging face
COPY download_model.py .RUN python download_model.py # Final image containing only the essential model files
FROM registry.access.redhat.com/ubi9/ubi-micro:9.4# Copy the model files from the base container
COPY --from=base /models /modelsUSER 1001
EOF
  1. 构建包含模型的镜像。
podman build . -t modelcar-example:latest --platform linux/amd64
  1. 将镜像推送到 Registry。
$ podman images localhost/modelcar-example
REPOSITORY                  TAG         IMAGE ID      CREATED         SIZE
localhost/modelcar-example  latest      ae4aac72bb2c  59 minutes ago  1.02 GB$ podman push localhost/modelcar-example quay.io/your-registry/modelcar-example:latest

在 OpenShift AI 使用模型镜像

部署模型

  1. 按下图创建一个使用镜像作为源的 connection。
    在这里插入图片描述
  2. 使用以上 connection 部署模型。将 Deployment mode 设为 Advanced,即使用 Serverless 运行模型;Number of model server replicas to deploy 设为 0,即初始运行副本数为零。
    在这里插入图片描述

扩展速度对比

结合《OpenShift AI - 在 OpenShift 和 OpenShift AI 上运行 LLM》中基于 S3 的模型部署模式,在同一环境中对 ModelCar 和 S3 方式运行的 ibm-granite/granite-3.2-2b-instruct 模型进行同时扩展。测试结果:

  • ModelCar 模式的扩展时间:1分12秒,明显快。
  • S3 模式的扩展时间:2分22秒。

参考

https://developers.redhat.com/articles/2025/01/30/build-and-deploy-modelcar-container-openshift-ai#modelcar_containers_pros_and_cons
https://github.com/redhat-ai-services/modelcar-catalog
https://opendatahub.io/docs/serving-models/
https://github.com/redhat-ai-services/modelcar-catalog/tree/main/modelcar-images/qwen2.5-0.5b-instruc

相关文章:

  • IP地址、端口、TCP介绍、socket介绍、程序中socket管理
  • Golang 设计哲学
  • 用Python代码绘制动态3D爱心效果
  • AI日报 · 2025年5月15日|GPT-4.1 登陆 ChatGPT
  • 实验-时序电路设计2-存储器阵列(数字逻辑)
  • 光谱相机的图像预处理技术
  • MYSQL基本命令
  • 70、微服务保姆教程(十三)Docker容器详细讲义
  • 人体肢体渲染-一步几个脚印从头设计数字生命——仙盟创梦IDE
  • 工业操作系统核心技术揭秘
  • Web GIS可视化地图框架Leaflet、OpenLayers、Mapbox、Cesium、ArcGis for JavaScript
  • 从基础到实习项目:C++后端开发学习指南
  • 数据结构 -- 顺序查找和折半查找
  • python的宫崎骏动漫电影网站管理系统
  • 【论信息系统项目的合同管理】
  • OpenResty Manager 介绍与部署(Docker部署)
  • 20250515让飞凌的OK3588-C的核心板在Linux R4下适配以太网RTL8211F-CG为4线百兆时的接线图
  • 微服务如何实现服务的高并发
  • JAVA单元测试、反射
  • 数据结构 -- 树形查找(一)二叉排序树
  • 贝壳一季度收入增长42%:二手房市场活跃度维持在高位
  • 中国—美国经贸合作对接交流会在华盛顿成功举行
  • 男子入户强奸高龄独居妇女致其死亡,法院:属实,已执行死刑
  • 西北大学副校长范代娣成陕西首富?系家庭财富,本人已从上市公司退出
  • 在对国宝的探索中,让美育浸润小学校园与家庭
  • 郑州通报“夜市摊贩收取香烟交给城管”:涉事人员停职调查