

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

# 使用 MIG 提交任务
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission"></a>

**Topics**
+ [使用 Kubernetes YAML](#sagemaker-hyperpod-eks-gpu-partitioning-task-submission-kubectl)
+ [使用 HyperPod CLI](#sagemaker-hyperpod-eks-gpu-partitioning-task-submission-cli)
+ [使用 MIG 进行模型部署](#sagemaker-hyperpod-eks-gpu-partitioning-task-submission-deployment)
+ [使用 HyperPod CLI](#sagemaker-hyperpod-eks-gpu-partitioning-task-submission-hyperpod-cli)

## 使用 Kubernetes YAML
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-kubectl"></a>

```
apiVersion: batch/v1
kind: Job
metadata:
  name: mig-job
  namespace: default
spec:
  template:
    spec:
      containers:
      - name: pytorch
        image: pytorch/pytorch:latest
        resources:
          requests:
            nvidia.com/mig-1g.5gb: 1
            cpu: "100m"
            memory: "128Mi"
          limits:
            nvidia.com/mig-1g.5gb: 1
      restartPolicy: Never
```

## 使用 HyperPod CLI
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-cli"></a>

使用 C HyperPod LI 部署支持 MIG 的 JumpStart 模型。以下示例演示了用于 GPU 分区的新 CLI 参数：

```
# Deploy JumpStart model with MIG
hyp create hyp-jumpstart-endpoint \
  --model-id deepseek-llm-r1-distill-qwen-1-5b \
  --instance-type ml.p5.48xlarge \
  --accelerator-partition-type mig-2g.10gb \
  --accelerator-partition-validation True \
  --endpoint-name my-endpoint \
  --tls-certificate-output-s3-uri s3://certificate-bucket/ \
  --namespace default
```

## 使用 MIG 进行模型部署
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-deployment"></a>

HyperPod 推理允许通过 Studio Classic 和 `kubectl` CLI HyperPod 在 MIG 配置文件上部署模型。要在上部署 JumpStart 模型 `kubectl` CRDs ，请调用字段将模型部署`spec.server.acceleratorPartitionType`到所需的 MIG 配置文件。我们进行验证以确保模型可以部署在 CRD 中选择的 MIG 配置文件上。如果您想禁用 MIG 验证检查，`spec.server.validations.acceleratorPartitionValidation`请使用。`False`

### JumpStart 模型
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-jumpstart"></a>

```
apiVersion: inference.sagemaker.aws.amazon.com/v1
kind: JumpStartModel
metadata:
  name: deepseek-model
  namespace: default
spec:
  sageMakerEndpoint:
    name: deepseek-endpoint
  model:
    modelHubName: SageMakerPublicHub
    modelId: deepseek-llm-r1-distill-qwen-1-5b
  server:
    acceleratorPartitionType: mig-7g.40gb
    instanceType: ml.p4d.24xlarge
```

### 使用从 Amazon S3 部署模型 InferenceEndpointConfig
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-s3"></a>

InferenceEndpointConfig 允许您从 Amazon S3 部署自定义模型。要在 MIG 上部署模型，请在和中`spec.worker.resources`提及 MIG 配置文件。`requests` `limits`请参阅下面的简单部署：

```
apiVersion: inference.sagemaker.aws.amazon.com/v1
kind: InferenceEndpointConfig
metadata:
  name: custom-model
  namespace: default
spec:
  replicas: 1
  modelName: my-model
  endpointName: my-endpoint
  instanceType: ml.p4d.24xlarge
  modelSourceConfig:
    modelSourceType: s3
    s3Storage:
      bucketName: my-model-bucket
      region: us-east-2
    modelLocation: model-path
  worker:
    resources:
      requests:
        nvidia.com/mig-3g.20gb: 1
        cpu: "5600m"
        memory: "10Gi"
      limits:
        nvidia.com/mig-3g.20gb: 1
```

### 使用 Lustre 从 FSx Lustre 部署模型 InferenceEndpointConfig
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-fsx"></a>

InferenceEndpointConfig 允许您从 FSx Lustre 部署自定义模型。要在 MIG 上部署模型，请在和中`spec.worker.resources`提及 MIG 配置文件。`requests` `limits`请参阅下面的简单部署：

```
apiVersion: inference.sagemaker.aws.amazon.com/v1
kind: InferenceEndpointConfig
metadata:
  name: custom-model
  namespace: default
spec:
  replicas: 1
  modelName: my-model
  endpointName: my-endpoint
  instanceType: ml.p4d.24xlarge
  modelSourceConfig:
    modelSourceType: fsx
    fsxStorage:
      fileSystemId: fs-xxxxx
    modelLocation: location-on-fsx
  worker:
    resources:
      requests:
        nvidia.com/mig-3g.20gb: 1
        cpu: "5600m"
        memory: "10Gi"
      limits:
        nvidia.com/mig-3g.20gb: 1
```

### 使用 Studio 经典用户界
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-studio"></a>

#### 使用 MIG 部署 JumpStart 模型
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-studio-deploy"></a>

1. 打开 **Studio 经典版**并导航到 **JumpStart**

1. 浏览或搜索你想要的模型（例如 DeepSeek “”、“Llama” 等）

1. 点击模型卡片并选择**部署**

1. 在部署配置中：
   + 选择**HyperPod**作为部署目标
   + 从下拉列表中选择您的启用 MiG 的集群
   + 在**实例配置**下：
     + 选择实例类型（例如`ml.p4d.24xlarge`）
     + 从可用选项中选择 **GPU 分区类型**
     + 配置**实例计数**和**自动扩展**设置

1. 查看并单击 “**部署**”

1. 在 “**终端节点**” 部分监控部署进度

#### 模型配置选项
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-studio-config"></a>

**端点设置：**
+ **终端节点名称**-您的部署的唯一标识符
+ **变体名称**-配置变体（默认： AllTraffic）
+ **实例类型**-必须支持 GPU 分区（p 系列）
+ **MIG 配置文件**-GPU 分区
+ **初始实例计数**-要部署的实例数量
+ **自动缩放**-启用以根据流量进行动态扩展

**高级配置：**
+ **模型数据位置**-自定义模型的 Amazon S3 路径
+ **容器镜像**-自定义推理容器（可选）
+ **环境变量**-特定于模型的配置
+ **亚马逊 VPC 配置**-网络隔离设置

#### 监控已部署的模型
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-studio-monitor"></a>

1. 导航到 **Studio 经典版** > **部署** > **终端节点**

1. 选择支持 MiG 的终端节点

1. 查看指标包括：
   + **MIG 利用率**-每个 GPU 分区的使用情况
   + **内存消耗**-每个 GPU 分区
   + **推理延迟**-请求处理时间
   + **吞吐量**-每秒请求数

1. 设置 **Amazon CloudWatch 警报**以进行自动监控

1. 根据 MIG 利用率配置**自动缩放策略**

## 使用 HyperPod CLI
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-hyperpod-cli"></a>

### JumpStart 部署
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-hyperpod-cli-jumpstart"></a>

 HyperPod CLI JumpStart 命令包括两个用于 MIG 支持的新字段：
+ `--accelerator-partition-type`-指定 MIG 配置（例如 mig-4g.20GB）
+ `--accelerator-partition-validation`-验证模型与 MIG 配置文件之间的兼容性（默认值：true）

```
hyp create hyp-jumpstart-endpoint \
  --version 1.1 \
  --model-id deepseek-llm-r1-distill-qwen-1-5b \
  --instance-type ml.p4d.24xlarge \
  --endpoint-name js-test \
  --accelerator-partition-type "mig-4g.20gb" \
  --accelerator-partition-validation true \
  --tls-certificate-output-s3-uri s3://my-bucket/certs/
```

### 自定义端点部署
<a name="sagemaker-hyperpod-eks-gpu-partitioning-task-submission-hyperpod-cli-custom"></a>

要通过自定义端点进行部署，请使用现有字段`--resources-requests``--resources-limits`并启用 MIG 配置文件功能：

```
hyp create hyp-custom-endpoint \
  --namespace default \
  --metadata-name deepseek15b-mig-10-14-v2 \
  --endpoint-name deepseek15b-mig-endpoint \
  --instance-type ml.p4d.24xlarge \
  --model-name deepseek15b-mig \
  --model-source-type s3 \
  --model-location deep-seek-15b \
  --prefetch-enabled true \
  --tls-certificate-output-s3-uri s3://sagemaker-bucket \
  --image-uri lmcache/vllm-openai:v0.3.7 \
  --container-port 8080 \
  --model-volume-mount-path /opt/ml/model \
  --model-volume-mount-name model-weights \
  --s3-bucket-name model-storage-123456789 \
  --s3-region us-east-2 \
  --invocation-endpoint invocations \
  --resources-requests '{"cpu":"5600m","memory":"10Gi","nvidia.com/mig-3g.20gb":"1"}' \
  --resources-limits '{"nvidia.com/mig-3g.20gb":"1"}' \
  --env '{
    "OPTION_ROLLING_BATCH":"vllm",
    "SERVING_CHUNKED_READ_TIMEOUT":"480",
    "DJL_OFFLINE":"true",
    "NUM_SHARD":"1",
    "SAGEMAKER_PROGRAM":"inference.py",
    "SAGEMAKER_SUBMIT_DIRECTORY":"/opt/ml/model/code",
    "MODEL_CACHE_ROOT":"/opt/ml/model",
    "SAGEMAKER_MODEL_SERVER_WORKERS":"1",
    "SAGEMAKER_MODEL_SERVER_TIMEOUT":"3600",
    "OPTION_TRUST_REMOTE_CODE":"true",
    "OPTION_ENABLE_REASONING":"true",
    "OPTION_REASONING_PARSER":"deepseek_r1",
    "SAGEMAKER_CONTAINER_LOG_LEVEL":"20",
    "SAGEMAKER_ENV":"1"
  }'
```