

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

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

您可以通过 Kubectl 或通过自定义 HyperPod CLI HyperPod 与 EKS 一起使用。您可以通过 Studio 或通过 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 还提供了其他命令供您调试作业提交问题。例如`list-pods`，`get-logs`在 HyperPod AWS CLI Github 存储库中。