5.2. HAMi
HAMi (Heterogeneous AI Computing Virtualization Middleware),原又称 k8s-vGPU-scheduler,是一个 “all-in-one” Chart,用于管理 k8s 集群中的异构 AI 计算设备。 它提供了共享异构 AI 设备的能力,并在任务之间提供资源隔离。
HAMi 致力于提高 Kubernetes 集群中异构计算设备的使用率,并为不同类型的异构设备提供统一的复用接口。 更多相关信息,参见 HAMi官方文档 。
5.2.1. 部署HAMi
备注
部署HAMi之前,请确保已安装可用的Kubernetes集群,且Kubernetes版本≥1.23。
部署的HAMi版本需≥2.6.0。
在线部署操作步骤参见通过 Helm 在线安装(推荐) 。 如果集群无法直接访问外部网络,可以使用离线部署,操作步骤参见离线安装 。
5.2.2. 使用sGPU
使用sGPU可以共享GPU设备资源:可以为任务分配一部分GPU,而不是完整的GPU。 sGPU支持以下参数以共享GPU,参数含义参见下表。
选项 |
类型 |
描述 |
|---|---|---|
|
integer/string |
sGPU数量。值不可大于节点GPU数量,该参数不可缺省 |
|
integer/string |
每张sGPU使用完整GPU的算力百分比。取值范围为1~100,缺省时表示使用GPU完整的算力 |
|
integer/string |
每张sGPU使用完整GPU的显存大小。默认单位为Gi,可指定单位为Mi或Gi,缺省时表示使用GPU完整的显存 |
用户还可以为任务配置调度策略以影响调度决策,HAMi支持的调度策略参见下表。
选项 |
类型 |
描述 |
|---|---|---|
|
string |
节点调度策略,可选 |
|
string |
GPU调度策略,可选 |
5.2.2.1. sGPU任务示例
用户可参考以下示例编写sGPU任务文件。 更多示例参见 sGPU示例 。
为任务分配算力与显存
apiVersion: v1 kind: Pod metadata: name: sample-pod spec: containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 1 # requesting 1 GPU metax-tech.com/vcore: 60 # requesting 60% compute of full GPU metax-tech.com/vmemory: 4 # requesting 4 GiB device memory of full GPU
为任务分配独占GPU
apiVersion: v1 kind: Pod metadata: name: sample-pod spec: containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 1 # requesting 1 exclusive GPU
为任务配置调度策略
apiVersion: v1 kind: Pod metadata: name: sample-pod annotations: hami.io/node-scheduler-policy: "binpack" # node policy is configured as "binpack" hami.io/gpu-scheduler-policy: "spread" # gpu policy is configured as "spread" spec: containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 1 # requesting 1 GPU metax-tech.com/vcore: 60 # requesting 60% compute of full GPU metax-tech.com/vmemory: 4 # requesting 4 GiB device memory of full GPU
将任务调度至满足特定sGPU调度策略的节点
apiVersion: v1 kind: Pod metadata: name: sample-pod spec: nodeSelector: metax-tech.com/gpu-device.qos-policy: "best-effort" # schedule Pod to the "best-effort" node containers: - name: ubuntu image: ubuntu:22.04 imagePullPolicy: IfNotPresent command: ['bash', '-c'] args: ["sleep infinity"] resources: limits: metax-tech.com/sgpu: 1 # requesting 1 GPU metax-tech.com/vcore: 60 # requesting 60% compute of full GPU metax-tech.com/vmemory: 4 # requesting 4 GiB device memory of full GPU
5.2.2.2. 提交sGPU任务
在Kubernetes管理节点执行以下命令提交任务。
kubectl create -f sample.yaml