このドキュメントでは、Vertex AI の Model as a Service(MaaS)を介してオープンモデルを使用する方法について説明します。MaaS は、選択したパートナー モデルとオープンソース モデルへのサーバーレス アクセスを提供するため、インフラストラクチャのプロビジョニングや管理は必要ありません。
Model Garden は、Google、Google パートナー、オープンモデル(オープンウェイトとオープンソース)の AI モデルと ML モデル(MaaS モデルを含む)の一元化されたライブラリです。Model Garden には、Hugging Face のモデルなど、Vertex AI で使用可能なモデルをデプロイする方法が複数用意されています。
MaaS の詳細については、パートナー モデルのドキュメントをご覧ください。
始める前に
MaaS モデルを使用するには、Google Cloud プロジェクトで Vertex AI API を有効にする必要があります。
gcloud services enable aiplatform.googleapis.com
モデルの API を有効にする
MaaS モデルを使用する前に、その API を有効にする必要があります。これを行うには、Model Garden のモデルページに移動します。MaaS で利用可能なモデルの一部は、セルフデプロイでも利用できます。両方のサービスの Model Garden モデルカードは異なります。MaaS モデルカードの名前には API Service が含まれています。
Google Gen AI SDK for Python を使用してモデルを呼び出す
次の例では、Google Gen AI SDK for Python を使用して Llama 3.3 モデルを呼び出します。
from google import genai
from google.genai import types
PROJECT_ID="PROJECT_ID"
LOCATION="LOCATION"
MODEL="meta/llama-3.3-70b-instruct-maas" # The model ID from Model Garden with "API Service"
# Define the prompt to send to the model.
prompt = "What is the distance between earth and moon?"
# Initialize the Google Gen AI SDK client.
client = genai.Client(
vertexai=True,
project=PROJECT_ID,
location=LOCATION,
)
# Prepare the content for the chat.
contents: types.ContentListUnion = [
types.Content(
role="user",
parts=[
types.Part.from_text(text=prompt)
]
)
]
# Configure generation parameters.
generate_content_config = types.GenerateContentConfig(
temperature = 0,
top_p = 0,
max_output_tokens = 4096,
)
try:
# Create a chat instance with the specified model.
chat = client.chats.create(model=MODEL)
# Send the message and print the response.
response = chat.send_message(contents)
print(response.text)
except Exception as e:
print(f"{MODEL} call failed due to {e}")
次のステップ
- オープンモデルのサービング オプションを選択する
- Model Garden からオープンモデルをデプロイする
- ビルド済みコンテナを使用してオープンモデルをデプロイする
- カスタム vLLM コンテナを使用してオープンモデルをデプロイする