朝阳网站关键词优化,网站建设网络营销文章,中国广东手机网站建设,盐山做网站价格《OpenShift / RHEL / DevSecOps 汇总目录》 说明#xff1a;本文已经在 OpenShift 4.18 OpenShift AI 2.19 的环境中验证 文章目录 什么是 ModelCar构建模型镜像在 OpenShift AI 使用模型镜像部署模型扩展速度对比 参考 什么是 ModelCar
KServe 典型的模型初始化方法是从 S…《OpenShift / RHEL / DevSecOps 汇总目录》 说明本文已经在 OpenShift 4.18 OpenShift AI 2.19 的环境中验证 文章目录 什么是 ModelCar构建模型镜像在 OpenShift AI 使用模型镜像部署模型扩展速度对比 参考 什么是 ModelCar
KServe 典型的模型初始化方法是从 S3 Bucket 获取模型。由于每次初始化都要下载模型文件这一过程对于小型模型来说是可行的但对于大型模型来说就成了性能瓶颈因为在自动扩展的过程中会大大延迟启动时间。
ModelCar 是 KServe 为应对这一问题的方案它具备以下突出优势
模型文件已放在容器镜像中当镜像在节点中已被缓存的时候可避免重复下载模型文件从而可显著减少模型启动的延迟。因为在节点上运行相同模型的 pod 将访问同一镜像无需在每个 pod 中下载模型数据因此可减少本地磁盘空间的使用。
构建模型镜像
创建下载模型的文件 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_idmodel_repo,local_dir/models,allow_patterns[*.safetensors, *.json, *.txt],
)
EOF创建构建镜像的文件 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 --frombase /models /modelsUSER 1001
EOF构建包含模型的镜像。
podman build . -t modelcar-example:latest --platform linux/amd64将镜像推送到 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 使用模型镜像
部署模型
按下图创建一个使用镜像作为源的 connection。 使用以上 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