Skip to main content
NetApp Solutions
本繁體中文版使用機器翻譯,譯文僅供參考,若與英文版本牴觸,應以英文版本為準。

執行單節點AI工作負載

貢獻者

若要在Kubernetes叢集中執行單節點AI和ML工作、請從部署跳接主機執行下列工作。有了Trident、您就能快速輕鬆地建立資料磁碟區、讓Kubernetes工作負載能夠存取可能含有PB資料的資料。若要從Kubernetes Pod中存取此類資料磁碟區、只需在Pod定義中指定一個PVc即可。此步驟為Kubernetes原生作業、不需要NetApp專業人員。

註 本節假設您已將您嘗試在Kubernetes叢集中執行的特定AI和ML工作負載(採用Docker容器格式)容器化。
  1. 下列命令範例顯示使用ImageNet資料集的TensorFlow基準測試工作負載建立Kubernetes工作。如需ImageNet資料集的詳細資訊、請參閱 "ImageNet網站"

    此範例工作要求八個GPU、因此可在單一GPU工作節點上執行、該工作節點具備八個或更多GPU。此範例工作可在叢集中提交、而具有八個以上GPU的工作節點不存在、或目前正與其他工作負載一起使用。如果是、則工作會維持在擱置狀態、直到該工作者節點可供使用為止。

    此外、為了將儲存頻寬最大化、包含所需訓練資料的磁碟區會在本工作所建立的Pod內掛載兩次。另外一個Volume也會掛載在Pod中。第二個磁碟區將用於儲存結果和指標。這些磁碟區會使用PVCS名稱在工作定義中參考。如需Kubernetes工作的詳細資訊、請參閱 "Kubernetes官方文件"

    此範例所建立的Pod中、會將「medium」值為「mory」的「emtyDir"磁碟區掛載到「開發/ shm」。Docker Container執行時間所自動建立的「/dev/shm」虛擬磁碟區的預設大小、有時可能不足以滿足TensorFlow的需求。如以下範例所示、掛載「empyDir"磁碟區可提供足夠大的「/dev/shm」虛擬磁碟區。如需有關「empyDir" Volume的詳細資訊、請參閱 "Kubernetes官方文件"

    在此範例工作定義中所指定的單一容器、其「優先」值為「true」。此值表示容器有效擁有主機的root存取權。在這種情況下會使用此註釋、因為執行的特定工作負載需要root存取權。具體而言、工作負載執行的清除快取作業需要root存取權。是否需要這種「特殊權限:真」註解、取決於您執行的特定工作負載需求。

    $ cat << EOF > ./netapp-tensorflow-single-imagenet.yaml
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: netapp-tensorflow-single-imagenet
    spec:
      backoffLimit: 5
      template:
        spec:
          volumes:
          - name: dshm
            emptyDir:
              medium: Memory
          - name: testdata-iface1
            persistentVolumeClaim:
              claimName: pb-fg-all-iface1
          - name: testdata-iface2
            persistentVolumeClaim:
              claimName: pb-fg-all-iface2
          - name: results
            persistentVolumeClaim:
              claimName: tensorflow-results
          containers:
          - name: netapp-tensorflow-py2
            image: netapp/tensorflow-py2:19.03.0
            command: ["python", "/netapp/scripts/run.py", "--dataset_dir=/mnt/mount_0/dataset/imagenet", "--dgx_version=dgx1", "--num_devices=8"]
            resources:
              limits:
                nvidia.com/gpu: 8
            volumeMounts:
            - mountPath: /dev/shm
              name: dshm
            - mountPath: /mnt/mount_0
              name: testdata-iface1
            - mountPath: /mnt/mount_1
              name: testdata-iface2
            - mountPath: /tmp
              name: results
            securityContext:
              privileged: true
          restartPolicy: Never
    EOF
    $ kubectl create -f ./netapp-tensorflow-single-imagenet.yaml
    job.batch/netapp-tensorflow-single-imagenet created
    $ kubectl get jobs
    NAME                                       COMPLETIONS   DURATION   AGE
    netapp-tensorflow-single-imagenet          0/1           24s        24s
  2. 確認您在步驟1中建立的工作正在正確執行。下列範例命令可確認已為工作建立單一Pod(如工作定義所指定)、而且此Pod目前正在其中一個GPU工作節點上執行。

    $ kubectl get pods -o wide
    NAME                                             READY   STATUS      RESTARTS   AGE
    IP              NODE            NOMINATED NODE
    netapp-tensorflow-single-imagenet-m7x92          1/1     Running     0          3m    10.233.68.61    10.61.218.154   <none>
  3. 確認您在步驟1中建立的工作已成功完成。下列命令範例可確認工作已成功完成。

    $ kubectl get jobs
    NAME                                             COMPLETIONS   DURATION   AGE
    netapp-tensorflow-single-imagenet                1/1           5m42s      10m
    $ kubectl get pods
    NAME                                                   READY   STATUS      RESTARTS   AGE
    netapp-tensorflow-single-imagenet-m7x92                0/1     Completed   0          11m
    $ kubectl logs netapp-tensorflow-single-imagenet-m7x92
    [netapp-tensorflow-single-imagenet-m7x92:00008] PMIX ERROR: NO-PERMISSIONS in file gds_dstore.c at line 702
    [netapp-tensorflow-single-imagenet-m7x92:00008] PMIX ERROR: NO-PERMISSIONS in file gds_dstore.c at line 711
    Total images/sec = 6530.59125
    ================ Clean Cache !!! ==================
    mpirun -allow-run-as-root -np 1 -H localhost:1 bash -c 'sync; echo 1 > /proc/sys/vm/drop_caches'
    =========================================
    mpirun -allow-run-as-root -np 8 -H localhost:8 -bind-to none -map-by slot -x NCCL_DEBUG=INFO -x LD_LIBRARY_PATH -x PATH python /netapp/tensorflow/benchmarks_190205/scripts/tf_cnn_benchmarks/tf_cnn_benchmarks.py --model=resnet50 --batch_size=256 --device=gpu --force_gpu_compatible=True --num_intra_threads=1 --num_inter_threads=48 --variable_update=horovod --batch_group_size=20 --num_batches=500 --nodistortions --num_gpus=1 --data_format=NCHW --use_fp16=True --use_tf_layers=False --data_name=imagenet --use_datasets=True --data_dir=/mnt/mount_0/dataset/imagenet --datasets_parallel_interleave_cycle_length=10 --datasets_sloppy_parallel_interleave=False --num_mounts=2 --mount_prefix=/mnt/mount_%d --datasets_prefetch_buffer_size=2000 --datasets_use_prefetch=True --datasets_num_private_threads=4 --horovod_device=gpu > /tmp/20190814_105450_tensorflow_horovod_rdma_resnet50_gpu_8_256_b500_imagenet_nodistort_fp16_r10_m2_nockpt.txt 2>&1
  4. *選用:*清除工作成品。下列命令範例顯示刪除在步驟1中建立的工作物件。

    刪除工作物件時、Kubernetes會自動刪除任何相關的Pod。

    $ kubectl get jobs
    NAME                                             COMPLETIONS   DURATION   AGE
    netapp-tensorflow-single-imagenet                1/1           5m42s      10m
    $ kubectl get pods
    NAME                                                   READY   STATUS      RESTARTS   AGE
    netapp-tensorflow-single-imagenet-m7x92                0/1     Completed   0          11m
    $ kubectl delete job netapp-tensorflow-single-imagenet
    job.batch "netapp-tensorflow-single-imagenet" deleted
    $ kubectl get jobs
    No resources found.
    $ kubectl get pods
    No resources found.