kubectl を使用して JumpStart からモデルをデプロイする - Amazon SageMaker AI

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

kubectl を使用して JumpStart からモデルをデプロイする

次のステップでは、kubectl を使用して JumpStart モデルを HyperPod クラスターにデプロイする方法を示します。

次の手順には、ターミナルで実行するように設計されたコードセルとコマンドが含まれています。これらのコマンドを実行する前に、 AWS 認証情報を使用して環境が設定されていることを確認してください。

前提条件

開始する前に、以下を確認してください。

セットアップと設定

  1. リージョンを選択します。

    export REGION=<region>
  2. すべての SageMaker パブリックハブモデルと HyperPod クラスターを表示します。

  3. JumpstartPublic Hub JumpstartModelから を選択します。JumpstartPublic ハブには多数のモデルが用意されているため、 NextTokenを使用してパブリックハブで使用可能なすべてのモデルを繰り返し一覧表示できます。

    aws sagemaker list-hub-contents --hub-name SageMakerPublicHub --hub-content-type Model --query '{Models: HubContentSummaries[].{ModelId:HubContentName,Version:HubContentVersion}, NextToken: NextToken}' --output json
    export MODEL_ID="deepseek-llm-r1-distill-qwen-1-5b" export MODEL_VERSION="2.0.4"
  4. 選択したモデル ID とクラスター名を以下の変数に設定します。

    注記

    クラスター管理者に確認して、このロールまたはユーザーに許可が付与されていることを確認します。を実行して!aws sts get-caller-identity --query "Arn"、ターミナルで使用しているロールまたはユーザーを確認できます。

    aws sagemaker list-clusters --output table # Select the cluster name where you want to deploy the model. export HYPERPOD_CLUSTER_NAME="<insert cluster name here>" # Select the instance that is relevant for your model deployment and exists within the selected cluster. # List availble instances in your HyperPod cluster aws sagemaker describe-cluster --cluster-name=$HYPERPOD_CLUSTER_NAME --query "InstanceGroups[].{InstanceType:InstanceType,Count:CurrentCount}" --output table # List supported instance types for the selected model aws sagemaker describe-hub-content --hub-name SageMakerPublicHub --hub-content-type Model --hub-content-name "$MODEL_ID" --output json | jq -r '.HubContentDocument | fromjson | {Default: .DefaultInferenceInstanceType, Supported: .SupportedInferenceInstanceTypes}' # Select and instance type from the cluster that is compatible with the model. # Make sure that the selected instance is either default or supported instance type for the jumpstart model export INSTANCE_TYPE="<Instance_type_In_cluster"
  5. 使用できる名前空間をクラスター管理者に確認します。管理者は、名前空間にhyperpod-inferenceサービスアカウントを作成している必要があります。

    export CLUSTER_NAMESPACE="default"
  6. 作成するエンドポイントとカスタムオブジェクトの名前を設定します。

    export SAGEMAKER_ENDPOINT_NAME="deepsek-qwen-1-5b-test"
  7. Jumpstart からのdeepseek-llm-r1-distill-qwen-1-5bモデルデプロイの例を次に示します。上記のステップで選択したモデルに基づいて、同様のデプロイ yaml ファイルを作成します。

    cat << EOF > jumpstart_model.yaml --- apiVersion: inference.sagemaker.aws.amazon.com/v1alpha1 kind: JumpStartModel metadata: name: $SAGEMAKER_ENDPOINT_NAME namespace: $CLUSTER_NAMESPACE spec: sageMakerEndpoint: name: $SAGEMAKER_ENDPOINT_NAME model: modelHubName: SageMakerPublicHub modelId: $MODEL_ID modelVersion: $MODEL_VERSION server: instanceType: $INSTANCE_TYPE metrics: enabled: true environmentVariables: - name: SAMPLE_ENV_VAR value: "sample_value" maxDeployTimeInSeconds: 1800 autoScalingSpec: cloudWatchTrigger: name: "SageMaker-Invocations" namespace: "AWS/SageMaker" useCachedMetrics: false metricName: "Invocations" targetValue: 10 minValue: 0.0 metricCollectionPeriod: 30 metricStat: "Sum" metricType: "Average" dimensions: - name: "EndpointName" value: "$SAGEMAKER_ENDPOINT_NAME" - name: "VariantName" value: "AllTraffic" EOF

モデルをデプロイする

kubernetes 設定を更新してモデルをデプロイする
  1. Amazon EKS によってオーケストレーションされた HyperPod クラスターに接続するように kubectl を設定します。

    export EKS_CLUSTER_NAME=$(aws --region $REGION sagemaker describe-cluster --cluster-name $HYPERPOD_CLUSTER_NAME \ --query 'Orchestrator.Eks.ClusterArn' --output text | \ cut -d'/' -f2) aws eks update-kubeconfig --name $EKS_CLUSTER_NAME --region $REGION
  2. JumpStart モデルをデプロイします。

    kubectl apply -f jumpstart_model.yaml
モデルデプロイのステータスをモニタリングする
  1. モデルが正常にデプロイされたことを確認します。

    kubectl describe JumpStartModel $SAGEMAKER_ENDPOINT_NAME -n $CLUSTER_NAMESPACE
  2. エンドポイントが正常に作成されたことを確認します。

    aws sagemaker describe-endpoint --endpoint-name=$SAGEMAKER_ENDPOINT_NAME --output table
  3. モデルエンドポイントを呼び出します。JumpStartModel オブジェクトからサンプルペイロードをプログラムで取得できます。

    aws sagemaker-runtime invoke-endpoint \ --endpoint-name $SAGEMAKER_ENDPOINT_NAME \ --content-type "application/json" \ --body '{"inputs": "What is AWS SageMaker?"}' \ --region $REGION \ --cli-binary-format raw-in-base64-out \ /dev/stdout

デプロイを管理する

JumpStart モデルのデプロイが不要になったら削除します。

kubectl delete JumpStartModel $SAGEMAKER_ENDPOINT_NAME -n $CLUSTER_NAMESPACE
トラブルシューティング

デプロイが想定どおりに機能しない場合は、これらのデバッグコマンドを使用します。

  1. Kubernetes デプロイのステータスを確認します。このコマンドは、モデルを実行しているポッドを管理する基盤となる Kubernetes デプロイオブジェクトを検査します。これを使用して、ポッドスケジューリング、リソース割り当て、コンテナの起動に関する問題のトラブルシューティングを行います。

    kubectl describe deployment $SAGEMAKER_ENDPOINT_NAME -n $CLUSTER_NAMESPACE
  2. JumpStart モデルリソースのステータスを確認します。このコマンドは、高レベルのモデル設定とデプロイライフサイクルを管理するカスタムJumpStartModelリソースを調べます。これを使用して、設定エラーや SageMaker AI エンドポイント作成の問題などのモデル固有の問題をトラブルシューティングします。

    kubectl describe JumpStartModel $SAGEMAKER_ENDPOINT_NAME -n $CLUSTER_NAMESPACE
  3. すべての Kubernetes オブジェクトのステータスを確認します。このコマンドは、名前空間内のすべての関連する Kubernetes リソースの包括的な概要を提供します。これを使用して、モデルのデプロイに関連付けられたポッド、サービス、デプロイ、カスタムリソースの全体的な状態をクイックヘルスチェックします。

    kubectl get pods,svc,deployment,JumpStartModel,sagemakerendpointregistration -n $CLUSTER_NAMESPACE