模型存储

Model Catalog 或 Model Registry 存储模型元数据和模型构件的位置。模型文件本身保留在推理服务可以访问的存储后端中。支持的存储后端包括:

  • S3 对象存储:Storage Initializer 在主容器启动前下载模型。
  • Persistent Volume Claim (PVC):Storage Initializer 从已挂载的持久卷加载模型。
  • OCI 容器:在 KServe 中也称为 modelcar;容器运行时使用镜像层和缓存高效加载模型。

注册模型版本时,将构件位置作为 Model URI 输入。有关在 UI 中管理的项目级 S3、URI 或 OCI 端点,请参阅使用连接。

选择存储后端

后端Model URI 示例凭据或访问配置
S3s3://models/Qwen2.5-0.5B-InstructS3 Connection,或 ServiceAccount 和 Secret
PVCpvc://model-pvc/models/Qwen2.5-0.5B-Instruct目标命名空间中可用的 PVC
OCIoci://registry.example.com/models/qwen:1.0注册表需要身份验证时使用 OCI Connection

将模型放入存储后,打开 AI Hub > Model Registry > Register Model 并输入 URI。然后,可以从 Model Registry 部署已注册的活动版本。目录条目也可以提供构件 URI,并可直接从 AI Hub > Model Catalog 部署。

使用 S3 对象存储

S3 通常用于模型存储。推理服务需要通过附加到 ServiceAccount 的 Secret,或通过在控制台中选择的 S3 Connection 获取端点和凭据。

身份验证配置

建议为每个项目创建单独的 ServiceAccount 和 Secret。以下示例展示 KServe S3 Secret 格式:

apiVersion: v1
stringData:
  AWS_ACCESS_KEY_ID: YOUR_ACCESS_KEY
  AWS_SECRET_ACCESS_KEY: YOUR_SECRET_KEY
kind: Secret
metadata:
  annotations:
    serving.kserve.io/s3-endpoint: your_s3_service_ip:your_s3_port
    serving.kserve.io/s3-usehttps: '0'
  name: s3-creds
  namespace: demo-space
type: Opaque
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: sa-models
  namespace: demo-space
secrets:
  - name: s3-creds
  1. 将 YOUR_ACCESS_KEY 和 YOUR_SECRET_KEY 替换为 S3 服务的凭据。2. 将 your_s3_service_ip:your_s3_port 替换为 S3 端点。3. 当端点使用 HTTPS 时,将 serving.kserve.io/s3-usehttps 设置为 "1"。4. 将 Secret 和 ServiceAccount 保留在推理服务运行所在的命名空间中。

部署 S3 支持的模型

以下是直接使用 KServe 的示例。在控制台中,建议将 storageUri 注册为模型构件 URI,并从 Model Registry 的活动版本创建服务。

kind: InferenceService
apiVersion: serving.kserve.io/v1beta1
metadata:
  annotations:
    serving.kserve.io/deploymentMode: Standard
  labels:
    aml.cpaas.io/runtime-type: vllm
  name: s3-demo
  namespace: demo-space
spec:
  predictor:
    maxReplicas: 1
    minReplicas: 1
    model:
      modelFormat:
        name: transformers
      protocolVersion: v2
      resources:
        limits:
          cpu: '2'
          ephemeral-storage: 10Gi
          memory: 8Gi
        requests:
          cpu: '2'
          memory: 4Gi
      runtime: aml-vllm-0.11.2-cpu
      storageUri: s3://models/Qwen2.5-0.5B-Instruct
    securityContext:
      seccompProfile:
        type: RuntimeDefault
    serviceAccountName: sa-models

将运行时替换为已安装的 ClusterServingRuntime。storageUri 必须指向 S3 bucket 中的模型目录,并且 ServiceAccount 必须能够读取 Secret。

使用 OCI 容器存储模型

你可以将模型打包为 OCI 镜像,并将其推送到 Harbor 或 Quay 等兼容 OCI 的注册表。对于离线安装,以及从具有节点侧镜像缓存的注册表快速启动,modelcar 存储非常有用。

将镜像引用记录为 Model URI,例如:

oci://registry.example.com/models/qwen:1.0

推理集群必须能够拉取该镜像。注册表为私有注册表时,请配置 OCI Connection。有关打包和部署步骤,请参阅使用 KServe Modelcar 存储模型。

使用 PVC 存储模型

将模型文件上传到 PVC

你可以从现有 PVC 提供模型服务。从已附加 PVC 的 Workbench 上传文件:

前提条件

  • 你可以访问 Alauda AI 监控面板和目标命名空间。
  • 你有一个正在运行的 Workbench 和一个 PVC。
  • Workbench 已附加到 PVC。
  • 模型文件位于本地计算机或 Workbench 中。

有关创建 Workbench 和附加 PVC 的信息,请参阅创建 Workbench。

操作步骤

  1. 在 Alauda AI 监控面板中,选择 Workbench。
  2. 找到正在运行的 Workbench,然后选择 Connect。
  3. 打开 IDE 文件浏览器。在 JupyterLab 中使用 Files;在 code-server 中使用 Explorer。
  4. 导航到已附加 PVC 的根目录,通常是 Workbench 主目录。在此处创建的文件会持久保存在 PVC 中。
  5. 为模型创建目录,例如 models/Qwen2.5-0.5B-Instruct。
  6. 上传模型文件。在 JupyterLab 中选择 Upload;在 code-server 中,将文件拖入目标目录。
  7. 确认模型文件显示在目标目录中。

Model URI 为:

pvc://<pvc-name>/models/Qwen2.5-0.5B-Instruct

将此 URI 注册为 Model Registry 版本的构件位置。PVC 和推理服务必须位于服务可以挂载该 claim 的命名空间中。

部署 PVC 支持的模型

kind: InferenceService
apiVersion: serving.kserve.io/v1beta1
metadata:
  annotations:
    serving.kserve.io/deploymentMode: Standard
  labels:
    aml.cpaas.io/runtime-type: vllm
  name: pvc-demo-1
  namespace: demo-space
spec:
  predictor:
    maxReplicas: 1
    minReplicas: 1
    model:
      modelFormat:
        name: transformers
      protocolVersion: v2
      resources:
        limits:
          cpu: '2'
          ephemeral-storage: 10Gi
          memory: 8Gi
        requests:
          cpu: '2'
          memory: 4Gi
      runtime: aml-vllm-0.11.2-cpu
      storageUri: pvc://model-pvc/models/Qwen2.5-0.5B-Instruct
    securityContext:
      seccompProfile:
        type: RuntimeDefault

将 model-pvc 和路径替换为包含模型的 PVC 和目录。

Model URI 要求

控制台会验证 Model URI 是否包含 scheme 以及非空的位置。以下形式在部署配置支持时有效:

  • s3://<bucket>/<path>
  • pvc://<pvc-name>/<optional-path>
  • oci://<registry>/<repository>:<tag>
  • 存储初始化器或服务运行时支持的其他已配置 URI scheme

诸如 /models/qwen 的本地路径或不带 scheme 的仓库名称不是完整的 Model URI。确认所选服务运行时支持该模型格式,并且运行时可以访问所引用的存储。