

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

# 公開されている基盤モデルを `JumpStartModel` クラスでデプロイする
<a name="jumpstart-foundation-models-use-python-sdk-model-class"></a>

SageMaker Python SDK を使用して、組み込みアルゴリズムまたは事前トレーニング済みモデルをわずか数行のコードで SageMaker AI エンドポイントにデプロイできます。

1. まず、「[Built-in Algorithms with pre-trained Model Table](https://sagemaker.readthedocs.io/en/stable/doc_utils/pretrainedmodels.html)」で、選択したモデルのモデル ID を調べます。

1. そのモデル ID を使用して、モデルを JumpStart モデルとして定義します。

   ```
   from sagemaker.jumpstart.model import JumpStartModel
   
   model_id = "huggingface-text2text-flan-t5-xl"
   my_model = JumpStartModel(model_id=model_id)
   ```

1. `deploy` メソッドを使用して、推論用にモデルを自動的にデプロイします。この例では、Hugging Face の FLAN-T5 XL モデルを使用します。

   ```
   predictor = my_model.deploy()
   ```

1. その後、`predict` メソッドを使用して、デプロイしたモデルで推論を実行できます。

   ```
   question = "What is Southern California often abbreviated as?"
   response = predictor.predict(question)
   print(response)
   ```

**注記**  
この例では、基盤モデル FLAN-T5 XL を使用しています。このモデルは、質疑応答、要約、チャットボットの作成など、幅広いテキスト生成のユースケースに適しています。モデルのユースケースの詳細については、「[利用可能な基盤モデル](jumpstart-foundation-models-latest.md)」を参照してください。

`JumpStartModel `クラスとそのパラメータの詳細については、「[JumpStartModel](https://sagemaker.readthedocs.io/en/stable/api/inference/model.html#sagemaker.jumpstart.model.JumpStartModel)」を参照してください。

## デフォルトのインスタンスタイプを確認する
<a name="jumpstart-foundation-models-use-python-sdk-model-class-instance-types"></a>

事前トレーニング済みのモデルを `JumpStartModel` クラスを使用してデプロイするときに、モデルのバージョンやインスタンスのタイプをオプションで指定することができます。すべての JumpStart モデルにはデフォルトのインスタンスタイプがあります。次のコードを使用して、デフォルトのデプロイインスタンスタイプを取得してください。

```
from sagemaker import instance_types

instance_type = instance_types.retrieve_default(
    model_id=model_id,
    model_version=model_version,
    scope="inference")
print(instance_type)
```

`instance_types.retrieve()` メソッドを使用して、特定の JumpStart モデルでサポートされているすべてのインスタンスタイプを確認してください。

## 推論コンポーネントを使用して複数のモデルを共有エンドポイントにデプロイする
<a name="jumpstart-foundation-models-use-python-sdk-model-class-endpoint-types"></a>

推論コンポーネントは SageMaker AI のホスティングオブジェクトです。これを使用して 1 つ以上のモデルをエンドポイントにデプロイし、柔軟性とスケーラビリティを高めることができます。JumpStart モデルの `endpoint_type` を、デフォルトのモデルベース (model-based) ではなく推論コンポーネントベース (inference-component-based) のエンドポイントに変更する必要があります。

```
predictor = my_model.deploy(
    endpoint_name = 'jumpstart-model-id-123456789012', 
    endpoint_type = EndpointType.INFERENCE_COMPONENT_BASED
)
```

推論コンポーネントを使用したエンドポイントの作成と SageMaker AI モデルのデプロイの詳細については、「[複数のモデルでリソース使用率を共有する](realtime-endpoints-deploy-models.md#deployed-shared-utilization)」を参照してください。

## 推論の有効な入出力形式を確認する
<a name="jumpstart-foundation-models-use-python-sdk-model-class-input-output"></a>

推論用の有効なデータ入力形式と出力形式を確認するには、`Serializers` クラスおよび `Deserializers` クラスから `retrieve_options()` メソッドを使用できます。

```
print(sagemaker.serializers.retrieve_options(model_id=model_id, model_version=model_version))
print(sagemaker.deserializers.retrieve_options(model_id=model_id, model_version=model_version))
```

## サポート対象のコンテンツタイプと出力タイプを確認する
<a name="jumpstart-foundation-models-use-python-sdk-model-class-content-types"></a>

同様に、`retrieve_options()` メソッドを使用して、モデルでサポートされているコンテンツタイプ (content type) と出力タイプ (accept type) を確認できます。

```
print(sagemaker.content_types.retrieve_options(model_id=model_id, model_version=model_version))
print(sagemaker.accept_types.retrieve_options(model_id=model_id, model_version=model_version))
```

ユーティリティの詳細については、「[Utility APIs](https://sagemaker.readthedocs.io/en/stable/api/utility/index.html)」を参照してください。