使用示例

训练任务支持cifar10和imagenet2012数据集。其中cifar10数据集已内置,imagenet2012数据集请下载数据集(使用该数据集需按照数据集提供者的使用规范使用),并进行物理机挂载操作。

获取任务yaml

获取任务yaml请参见yaml下载地址,根据实际情况选择对应的yaml。

表1 yaml文件

yaml名称

说明

infer-volcano.yaml

推理环境使用Volcano作为调度器

train_cifar_vcjob.yaml

训练环境使用cifar10数据集

train_imagenet_vcjob.yaml

训练环境使用imagenet2012数据集

挂载imagenet2012数据集

若使用imagenet2012数据集进行训练任务的下发,需要先上传数据集到当前环境上,再挂载imagenet2012数据集。

打开train_imagenet_vcjob.yaml,配置imagenet2012数据集的正确路径,该路径的目录及其子目录的属主、属组均为HwHiAiUser。
- name: data
  hostPath:
    path: "/data/imagenet"  # Configure the path of the training set.

下发训练任务

以训练任务train_cifar_vcjob.yaml或train_imagenet_vcjob.yaml为例。

  1. 上传yaml到当前环境的任意路径。
  2. 修改任务yaml。

    1. 修改镜像版本。
      请根据实际拉取的mindspore-modelzoo镜像名和版本,修改yaml中镜像名和版本,当前仅支持22.0.0及以上版本。
               containers:
               - image: ascendhub.huawei.com/public-ascendhub/mindspore-modelzoo:22.0.0         # Training framework image, which can be modified.
                 imagePullPolicy: IfNotPresent
                 name: mindspore
                 env:
                 - name: mindx-dls-test        # The value must be consistent with the value of JobName.
    2. 根据任务部署到的节点架构,修改对应的nodeSelector。
      • 如果任务部署到x86_64架构节点,nodeSelector修改为:host-arch: huawei-x86
                nodeSelector:
                   host-arch: huawei-x86 
      • 如果任务部署到aarch64架构节点,nodeSelector修改为:host-arch: huawei-arm
                nodeSelector:
                   host-arch: huawei-arm 
    3. 修改节点数量。默认支持在2个节点上进行集群训练,可通过修改yaml中minAvailable和replicas的值,自定义节点数量。
      spec:
         minAvailable: 2                       # The value of minAvailable is 1 in a single-node scenario and N in an N-node distributed scenario.
         schedulerName: volcano                # Use the Volcano scheduler to schedule jobs.
         policies:
           - event: PodEvicted
             action: RestartJob
         plugins:
           ssh: []
           env: []
           svc: []
         maxRetry: 3
         queue: default
         tasks:
         - name: "default-test"
           replicas: 2                
    4. 修改芯片数量。默认挂载Ascend910芯片且是满配8卡,可通过修改requests和limits的值,自定义芯片数量。requests和limits的值需保持一致。
      resources:
        requests:
          huawei.com/Ascend910: 8                 # Number of required NPUs. The maximum value is 8. You can add lines below to configure resources such as memory and CPU.
        limits:
          huawei.com/Ascend910: 8
    5. (可选)若需要配置CPU、Memory资源,请参见如下示例手动添加“cpu”“memory”参数和对应的参数值,具体数值请根据实际情况配置。
      ...
                resources:  
                  requests:
                    huawei.com/Ascend910: 8
                    cpu: 100m                # means 100 milliCPU.For example 100m CPU, 100 milliCPU, and 0.1 CPU are all the same
                    memory: 100Gi            # means 100*230 bytes of memory
                  limits:
                    huawei.com/Ascend910: 8
                    cpu: 100m
                    memory: 100Gi
      ...

  3. 下发任务yaml。

    • 执行以下命令,使用cifar10数据集进行训练。
      kubectl apply -f train_cifar_vcjob.yaml
    • 执行以下命令,使用imagenet2012数据集进行训练。
      kubectl apply -f train_imagenet_vcjob.yaml

  4. 查看训练结果。

    在管理节点执行如下命令。

    kubectl logs -n 命令空间名称 {pod名字}

    如:

    kubectl logs  -n vcjob mindx-dls-test-default-test-0
    若回显示例如下,则说明训练任务执行成功,组件部署成功。
    ...
    Train epoch time: 14614.743 ms, per step time: 2435.791 ms
    epoch: 83 step: 6, loss is 6.024412
    Train epoch time: 8068.264 ms, per step time: 1344.711 ms
    epoch: 84 step: 6, loss is 6.022005
    Train epoch time: 6966.450 ms, per step time: 1161.075 ms
    epoch: 85 step: 6, loss is 6.052724
    Train epoch time: 8519.337 ms, per step time: 1419.889 ms
    epoch: 86 step: 6, loss is 5.9838204

  5. (可选)删除训练任务。

    1. 执行以下命令,删除使用cifar10数据集的训练任务。
      kubectl delete -f train_cifar_vcjob.yaml
    2. 执行以下命令,删除使用imagenet2012数据集的训练任务。
      kubectl delete -f train_imagenet_vcjob.yaml
    回显示例如下,表示删除成功。
    configmap "rings-config-mindx-dls-test" deleted
    job.batch.volcano.sh "mindx-dls-test" deleted

