基于节点池管理共享GPU能够为您提供更加灵活的GPU共享调度和显存隔离策略。本文通过创建两个含标签的节点池示例,介绍如何基于节点池管理共享GPU的调度能力和显存隔离能力。
前提条件
- 安装共享GPU组件。
- 规划节点池。
节点池名称可自定义,本文以cgpu和cgpu-no-isolation为例进行阐述。
节点池名称 共享调度 显存隔离 标签 cgpu 是 是 - cgpu=true
- cgpu.disable.isolation=false
cgpu-no-isolation 是 否 - cgpu=true
- cgpu.disable.isolation=true
背景信息
在阿里云容器服务Kubernetes版ACK(Container Service for Kubernetes)上使用GPU共享调度时,您可能会遇到以下场景:
- 训练任务A在代码中已经配置该任务可使用的GPU显存大小,此时集群只需要提供GPU共享调度能力即可,不需要提供GPU显存隔离能力。
- 训练任务B在代码中没有配置该任务可使用的GPU显存大小,此时集群不仅需要提供GPU共享调度能力,而且还需要提供GPU显存隔离能力。
那如何在一个集群中同时支持这两种场景呢?
基于节点池管理共享GPU的方法同时支持这两种场景。您只需要创建两个节点池:
- 第一个节点池的节点只提供共享调度能力,不提供显存隔离能力,该节点池只适用于运行训练任务A。
- 第二个节点池的节点同时提供共享调度能力和显存隔离能力,该节点池只适用于运行训练任务B。
注意事项
在使用节点池管理共享GPU的过程中,需要注意以下两点:
-
用节点池管理共享GPU时,如果某个任务没有写nodeSelector,那么该任务的Pod可能被调度到任意一个节点池,容易造成结果错乱。
注意 强烈建议给任务指定nodeSelector。 -
如果某个节点的特定标签发生变化(例如:cgpu.disable.isolation=false变为cgpu.disable.isolation=true),需要重启该节点的gpushare-device-plugin,显存隔离的配置才能生效。
重启策略是将旧的gpushare-device-plugin Pod删除后,ACK会自动创建一个新的Pod,具体操作如下:
- 查询集群的gpushare-device-plugin Pod。
输入命令如下:
kubectl get po -n kube-system -l name=gpushare-device-plugin-ds -o wide
系统输出结果如下:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES gpushare-device-plugin-ds-6r8gs 1/1 Running 0 18h 192.168.7.157 cn-shanghai.192.168.7.157 <none> <none> gpushare-device-plugin-ds-pjrvn 1/1 Running 0 15h 192.168.7.158 cn-shanghai.192.168.7.158 <none> <none>
- 以cn-shanghai.192.168.7.157节点为例,在删除其旧的gpushare-device-plugin Pod后,ACK会自动创建一个新的Pod。相关命令如下:
kubectl delete po gpushare-device-plugin-ds-6r8gs -n kube-system
- 查询集群的gpushare-device-plugin Pod。
步骤一:创建节点池
步骤二:提交任务
提交cgpu-test和cgpu-test-no-isolation两个任务,在部署任务的YAML文件中均需要指定nodeSelector。
-
cgpu-test:该任务的代码中没有设置可用的GPU显存大小,需要借助共享的显存隔离能力才能正常运行。示例YAML配置如下:
apiVersion: apps/v1beta1 kind: StatefulSet metadata: name: cgpu-test labels: app: cgpu-test spec: replicas: 1 serviceName: "cgpu-test" podManagementPolicy: "Parallel" selector: # define how the deployment finds the pods it manages. matchLabels: app: cgpu-test template: # define the pods specifications. metadata: labels: app: cgpu-test spec: nodeSelector: # 添加nodeSelector,选择节点池cgpu。 cgpu.disable.isolation: "false" containers: - name: cgpu-test image: registry.cn-shanghai.aliyuncs.com/tensorflow-samples/tensorflow-gpu-mem:10.0-runtime-centos7 command: - python3 - /app/main.py env: resources: limits: # 申请的显存单位为GiB,该容器申请了3 GiB显存。 aliyun.com/gpu-mem: 3
说明- nodeSelector:指定节点池为cgpu。
- cgpu.disable.isolation=false:表示将任务调度到节点池cgpu的节点上运行。
- aliyun.com/gpu-mem:设置GPU显存大小。
-
cgpu-test-no-isolation:该任务的代码中设置了每个GPU可用显存大小,不需要借助cgpu的显存隔离能力。示例YAML配置如下:
apiVersion: apps/v1beta1 kind: StatefulSet metadata: name: cgpu-test-no-isolation labels: app: cgpu-test-no-isolation spec: replicas: 1 serviceName: "cgpu-test-no-isolation" podManagementPolicy: "Parallel" selector: # define how the deployment finds the pods it manages matchLabels: app: cgpu-test-no-isolation template: # define the pods specifications metadata: labels: app: cgpu-test-no-isolation spec: nodeSelector: # 添加nodeSelector,选择节点池cgpu-no-isolation。 cgpu.disable.isolation: "true" containers: - name: cgpu-test-no-isolation image: cheyang/gpu-player:v2 resources: limits: # 申请了3 GiB显存。 aliyun.com/gpu-mem: 3
说明- nodeSelector:指定节点池为cgpu-no-isolation。
- cgpu.disable.isolation=true:表示将任务调度到节点池cgpu-no-isolation的节点上运行。
- aliyun.com/gpu-mem:设置GPU显存大小。
在文档使用中是否遇到以下问题
更多建议
匿名提交