

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# HyperPod 任務控管 AWS CLI 命令範例
<a name="sagemaker-hyperpod-eks-operate-console-ui-governance-cli"></a>

您可以透過 Kubectl 或透過 HyperPod 自訂 CLI 來使用 HyperPod 搭配 EKS。您可以透過 Studio 或 使用這些命令 AWS CLI。以下提供 SageMaker HyperPod 任務控管範例，說明如何使用 HyperPod AWS CLI 命令檢視叢集詳細資訊。如需詳細資訊，包括如何安裝，請參閱 [HyperPod CLI Github 儲存庫](https://github.com/aws/sagemaker-hyperpod-cli)。

**Topics**
+ [

## 取得叢集加速器裝置配額資訊
](#hp-eks-cli-get-clusters)
+ [

## 將任務提交至 SageMaker AI 受管佇列和命名空間
](#hp-eks-cli-start-job)
+ [

## 列出任務
](#hp-eks-cli-list-jobs)
+ [

## 取得任務詳細資訊
](#hp-eks-cli-get-job)
+ [

## 暫停和取消暫停任務
](#hp-eks-cli-patch-job)
+ [

## 偵錯任務
](#hp-eks-cli-other)

## 取得叢集加速器裝置配額資訊
<a name="hp-eks-cli-get-clusters"></a>

下列範例命令會取得叢集加速器裝置配額的相關資訊。

```
hyperpod get-clusters -n hyperpod-ns-test-team
```

此範例 `hyperpod-ns-test-team` 中的命名空間是在運算配置建立時根據所提供的團隊名稱 `test-team` 建立於 Kubernetes。如需詳細資訊，請參閱[編輯政策](sagemaker-hyperpod-eks-operate-console-ui-governance-policies-edit.md)。

回應範例：

```
[
    {
        "Cluster": "hyperpod-eks-test-cluster-id",
        "InstanceType": "ml.g5.xlarge",
        "TotalNodes": 2,
        "AcceleratorDevicesAvailable": 1,
        "NodeHealthStatus=Schedulable": 2,
        "DeepHealthCheckStatus=Passed": "N/A",
        "Namespaces": {
            "hyperpod-ns-test-team": {
                "TotalAcceleratorDevices": 1,
                "AvailableAcceleratorDevices": 1
            }
        }
    }
]
```

## 將任務提交至 SageMaker AI 受管佇列和命名空間
<a name="hp-eks-cli-start-job"></a>

下列範例命令會將任務提交至您的 HyperPod 叢集。如果您只能存取一個團隊，在這種情況下，HyperPod AWS CLI 會自動為您指派佇列。否則，如果發現多個佇列，我們將顯示所有可行的選項供您選取。

```
hyperpod start-job --job-name hyperpod-cli-test --job-kind kubeflow/PyTorchJob --image docker.io/kubeflowkatib/pytorch-mnist-cpu:v1beta1-bc09cfd --entry-script /opt/pytorch-mnist/mnist.py --pull-policy IfNotPresent --instance-type ml.g5.xlarge --node-count 1 --tasks-per-node 1 --results-dir ./result --priority training-priority
```

優先順序類別是在**叢集政策**中定義，其會定義任務的優先順序排定方式和閒置運算的配置方式。當資料科學家提交任務時，他們會使用格式為 `priority-class-name-priority` 的其中一個優先順序類別名稱。在此範例中，`training-priority` 是指名為 “training” 的優先順序類別。如需政策的詳細資訊，請參閱[政策](sagemaker-hyperpod-eks-operate-console-ui-governance-policies.md)。

如果未指定優先順序類別，任務會被視為低優先順序任務，任務排名值為 0。

如果指定了優先順序類別，但未對應至**叢集政策**中定義的其中一個優先順序類別，則提交會失敗，且錯誤訊息會提供一組定義的優先順序類別。

您也可以使用下列命令，提交使用 YAML 組態檔案的任務：

```
hyperpod start-job --config-file ./yaml-configuration-file-name.yaml
```

以下是 YAML 組態檔案範例，等同於上述提交任務。

```
defaults:
  - override hydra/job_logging: stdout
hydra:
  run:
    dir: .
  output_subdir: null
training_cfg:
  entry_script: /opt/pytorch-mnist/mnist.py
  script_args: []
  run:
    name: hyperpod-cli-test
    nodes: 1
    ntasks_per_node: 1
cluster:
  cluster_type: k8s
  instance_type: ml.g5.xlarge
  custom_labels:
    kueue.x-k8s.io/priority-class: training-priority
  cluster_config:
    label_selector:
      required:
        sagemaker.amazonaws.com/node-health-status:
          - Schedulable
      preferred:
        sagemaker.amazonaws.com/deep-health-check-status:
          - Passed
      weights:
        - 100
    pullPolicy: IfNotPresent
base_results_dir: ./result
container: docker.io/kubeflowkatib/pytorch-mnist-cpu:v1beta1-bc09cfd
env_vars:
  NCCL_DEBUG: INFO
```

或者，您可以使用 `kubectl` 提交任務，以確保任務出現在**儀表板**索引標籤中。下列是範例 kubectl 命令。

```
kubectl apply -f ./yaml-configuration-file-name.yaml
```

提交任務時，請包含您的佇列名稱和優先順序類別標籤。例如，搭配佇列名稱 `hyperpod-ns-team-name-localqueue` 和優先順序類別 `priority-class-name-priority`，您必須包含下列標籤：
+ `kueue.x-k8s.io/queue-name: hyperpod-ns-team-name-localqueue` 
+ `kueue.x-k8s.io/priority-class: priority-class-name-priority`

下列 YAML 組態程式碼片段示範如何將標籤新增至您的原始組態檔案，以確保您的任務出現在**儀表板**索引標籤中：

```
metadata:
    name: job-name
    namespace: hyperpod-ns-team-name
    labels:
        kueue.x-k8s.io/queue-name: hyperpod-ns-team-name-localqueue
        kueue.x-k8s.io/priority-class: priority-class-name-priority
```

## 列出任務
<a name="hp-eks-cli-list-jobs"></a>

下列命令會列出任務及其詳細資訊。

```
hyperpod list-jobs
```

回應範例：

```
{
    "jobs": [
        {
            "Name": "hyperpod-cli-test",
            "Namespace": "hyperpod-ns-test-team",
            "CreationTime": "2024-11-18T21:21:15Z",
            "Priority": "training",
            "State": "Succeeded"
        }
    ]
}
```

## 取得任務詳細資訊
<a name="hp-eks-cli-get-job"></a>

下列命令提供任務的詳細資訊。如果未指定命名空間，HyperPod AWS CLI 會擷取您能夠存取的 SageMaker AI 管理的命名空間。

```
hyperpod get-job --job-name hyperpod-cli-test
```

回應範例：

```
{
    "Name": "hyperpod-cli-test",
    "Namespace": "hyperpod-ns-test-team",
    "Label": {
        "app": "hyperpod-cli-test",
        "app.kubernetes.io/managed-by": "Helm",
        "kueue.x-k8s.io/priority-class": "training"
    },
    "CreationTimestamp": "2024-11-18T21:21:15Z",
    "Status": {
        "completionTime": "2024-11-18T21:25:24Z",
        "conditions": [
            {
                "lastTransitionTime": "2024-11-18T21:21:15Z",
                "lastUpdateTime": "2024-11-18T21:21:15Z",
                "message": "PyTorchJob hyperpod-cli-test is created.",
                "reason": "PyTorchJobCreated",
                "status": "True",
                "type": "Created"
            },
            {
                "lastTransitionTime": "2024-11-18T21:21:17Z",
                "lastUpdateTime": "2024-11-18T21:21:17Z",
                "message": "PyTorchJob hyperpod-ns-test-team/hyperpod-cli-test is running.",
                "reason": "PyTorchJobRunning",
                "status": "False",
                "type": "Running"
            },
            {
                "lastTransitionTime": "2024-11-18T21:25:24Z",
                "lastUpdateTime": "2024-11-18T21:25:24Z",
                "message": "PyTorchJob hyperpod-ns-test-team/hyperpod-cli-test successfully completed.",
                "reason": "PyTorchJobSucceeded",
                "status": "True",
                "type": "Succeeded"
            }
        ],
            "replicaStatuses": {
                "Worker": {
                    "selector": "training.kubeflow.org/job-name=hyperpod-cli-test,training.kubeflow.org/operator-name=pytorchjob-controller,training.kubeflow.org/replica-type=worker",
                    "succeeded": 1
                }
            },
        "startTime": "2024-11-18T21:21:15Z"
    },
    "ConsoleURL": "https://us-west-2.console.aws.amazon.com/sagemaker/home?region=us-west-2#/cluster-management/hyperpod-eks-test-cluster-id“
}
```

## 暫停和取消暫停任務
<a name="hp-eks-cli-patch-job"></a>

如果您想要從排程器移除一些已提交的任務，HyperPod AWS CLI 會提供 `suspend` 命令來暫時從協同運作中移除任務。除非透過 `unsuspend` 命令手動取消暫停任務，否則不會再排程已暫停的任務

若要暫停任務：

```
hyperpod patch-job suspend --job-name hyperpod-cli-test
```

若要將任務新增回佇列：

```
hyperpod patch-job unsuspend --job-name hyperpod-cli-test
```

## 偵錯任務
<a name="hp-eks-cli-other"></a>

HyperPod AWS CLI 也提供其他命令，讓您偵錯任務提交問題。例如，HyperPod AWS CLI Github 儲存庫`get-logs`中的 `list-pods`和 。