下发推理任务

以推理任务infer-volcano.yaml为例。

  1. 上传yaml到当前环境的任意路径。
  2. 修改任务yaml。

    1. 修改镜像版本。
      请根据实际拉取的mindspore-modelzoo镜像名和版本,修改yaml中镜像名和版本,当前仅支持22.0.0及以上版本。
      containers:
               - image: ascendhub.huawei.com/public-ascendhub/mindspore-modelzoo:22.0.0               # Training framework image, which can be modified.
                 imagePullPolicy: IfNotPresent
                 name: mindspore
                 env:
                 - name: mindx-dls-test   
    2. 根据任务部署到的节点架构,修改对应的nodeSelector。
      • 如果任务部署到x86_64架构节点,nodeSelector修改为:host-arch: huawei-x86
                nodeSelector:
                   host-arch: huawei-x86 
      • 如果任务部署到aarch64架构节点,nodeSelector修改为:host-arch: huawei-arm
                nodeSelector:
                   host-arch: huawei-arm 
    3. 修改芯片类型和挂载数量。默认挂载Atlas 推理系列产品芯片,可通过修改requests和limits的值来修改芯片类型和挂载数量,最多支持挂载8卡。requests和limits的值需保持一致。
      resources:
        requests:
          huawei.com/Ascend310P: 1                 # Number of required NPUs. The maximum value is 8. You can add lines below to configure resources such as memory and CPU.
        limits:
          huawei.com/Ascend310P: 1
    4. (可选)若需要配置CPU、Memory资源,请参见如下示例手动添加“cpu”“memory”参数和对应的参数值,具体数值请根据实际情况配置。
      ...
                resources:  
                  requests:
                    huawei.com/Ascend310P: 1
                    cpu: 100m                # means 100 milliCPU.For example 100m CPU, 100 milliCPU, and 0.1 CPU are all the same
                    memory: 100Gi            # means 100*230 bytes of memory
                  limits:
                    huawei.com/Ascend310P: 1
                    cpu: 100m
                    memory: 100Gi
      ...

  3. 下发任务yaml。

    kubectl apply -f infer_vcjob.yaml

  4. 查看推理结果。

    在管理节点执行如下命令。
    kubectl logs -n 命令空间名称 {pod名字}

    如:

    kubectl logs -n vcjob mindx-dls-test-default-test-0
    若回显示例如下,则说明推理任务执行成功,组件部署成功。
    acl init success
    set device 0 success
    create context success
    create stream success
    get run mode success
    dvpp init resource success
    load model ../model/resnet50_aipp.om success
    create model description success
    create model output success
    model input width 224, input height 224
    init sigle op success
    start to process picture:../data/dog1_1024_683.jpg
    ...

  5. (可选)删除推理任务。

    kubectl delete -f infer_vcjob.yaml
    回显示例如下,表示删除成功。
    configmap "rings-config-mindx-dls-test" deleted
    job.batch.volcano.sh "mindx-dls-test" deleted