|
| 1 | +(inference)= |
| 2 | + |
| 3 | +# Inference with SageMaker HyperPod |
| 4 | + |
| 5 | +SageMaker HyperPod provides powerful capabilities for deploying and managing inference endpoints on EKS-hosted clusters. This guide covers how to create, invoke, and manage inference endpoints using both the HyperPod CLI and SDK. |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +SageMaker HyperPod inference endpoints allow you to: |
| 10 | + |
| 11 | +- Deploy pre-trained JumpStart models |
| 12 | +- Deploy custom models with your own inference code |
| 13 | +- Configure resource requirements for inference |
| 14 | +- Manage endpoint lifecycle |
| 15 | +- Invoke endpoints for real-time predictions |
| 16 | +- Monitor endpoint performance |
| 17 | + |
| 18 | +## Creating Inference Endpoints |
| 19 | + |
| 20 | +You can create inference endpoints using either JumpStart models or custom models: |
| 21 | + |
| 22 | +### JumpStart Model Endpoints |
| 23 | + |
| 24 | +**CLI** |
| 25 | +```bash |
| 26 | +hyp create hyp-jumpstart-endpoint \ |
| 27 | + --version 1.0 \ |
| 28 | + --model-id jumpstart-model-id \ |
| 29 | + --instance-type ml.g5.8xlarge \ |
| 30 | + --endpoint-name endpoint-jumpstart \ |
| 31 | + --tls-output-s3-uri s3://sample-bucket |
| 32 | +``` |
| 33 | + |
| 34 | +**SDK** |
| 35 | +```python |
| 36 | +from sagemaker.hyperpod.inference import HyperPodJumpstartEndpoint |
| 37 | + |
| 38 | +# Create a JumpStart endpoint |
| 39 | +endpoint = HyperPodJumpstartEndpoint( |
| 40 | + endpoint_name="endpoint-jumpstart", |
| 41 | + model_id="jumpstart-model-id", |
| 42 | + instance_type="ml.g5.8xlarge", |
| 43 | + tls_output_s3_uri="s3://sample-bucket" |
| 44 | +) |
| 45 | + |
| 46 | +# Deploy the endpoint |
| 47 | +endpoint.create() |
| 48 | +``` |
| 49 | + |
| 50 | +### Custom Model Endpoints |
| 51 | + |
| 52 | +**CLI** |
| 53 | +```bash |
| 54 | +hyp create hyp-custom-endpoint \ |
| 55 | + --version 1.0 \ |
| 56 | + --endpoint-name endpoint-custom \ |
| 57 | + --model-uri s3://my-bucket/model-artifacts \ |
| 58 | + --image 123456789012.dkr.ecr.us-west-2.amazonaws.com/my-inference-image:latest \ |
| 59 | + --instance-type ml.g5.8xlarge \ |
| 60 | + --tls-output-s3-uri s3://sample-bucket |
| 61 | +``` |
| 62 | + |
| 63 | +**SDK** |
| 64 | +```python |
| 65 | +from sagemaker.hyperpod.inference import HyperPodCustomEndpoint |
| 66 | + |
| 67 | +# Create a custom endpoint |
| 68 | +endpoint = HyperPodCustomEndpoint( |
| 69 | + endpoint_name="endpoint-custom", |
| 70 | + model_uri="s3://my-bucket/model-artifacts", |
| 71 | + image="123456789012.dkr.ecr.us-west-2.amazonaws.com/my-inference-image:latest", |
| 72 | + instance_type="ml.g5.8xlarge", |
| 73 | + tls_output_s3_uri="s3://sample-bucket" |
| 74 | +) |
| 75 | + |
| 76 | +# Deploy the endpoint |
| 77 | +endpoint.create() |
| 78 | +``` |
| 79 | + |
| 80 | +## Key Parameters |
| 81 | + |
| 82 | +When creating an inference endpoint, you'll need to specify: |
| 83 | + |
| 84 | +- **endpoint-name**: Unique identifier for your endpoint |
| 85 | +- **model-id** (JumpStart): ID of the pre-trained JumpStart model |
| 86 | +- **model-uri** (Custom): S3 location of your model artifacts |
| 87 | +- **image** (Custom): Docker image containing your inference code |
| 88 | +- **instance-type**: The EC2 instance type to use |
| 89 | +- **tls-output-s3-uri**: S3 location to store TLS certificates |
| 90 | + |
| 91 | +## Managing Inference Endpoints |
| 92 | + |
| 93 | +### List Endpoints |
| 94 | + |
| 95 | +**CLI** |
| 96 | +```bash |
| 97 | +# List JumpStart endpoints |
| 98 | +hyp list hyp-jumpstart-endpoint |
| 99 | + |
| 100 | +# List custom endpoints |
| 101 | +hyp list hyp-custom-endpoint |
| 102 | +``` |
| 103 | + |
| 104 | +**SDK** |
| 105 | +```python |
| 106 | +from sagemaker.hyperpod.inference import HyperPodJumpstartEndpoint, HyperPodCustomEndpoint |
| 107 | + |
| 108 | +# List JumpStart endpoints |
| 109 | +jumpstart_endpoints = HyperPodJumpstartEndpoint.list() |
| 110 | +print(jumpstart_endpoints) |
| 111 | + |
| 112 | +# List custom endpoints |
| 113 | +custom_endpoints = HyperPodCustomEndpoint.list() |
| 114 | +print(custom_endpoints) |
| 115 | +``` |
| 116 | + |
| 117 | +### Describe an Endpoint |
| 118 | + |
| 119 | +**CLI** |
| 120 | +```bash |
| 121 | +# Describe JumpStart endpoint |
| 122 | +hyp describe hyp-jumpstart-endpoint --endpoint-name <endpoint-name> |
| 123 | + |
| 124 | +# Describe custom endpoint |
| 125 | +hyp describe hyp-custom-endpoint --endpoint-name <endpoint-name> |
| 126 | +``` |
| 127 | + |
| 128 | +**SDK** |
| 129 | +```python |
| 130 | +from sagemaker.hyperpod.inference import HyperPodJumpstartEndpoint, HyperPodCustomEndpoint |
| 131 | + |
| 132 | +# Get JumpStart endpoint details |
| 133 | +jumpstart_endpoint = HyperPodJumpstartEndpoint.load(endpoint_name="endpoint-jumpstart") |
| 134 | +jumpstart_details = jumpstart_endpoint.describe() |
| 135 | +print(jumpstart_details) |
| 136 | + |
| 137 | +# Get custom endpoint details |
| 138 | +custom_endpoint = HyperPodCustomEndpoint.load(endpoint_name="endpoint-custom") |
| 139 | +custom_details = custom_endpoint.describe() |
| 140 | +print(custom_details) |
| 141 | +``` |
| 142 | + |
| 143 | +### Invoke an Endpoint |
| 144 | + |
| 145 | +**CLI** |
| 146 | +```bash |
| 147 | +# Invoke custom endpoint |
| 148 | +hyp invoke hyp-custom-endpoint \ |
| 149 | + --endpoint-name <endpoint-name> \ |
| 150 | + --content-type "application/json" \ |
| 151 | + --payload '{"inputs": "What is machine learning?"}' |
| 152 | +``` |
| 153 | + |
| 154 | +**SDK** |
| 155 | +```python |
| 156 | +from sagemaker.hyperpod.inference import HyperPodCustomEndpoint |
| 157 | + |
| 158 | +# Load the endpoint |
| 159 | +endpoint = HyperPodCustomEndpoint.load(endpoint_name="endpoint-custom") |
| 160 | + |
| 161 | +# Invoke the endpoint |
| 162 | +response = endpoint.invoke( |
| 163 | + payload={"inputs": "What is machine learning?"}, |
| 164 | + content_type="application/json" |
| 165 | +) |
| 166 | +print(response) |
| 167 | +``` |
| 168 | + |
| 169 | +### Delete an Endpoint |
| 170 | + |
| 171 | +**CLI** |
| 172 | +```bash |
| 173 | +# Delete JumpStart endpoint |
| 174 | +hyp delete hyp-jumpstart-endpoint --endpoint-name <endpoint-name> |
| 175 | + |
| 176 | +# Delete custom endpoint |
| 177 | +hyp delete hyp-custom-endpoint --endpoint-name <endpoint-name> |
| 178 | +``` |
| 179 | + |
| 180 | +**SDK** |
| 181 | +```python |
| 182 | +from sagemaker.hyperpod.inference import HyperPodJumpstartEndpoint, HyperPodCustomEndpoint |
| 183 | + |
| 184 | +# Delete JumpStart endpoint |
| 185 | +jumpstart_endpoint = HyperPodJumpstartEndpoint.load(endpoint_name="endpoint-jumpstart") |
| 186 | +jumpstart_endpoint.delete() |
| 187 | + |
| 188 | +# Delete custom endpoint |
| 189 | +custom_endpoint = HyperPodCustomEndpoint.load(endpoint_name="endpoint-custom") |
| 190 | +custom_endpoint.delete() |
| 191 | +``` |
| 192 | + |
| 193 | +## Inference Example Notebooks |
| 194 | + |
| 195 | +For detailed examples of inference with HyperPod, see: |
| 196 | +- [CLI Inference FSX Model Example](https://github.com/aws/sagemaker-hyperpod-cli/blob/main/examples/inference/CLI/inference-fsx-model-e2e-cli.ipynb) |
| 197 | +- [CLI Inference Jumpstart Model Example](https://github.com/aws/sagemaker-hyperpod-cli/blob/main/examples/inference/CLI/inference-jumpstart-e2e-cli.ipynb) |
| 198 | +- [CLI Inference S3 Model Example](https://github.com/aws/sagemaker-hyperpod-cli/blob/main/examples/inference/CLI/inference-s3-model-e2e-cli.ipynb) |
0 commit comments