

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

# 使用 SageMaker HyperPod CLI 运行作业
<a name="sagemaker-hyperpod-eks-run-jobs-hyperpod-cli"></a>

要运行作业，请确保在 EKS 集群中安装了 Kubeflow Training Operator。有关更多信息，请参阅 [使用 Helm 在 Amazon EKS 集群上安装软件包](sagemaker-hyperpod-eks-install-packages-using-helm-chart.md)。

运行`hyperpod get-cluster`命令以获取可用 HyperPod 集群列表。

```
hyperpod get-clusters
```

运行，`hyperpod connect-cluster`配置 SageMaker HyperPod CLI，让 EKS 集群负责协调集群。 HyperPod 

```
hyperpod connect-cluster --cluster-name <hyperpod-cluster-name>
```

使用 `hyperpod start-job` 命令运行作业。下面的命令显示了带有所需选项的命令。

```
hyperpod start-job \
    --job-name <job-name>
    --image <docker-image-uri>
    --entry-script <entrypoint-script>
    --instance-type <ml.instance.type>
    --node-count <integer>
```

`hyperpod start-job` 命令还包含各种选项，如作业自动恢复和作业调度。

## 启用作业自动恢复
<a name="sagemaker-hyperpod-eks-run-jobs-hyperpod-cli-enable-auto-resume"></a>

`hyperpod start-job` 命令还有以下选项用于指定作业自动恢复。要使用 SageMaker HyperPod节点弹性功能启用作业自动恢复，必须将该`restart-policy`选项的值设置为。`OnFailure`作业必须在 `kubeflow` 命名空间或以 `hyperpod` 为前缀的命名空间下运行。
+ [--auto-resume<bool>] \$1可选项，启用作业失败后自动恢复，默认为 false
+ [--max-retry<int>] \$1可选项，如果自动恢复为 true，如果未指定，最大重试默认为 1
+ [--restart-policy<enum>] \$1Optional，重启策略。 PyTorchJob 可用值为 `Always`、`OnFailure`、`Never` 或 `ExitCode`。默认值为 `OnFailure`。

```
hyperpod start-job \
    ... // required options \
    --auto-resume true \
    --max-retry 3 \
    --restart-policy OnFailure
```

## 使用调度选项运行作业
<a name="sagemaker-hyperpod-eks-run-jobs-hyperpod-cli-scheduling"></a>

`hyperpod start-job` 命令有以下选项，用于使用队列机制设置作业。

**注意**  
您需要在 EKS 集群中安装 [Kueue](https://kueue.sigs.k8s.io/docs/overview/)。如果您尚未安装，请按照[SageMaker HyperPod 任务管理设置](sagemaker-hyperpod-eks-operate-console-ui-governance-setup.md)中的说明进行安装。
+ [--scheduler-type<enum>] \$1可选项，指定调度程序类型。默认值为 `Kueue`。
+ [--queue-name<string>] \$1可选项，指定要与作业一起提交的[本地队列](https://kueue.sigs.k8s.io/docs/concepts/local_queue/)或[集群队列](https://kueue.sigs.k8s.io/docs/concepts/cluster_queue/)的名称。队列应由集群管理员使用 `CreateComputeQuota` 创建。
+ [--priority<string>] \$1可选项，指定应由集群管理员创建的[工作负载优先级类别](https://kueue.sigs.k8s.io/docs/concepts/workload_priority_class/)的名称。

```
hyperpod start-job \
    ... // required options
    --scheduler-type Kueue \
    --queue-name high-priority-queue \
    --priority high
```

## 从配置文件运行作业
<a name="sagemaker-hyperpod-eks-run-jobs-hyperpod-cli-from-config"></a>

另一种方法是创建包含作业所需全部参数的作业配置文件，然后使用 --config-file 选项将该配置文件传递给 `hyperpod start-job` 命令。在本例中：

1. 创建包含所需参数的作业配置文件。有关[基准配置文件，请参阅 SageMaker HyperPod CLI GitHub 存储库中的作业配置文件](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-hyperpod-eks-run-jobs-hyperpod-cli.html#sagemaker-hyperpod-eks-hyperpod-cli-from-config)。

1. 使用配置文件启动作业，如下所示。

   ```
   hyperpod start-job --config-file /path/to/test_job.yaml
   ```

**提示**  
有关`hyperpod start-job`命令参数的完整列表，请参阅 SageMaker HyperPod CLI GitHub 存储库中的 “[提交 Job](https://github.com/aws/sagemaker-hyperpod-cli?tab=readme-ov-file#submitting-a-job)” 部分。`README.md`