Deploy models to GPU partitions with inference components
After your partitioned endpoint is InService, you deploy a model to it by
creating an inference component that requests a partition type. Each copy of the
inference component occupies one partition of that type. To create the endpoint, see Create an endpoint with GPU partitions.
Inference component rules
The following rules apply to inference components on an endpoint with a partition layout:
-
AcceleratorPartitionTypeis required. If you omit it, SageMaker AI returns a 400 error. -
The requested type must be one that the endpoint layout declares. Otherwise, SageMaker AI returns a 400 error that names the declared types.
-
NumberOfAcceleratorDevicesRequiredmust be 1. It refers to one partition. -
MinMemoryRequiredInMbandNumberOfCpuCoresRequireddescribe host memory and CPU. The partition type sets the GPU memory. -
Each copy uses one partition. Increase
CopyCountto place more copies on free partitions of the same type.
Create inference components
The following procedure deploys a model to the endpoint
partition-demo on a mig-4g.20gb partition. The
inference component defines its model inline with a Hugging Face inference container
that downloads the gpt2 model from Hugging Face at startup, so you don't
need to run create-model.
To create inference components on partitions (Amazon CLI)
-
Create an inference component. Set
AcceleratorPartitionTypeto select the partition type that the model runs on. The followingcreate-inference-componentcommand creates the inference componentdemo-ic-4gon amig-4g.20gbpartition:aws sagemaker create-inference-component \ --region us-west-2 \ --inference-component-name demo-ic-4g \ --endpoint-name partition-demo \ --variant-name AllTraffic \ --specification '{ "Container": { "Image": "763104351884.dkr.ecr.us-west-2.amazonaws.com/huggingface-pytorch-inference:1.10.2-transformers4.17.0-gpu-py38-cu113-ubuntu20.04", "Environment": { "HF_MODEL_ID": "gpt2", "HF_TASK": "text-generation" } }, "ComputeResourceRequirements": { "AcceleratorPartitionType": "mig-4g.20gb", "NumberOfAcceleratorDevicesRequired": 1, "NumberOfCpuCoresRequired": 1, "MinMemoryRequiredInMb": 2048 } }' \ --runtime-config '{"CopyCount": 1}'To place a model on each partition type in the layout, repeat the command for each type with a different inference component name and
AcceleratorPartitionType.The following list describes the fields in this example:
-
AcceleratorPartitionTypemust be one of the types in the endpoint layout. -
NumberOfAcceleratorDevicesRequiredmust be 1. It refers to one partition. -
NumberOfCpuCoresRequiredandMinMemoryRequiredInMbdescribe host CPU and memory. The partition type sets the GPU memory.
-
-
Describe the inference component. It takes a few minutes to create. The following
describe-inference-componentcommand returns the name, status, and any failure reason of the inference component:aws sagemaker describe-inference-component --region us-west-2 --inference-component-name demo-ic-4g \ --query '[InferenceComponentName,InferenceComponentStatus,FailureReason]' --output textAn inference component is ready when its status is
InService. If the status isFailed, the third column shows the failure reason. When the inference component isInService, the model runs on its own partition.
Partitioning doesn't affect invocation. Invoke the model as you would any inference component, by calling InvokeEndpoint with the inference component name. For more information, see Invoke models for real-time inference.