Amazon SageMaker Python SDK v3、LLM 最適化機能を統合
本文の状態
日本語全文を表示中
詳細モードで約12分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
AWS Machine Learning Blog
Amazon は Python SDK v3 の新機能として、Notebook から直接エンドポイントのベンチマークを行い、コストと性能を最適化した生成 AI 推論設定を推奨・デプロイする機能を追加した。
AI深層分析を開く2026年8月7日 01:33
AI深層分析
キーポイント
SDK によるワークフロー統合
Amazon SageMaker Python SDK v3 が新バージョンで、Notebook 環境内で直接生成 AI 推論のベンチマークと推奨設定のデプロイを可能にする機能を公開した。
自動化された最適化プロセス
システムは生の実ワークロードに対してエンドポイントをベンチマークし、スループットやレイテンシを測定してコストと性能のバランスに基づいた推奨設定を生成する。
多様なアクセス経路の提供
この機能は Python SDK の他、Amazon SageMaker AI UI および Boto3 API からも利用可能となり、開発者のワークフローに柔軟に対応する。
最新SDKのインストール要件
Amazon SageMaker Python SDK を使用するには、バージョン 3.17.0 以降へのアップグレードが必要である。
自動化された最適化ワークフロー
SDK の統合により、手動での試行錯誤に代わり、インスタンスやフレームワーク構成の探索から推奨結果のデプロイまでをノートブック内で完結できる。
重要な引用
Optimizing generative AI inference deployments requires benchmarking endpoints, evaluating instance configurations, and iterating on deployment settings.
With this release, you can benchmark an endpoint, generate data-driven deployment recommendations, and deploy the recommended configuration directly from a notebook using the Amazon SageMaker Python SDK v3.
pip install --upgrade sagemaker >= 3.17.0
Traditionally, this involves manual trial and error across multiple instance types, container versions, and concurrency settings.
編集コメントを表示
編集コメント
開発者が手動で設定を調整する手間を省き、データに基づいた最適な推論環境の構築を可能にする点は実務的な価値が高い。AWS のエコシステム内で SDK を活用しているチームにとって、ワークフローの効率化に直結する機能強化と言える。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
生成AIの推論デプロイメントを最適化するには、エンドポイントのベンチマーク実施、インスタンス構成の評価、およびデプロイ設定の反復的な調整が必要です。Amazon SageMaker Python SDK v3では、Amazon SageMaker AIにおける生成AI推論推奨事項をノートブックワークフロー内で直接参照できるようになりました。これらの推奨事項は、Amazon SageMaker AI UI や Boto3 APIs を通じてアクセスすることも可能です。今回のリリースにより、Amazon SageMaker Python SDK v3を使用すれば、エンドポイントのベンチマークからデータ駆動型のデプロイ推奨事項の生成、そして推奨される構成への直接デプロイまでを、ノートブック 上で完結して実行できます。
本稿では、生成AI推論デプロイメントの最適化に向けたエンドツーエンドのワークフローで、新しいSDKインターフェースをどのように活用するかを実演します。
Amazon SageMaker AIにおける生成AI推論推奨事項のメリット
Amazon SageMaker AIの生成AI推論推奨機能は、以下の方法で推論の最適化を自動化します:
Amazon SageMaker エンドポイントに対して、合成または実際のトラフィック負荷を適用し、スループット、最初のトークンまでの時間 (TTFT)、エンドツーエンドのレイテンシなどを測定するベンチマークが可能です。
実際の使用パターンに基づき、コストとパフォーマンスのトレードオフでランク付けされたデプロイ推奨事項を生成できます。
ランク付けされた上位構成を、Amazon SageMaker リアルタイムエンドポイントに直接デプロイすることも可能です。
従来はこれらの機能を実現するために、Amazon SageMaker Studio を利用するか、AWS SDK for Python (Boto3) の API 呼び出しを構築する必要がありました。今回のリリースにより、これらは Python SDK の操作として扱えるようになり、既存のノートブックやパイプラインワークフローに自然に組み込むことができるようになりました。
新しい SDK インターフェース
新機能は、バージョン 3.17.0 から sagemaker.serve.ai_inference_recommender パッケージ内で利用可能となり、以下の主要な操作を公開しています。
| エントリーポイント | 機能 |
|---|---|
| ModelBuilder.from_jumpstart_config(…) | JumpStart モデル ID と計算設定から ModelBuilder を構築します |
| start_benchmark(endpoint, …) | 構成可能な合成ワークロードを使用して、デプロイされたエンドポイントに対して負荷テストを実行します |
| mb.generate_deployment_recommendations(…) | ワークロードに対してインスタンス/フレームワーク構成を検索し、ランク付けされた推奨事項を返します |
| mb.deploy(…) | 上位の推奨事項を実時間エンドポイントにデプロイします |
| ModelBuilder.from_recommendation_job(job_name) | 完了した推奨ジョブから ModelBuilder を復元します — 異なるプロセスまたはセッションでデプロイできます |
前提条件
最新の Amazon SageMaker Python SDK がインストールされていることを確認してください。
pip install --upgrade sagemaker >= 3.17.0また、以下の準備も必要です。
- Amazon SageMaker の実行権限を持つ AWS Identity and Access Management (IAM) ロールが付与された AWS アカウント。
- デプロイ済みの Amazon SageMaker リアルタイムエンドポイント(または、後述のセクションで説明する JumpStart モデルからデプロイ可能なもの)。
ソリューションの概要
一般的なシナリオとして、本番環境での利用が可能な生成 AI モデルがあり、最適なインスタンスタイプ、フレームワーク設定、推論パラメータを決定する必要があるケースを考えてみましょう。従来は、複数のインスタンスタイプやコンテナバージョン、並行処理設定を手動で試行錯誤する必要がありました。
しかし、Amazon SageMaker Python SDK の統合機能を使えば、この一連のワークフローを単一のノートブック内で自動化できます。以下の手順では、こちらのノートブック を使用して、エンドツーエンドの処理を詳しく解説します。
- デプロイ推奨事項の生成: サービスがワークロードのプロファイルに基づいてインスタンスタイプやフレームワーク構成を検索し、ランク付けされたオプションを返します。
- 結果の解釈と選択: ランク付けされた結果を確認し、トレードオフを理解した上で最適な設定を選択します。
- デプロイ: 選定された設定を実際の Amazon SageMaker エンドポイントに適用して展開します。
実負荷条件下でのデプロイ済みエンドポイントの検証
- ベンチマーク: 実際の負荷条件の下で、デプロイされたエンドポイントを検証します。
- フレームワークの比較: 必要に応じて LMI と vLLM を直接比較し、最適なサービングスタックを見つけます。
実トラフィックデータに基づく推奨事項の生成
まずは、モデルとワークロードに最適なデプロイ構成を見つけることから始めましょう。手動で複数のインスタンスタイプを試しにデプロイするのではなく、mb.generate_deployment_recommendations(…) を呼び出すことで、サービス側がワークロードのプロファイルに基づいてインスタンスタイプやフレームワークの構成を自動的に探索します。このサービスは候補となる各環境にモデルを展開し、実際のトラフィックパターンに合わせた負荷テストを実行した上で、選択したパフォーマンス目標に対して最適化された構成を順位付けして返却します。
import time, uuid
from sagemaker.core.jumpstart.configs import JumpStartConfig
from sagemaker.serve import ModelBuilder
from sagemaker.train.configs import Compute
from sagemaker.serve import InferenceFramework, PerformanceTarget
uid = f"{int(time.time())}-{uuid.uuid4().hex[:8]}"
src_model_name = f"demo-rec-source-{uid}"
rec_ep_name = f"demo-rec-ep-{uid}"
mb = ModelBuilder.from_jumpstart_config(
jumpstart_config=JumpStartConfig(model_id=MODEL_ID),
compute=Compute(instance_type=INSTANCE_TYPE),
role_arn=ROLE,
)
source_model = mb.build(model_name=src_model_name)
rec_job = mb.generate_deployment_recommendations(
tokenizer="google/gemma-4-e2b-it",
concurrency=1,
request_count=10,
prompt_input_tokens_mean=32,
output_tokens_mean=32,
streaming=True,
performance_target=PerformanceTarget.TTFT_MS
instance_types=[INSTANCE_TYPE],
advanced_optimization=False,
framework=InferenceFramework.LMI,
role_arn=ROLE,
wait=True,
)
#Comparative table across all returned recommendations
print(mb.recommendations)
# .best is the top-ranked row
top = mb.recommendations.best
print(f"Throughput avg: {top.expected_performance.request_throughput.avg}")
print(f"TTFT p99: {top.expected_performance.time_to_first_token.p99}")
# auto_approve=True bypasses the ModelPackage approval-status check
rec_endpoint = mb.deploy(
endpoint_name=rec_ep_name,
role=ROLE,
wait=True,
auto_approve=True,
)
print(f"Deployed: {rec_endpoint.endpoint_name} ({rec_endpoint.endpoint_status})")推奨結果は、Python のデータフレームとしても取得可能です。
import pandas as pd
pd.set_option("display.width", 200)
pd.set_option("display.max_columns", None)
pd.set_option("display.max_colwidth", 60)
rows = []
for i, rec in enumerate(mb.recommendations):
raw = rec._raw
spec = raw.model_details.inference_specification_name
for m in raw.expected_performance:
rows.append({
"rank": i,
"spec_name": spec,
"instance": raw.deployment_configuration.instance_type,
"metric": m.metric, # ← attribute, not subscript
"stat": m.stat,
"value": float(m.value),
"unit": m.unit,
})
df_long = pd.DataFrame(rows)
print(df_long) rank spec_name instance metric stat value unit
0 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge RequestThroughput avg 112.7664 Requests/Second
1 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge OutputTokenThroughput avg 3608.5300 Tokens/Second
2 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge RequestLatency p50 462.1300 Milliseconds
3 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge RequestLatency p90 999.5400 Milliseconds
4 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge RequestLatency p99 1069.8400 Milliseconds
5 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge TimeToFirstToken p50 438.5300 Milliseconds
6 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge TimeToFirstToken p90 983.3300 Milliseconds
7 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge InterTokenLatency p50 0.7900 Milliseconds
8 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge InterTokenLatency p90 2.8700 Milliseconds
9 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge ClientSideConcurrency 64.0000 Count
10 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge RequestThroughput avg 96.8522 Requests/Second
11 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge OutputTokenThroughput avg 3099.2700 Tokens/Second
12 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge RequestLatency p50 541.1600 Milliseconds
13 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge RequestLatency p90 1122.2000 Milliseconds
14 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge RequestLatency p99 1162.5300 Milliseconds
15 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge TimeToFirstToken p50 502.9000 Milliseconds
16 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge TimeToFirstToken p90 1088.4800 Milliseconds
17 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge InterTokenLatency p50 1.0000 Milliseconds
18 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge InterTokenLatency p90 3.6100 Milliseconds
19 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge ClientSideConcurrency 64.0000 Count推奨結果の読み解き方
推奨結果の表には、ml.g6.2xlarge インスタンス上で動作する 2 つの候補構成(ランク 0 とランク 1)が表示されています。両者は異なる LMI コンテナバージョンを使用しています。主要な指標を確認し、どちらを選ぶべきか判断する方法は以下の通りです。
比較すべき主要指標:
- RequestThroughput (avg): エンドポイントが 1 秒間に処理できるリクエスト数です。数値が高いほど優れています。
- OutputTokenThroughput (avg): 並行するすべてのリクエストで、1 秒間に生成されるトークンの総数です。数値が高いほど優れています。
- RequestLatency (p50/p90/p99): リクエストから完全なレスポンスが返ってくるまでのエンドツーエンドの時間です。数値が低いほど優れています。
- TimeToFirstToken (p50/p90): ユーザーがストリーミングされた最初のトークンを目にするまでの時間。数値が小さいほど望ましい。
- InterTokenLatency (p50/p90): ストリーミング中の連続するトークンの間の遅延。数値が小さいほど望ましい。
この例で示されている 2 つの構成を比較すると、Rank 0 (lmi-26-0-0) はスループットが 112.8 req/s、トークン生成速度が 3,609 tokens/s で、p90 の TTFT が 983 ms、p90 のレイテンシが 1,000 ms です。一方、Rank 1 (lmi-27-0-0) はスループットが 96.9 req/s、トークン生成速度が 3,099 tokens/s で、p90 の TTFT が 1,088 ms、p90 のレイテンシが 1,122 ms です。Rank 0 はすべての指標で優れています。スループットは約 16% 高く、レイテンシは約 10% 低いです。このサービスでは Rank 0 を最上位にランク付けしています。これはジョブ設定で performance_target=PerformanceTarget.TTFT_MS が指定されており、オプティマイザーが TimeToFirstToken の最小化を優先する構成を選んだためです。
一般的な意思決定の枠組み
レイテンシ敏感なアプリケーション(チャットボットや対話型 UI など)では、ユーザーに高速なレスポンスを感じてもらうために、低い TTFT (p90/p99) を最優先してください。
スループット敏感なワークロード(バッチ要約やオフライン処理など)では、ドルあたりのトークン生成数を最大化するために、高い RequestThroughput と OutputTokenThroughput を最優先してください。
2 つの構成が主要指標でほぼ同等の場合、二次的な指標をデッドヒートの決着付けに使い、さらにコストも考慮します。同程度の性能なら、より小さなインスタンスを選んだ方が費用対効果が高まります。
この例では、上位ランクの構成 (lmi-26-0-0) が、同じ並列度(64)ですべての指標を支配しているため、明確な最適解と言えます。
以前実行した推薦ジョブからデプロイ
本番環境のワークフローでは、推奨事項を生成するセッションと、それを実際にデプロイするセッションが別々になることがよくあります。例えば、データサイエンティストが実験段階で推薦ジョブを実行し、MLOps パイプラインがリリースサイクルの結果としてデプロイを行うといったケースです。完了したジョブから ModelBuilder を作成するには、ModelBuilder.from_recommendation_job(job_name) を使用します。
from sagemaker.serve import ModelBuilder
# Hydrate a fresh ModelBuilder from a completed recommendation job
mb = ModelBuilder.from_recommendation_job("my-rec-job-name")
print(f"Loaded {len(mb.recommendations)} recommendations")
print(mb.recommendations)
# Deploy the top-ranked recommendation
endpoint = mb.deploy(
role=ROLE,
wait=True,
auto_approve=True,
)JumpStart モデルのデプロイとベンチマーク
推奨された構成をデプロイした後、次は制御された条件下でそのパフォーマンスを検証する必要があります。ベンチマークを実施することで、本番トラフィックを処理する前にエンドポイントがレイテンシやスループット要件を満たしているかを確認できます。この SDK を使えば、JumpStart モデルのデプロイと合成負荷テストの実行を数行のコードで簡単に実行可能です。
import time, uuid
from sagemaker.core.jumpstart.configs import JumpStartConfig
from sagemaker.serve import ModelBuilder, start_benchmark
from sagemaker.train.configs import Compute
from sagemaker.serve import InferenceFramework, PerformanceTarget
uid = f"{int(time.time())}-{uuid.uuid4().hex[:8]}"
ep_name = f"demo-bench-ep-{uid}"
model_name = f"demo-bench-model-{uid}"
# Build and deploy a JumpStart endpoint
mb = ModelBuilder.from_jumpstart_config(
jumpstart_config=JumpStartConfig(model_id=MODEL_ID),
compute=Compute(instance_type=INSTANCE_TYPE),
role_arn=ROLE,
)
core_model = mb.build(model_name=model_name)
core_endpoint = mb.deploy(endpoint_name=ep_name)
# Benchmark with a synthetic workload
job = start_benchmark(
endpoint=core_endpoint,
tokenizer="google/gemma-4-e2b-it",
concurrency=1,
request_count=10,
prompt_input_tokens_mean=32,
output_tokens_mean=32,
streaming=True,
role=ROLE,
wait=True,
)
result = job.show_result()ベンチマーク結果の確認
ベンチマークが完了したら、エンドポイントがサービスレベル目標(SLO)を満たしているかどうかを確認する必要があります。ベンチマークは、スループット、レイテンシのパーセンタイル、トークン単位のタイミングをプログラムで取得できるメトリクスアクセサーを持つ型付きの結果オブジェクトを返します。IDE の自動補完機能もすべてのフィールドに対して有効です。
# Well-known shortcuts — fully typed, IDE autocomplete works
print(f"Throughput avg: {result.metrics.request_throughput.avg} req/sec")
print(f"TTFT p99: {result.metrics.time_to_first_token.p99} ms")
print(f"E2E latency p90: {result.metrics.request_latency.p90} ms")
# Any metric AIPerf produced, by raw key
ott = result.metrics.get("output_token_throughput")
if ott:
print(f"Output token throughput p90: {ott.p90} {ott.unit}")ベンチマーク結果は、同様に Python データフレームとして表現することもできます。
import pandas as pd
pd.set_option("display.width", 200)
pd.set_option("display.max_columns", None)
pd.set_option("display.max_colwidth", 60)
result = job.show_result()
rows = []
for name, m in result.metrics.all_metrics.items():
rows.append({
"metric": name,
"unit": m.unit,
"avg": m.avg,
"p50": m.p50,
"p90": m.p90,
"p99": m.p99,
})
df = pd.DataFrame(rows).set_index("metric")
print(df)unit avg p50 p90 p99
metric
request_throughput requests/sec 3.841439 NaN NaN NaN
request_latency ms 256.288407 206.586304 257.917252 656.735558
request_count requests 10.000000 NaN NaN NaN
time_to_first_token ms 91.770545 23.977319 93.899204 636.935233
time_to_second_token ms 3.035445 3.400013 3.611624 3.670301
inter_token_latency ms 4.987234 5.518454 5.689482 5.695788
output_token_throughput tokens/sec 130.608919 NaN NaN NaN
output_token_throughput_per_user tokens/sec/user 1036.753582 181.210181 1041.238702 7969.310858
output_sequence_length tokens 34.000000 34.000000 35.000000 35.000000
input_sequence_length tokens 32.000000 32.000000 32.000000 32.000000
output_token_count tokens 34.000000 34.000000 35.000000 35.000000
inter_chunk_latency ms 5.307028 5.921907 6.133938 6.599335
total_output_tokens tokens 340.000000 NaN NaN NaN
benchmark_duration sec 2.603191 NaN NaN NaN
total_isl tokens 320.000000 NaN NaN NaN
total_osl tokens 340.000000 NaN NaN NaN
http_req_sending ms 0.504841 0.230543 0.527351 2.798082
http_req_waiting ms 91.130199 23.709262 93.193301 633.795432
http_req_data_received KB 7.954883 7.956055 7.970801 7.971592
http_req_connecting ms 0.257011 0.000000 0.257011 2.338797
http_req_connection_reused ratio 0.900000 1.000000 1.000000 1.000000
http_req_blocked ms 0.000000 0.000000 0.000000 0.000000
http_req_dns_lookup ms 0.042871 0.000000 0.042871 0.390126
http_req_chunks_received count
原文を表示
Optimizing generative AI inference deployments requires benchmarking endpoints, evaluating instance configurations, and iterating on deployment settings. The Amazon SageMaker Python SDK v3 now exposes generative AI inference recommendations in Amazon SageMaker AI directly in your notebook workflow. These recommendations are also accessible through the Amazon SageMaker AI UI and Boto3 APIs. With this release, you can benchmark an endpoint, generate data-driven deployment recommendations, and deploy the recommended configuration directly from a notebook using the Amazon SageMaker Python SDK v3.
In this post, we demonstrate how to use the new SDK interface for the end-to-end workflow to optimize generative AI inference deployments.
Benefits of generative AI inference recommendations in Amazon SageMaker AI
Generative AI inference recommendations in Amazon SageMaker AI automate inference optimization by:
- Benchmarking a live Amazon SageMaker endpoint against a synthetic or real-traffic workload, measuring throughput, time-to-first-token (TTFT), end-to-end latency, and more.
- Generating deployment recommendations ranked by cost-performance tradeoff using your actual usage patterns.
- Deploying the top-ranked configuration directly to an Amazon SageMaker real-time endpoint.
Previously, these capabilities required using Amazon SageMaker Studio or constructing AWS SDK for Python (Boto3) API calls. With this launch, they become Python SDK operations, fitting naturally into existing notebook and pipeline workflows.
New SDK interfaces
The new functionality is available under the sagemaker.serve.ai_inference_recommender package starting with version 3.17.0 and exposes the following primary operations:
| Entry point | What it does |
|---|---|
| ModelBuilder.from_jumpstart_config(…) | Builds a ModelBuilder from a JumpStart model ID and compute config |
| start_benchmark(endpoint, …) | Runs a load test against a deployed endpoint with a configurable synthetic workload |
| mb.generate_deployment_recommendations(…) | Explores instance/framework configs against your workload and returns ranked recommendations |
| mb.deploy(…) | Deploys the top recommendation to a real-time endpoint |
| ModelBuilder.from_recommendation_job(job_name) | Hydrates a ModelBuilder from a completed recommendation job — deploy in a different process or session |
Prerequisites
Verify you have the latest version of the Amazon SageMaker Python SDK installed:
pip install --upgrade sagemaker >= 3.17.0You will also need:
- An AWS account with an AWS Identity and Access Management (IAM) role with Amazon SageMaker execution permissions.
- A deployed Amazon SageMaker real-time endpoint (or a JumpStart model to deploy; see the following section).
Solution overview
Consider a common scenario: you have a generative AI model ready for production and need to determine the optimal instance type, framework configuration, and serving parameters. Traditionally, this involves manual trial and error across multiple instance types, container versions, and concurrency settings. With the Amazon SageMaker Python SDK integration, you can automate this entire workflow in a single notebook. The following walkthrough guides you through the end-to-end journey using this notebook:
- Generate deployment recommendations: Let the service explore instance and framework configurations against your workload profile and return ranked options.
- Interpret and select: Review the ranked results, understand the tradeoffs, and pick the best fit.
- Deploy: Push the winning configuration to a live Amazon SageMaker endpoint.
- Benchmark: Validate the deployed endpoint under realistic load conditions.
- Compare frameworks: Optionally run LMI and vLLM head-to-head to find the best serving stack.
Generate recommendations from real traffic data
Your first step is to find the best deployment configuration for your model and workload. Rather than manually deploying across multiple instance types, call mb.generate_deployment_recommendations(…) to let the service explore instance types and framework configurations against your workload profile. The service deploys your model on each candidate, runs a load test matching your traffic pattern, and returns a ranked list of configurations optimized for your chosen performance target.
import time, uuid
from sagemaker.core.jumpstart.configs import JumpStartConfig
from sagemaker.serve import ModelBuilder
from sagemaker.train.configs import Compute
from sagemaker.serve import InferenceFramework, PerformanceTarget
uid = f"{int(time.time())}-{uuid.uuid4().hex[:8]}"
src_model_name = f"demo-rec-source-{uid}"
rec_ep_name = f"demo-rec-ep-{uid}"
mb = ModelBuilder.from_jumpstart_config(
jumpstart_config=JumpStartConfig(model_id=MODEL_ID),
compute=Compute(instance_type=INSTANCE_TYPE),
role_arn=ROLE,
)
source_model = mb.build(model_name=src_model_name)
rec_job = mb.generate_deployment_recommendations(
tokenizer="google/gemma-4-e2b-it",
concurrency=1,
request_count=10,
prompt_input_tokens_mean=32,
output_tokens_mean=32,
streaming=True,
performance_target=PerformanceTarget.TTFT_MS
instance_types=[INSTANCE_TYPE],
advanced_optimization=False,
framework=InferenceFramework.LMI,
role_arn=ROLE,
wait=True,
)
#Comparative table across all returned recommendations
print(mb.recommendations)
# .best is the top-ranked row
top = mb.recommendations.best
print(f"Throughput avg: {top.expected_performance.request_throughput.avg}")
print(f"TTFT p99: {top.expected_performance.time_to_first_token.p99}")
# auto_approve=True bypasses the ModelPackage approval-status check
rec_endpoint = mb.deploy(
endpoint_name=rec_ep_name,
role=ROLE,
wait=True,
auto_approve=True,
)
print(f"Deployed: {rec_endpoint.endpoint_name} ({rec_endpoint.endpoint_status})")Recommendation results can also be represented as a Python data frame.
import pandas as pd
pd.set_option("display.width", 200)
pd.set_option("display.max_columns", None)
pd.set_option("display.max_colwidth", 60)
rows = []
for i, rec in enumerate(mb.recommendations):
raw = rec._raw
spec = raw.model_details.inference_specification_name
for m in raw.expected_performance:
rows.append({
"rank": i,
"spec_name": spec,
"instance": raw.deployment_configuration.instance_type,
"metric": m.metric, # ← attribute, not subscript
"stat": m.stat,
"value": float(m.value),
"unit": m.unit,
})
df_long = pd.DataFrame(rows)
print(df_long) rank spec_name instance metric stat value unit
0 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge RequestThroughput avg 112.7664 Requests/Second
1 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge OutputTokenThroughput avg 3608.5300 Tokens/Second
2 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge RequestLatency p50 462.1300 Milliseconds
3 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge RequestLatency p90 999.5400 Milliseconds
4 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge RequestLatency p99 1069.8400 Milliseconds
5 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge TimeToFirstToken p50 438.5300 Milliseconds
6 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge TimeToFirstToken p90 983.3300 Milliseconds
7 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge InterTokenLatency p50 0.7900 Milliseconds
8 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge InterTokenLatency p90 2.8700 Milliseconds
9 0 low-ttft-on-g6-2xlarge-lmi-26-0-0 ml.g6.2xlarge ClientSideConcurrency 64.0000 Count
10 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge RequestThroughput avg 96.8522 Requests/Second
11 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge OutputTokenThroughput avg 3099.2700 Tokens/Second
12 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge RequestLatency p50 541.1600 Milliseconds
13 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge RequestLatency p90 1122.2000 Milliseconds
14 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge RequestLatency p99 1162.5300 Milliseconds
15 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge TimeToFirstToken p50 502.9000 Milliseconds
16 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge TimeToFirstToken p90 1088.4800 Milliseconds
17 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge InterTokenLatency p50 1.0000 Milliseconds
18 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge InterTokenLatency p90 3.6100 Milliseconds
19 1 low-ttft-on-g6-2xlarge-lmi-27-0-0 ml.g6.2xlarge ClientSideConcurrency 64.0000 CountHow to interpret recommendation results
The recommendations table shows two candidate configurations (rank 0 and rank 1), both on ml.g6.2xlarge but with different LMI container versions. Here’s how to read the key metrics and choose between them:
Key metrics to compare:
- RequestThroughput (avg): Requests the endpoint can serve per second. Higher is better.
- OutputTokenThroughput (avg): Total tokens generated per second across all concurrent requests. Higher is better.
- RequestLatency (p50/p90/p99): End-to-end time from request to full response. Lower is better.
- TimeToFirstToken (p50/p90): How quickly the user sees the first streamed token. Lower is better.
- InterTokenLatency (p50/p90): Delay between successive tokens during streaming. Lower is better.
Choosing between the two configurations in this example:
Rank 0 (lmi-26-0-0) delivers 112.8 req/s throughput and 3,609 tokens/s, with p90 TTFT of 983 ms and p90 latency of 1,000 ms. Rank 1 (lmi-27-0-0) delivers 96.9 req/s throughput and 3,099 tokens/s, with p90 TTFT of 1,088 ms and p90 latency of 1,122 ms. Rank 0 wins on every dimension: approximately 16% higher throughput and approximately 10 percent lower latency. The service ranks it first because the job was configured with performance_target=PerformanceTarget.TTFT_MS, meaning the optimizer prioritized configurations that minimize time-to-first-token.
General decision framework
Latency-sensitive applications (chatbots, interactive UIs): Prioritize low TTFT (p90/p99) so users perceive fast responses.
Throughput-sensitive workloads (batch summarization, offline processing): Prioritize high RequestThroughput and OutputTokenThroughput to maximize tokens per dollar.
If two configurations are close on your primary metric, use the secondary metrics as tiebreakers, then factor in cost (a smaller instance at similar performance saves money).
In this example, the top-ranked configuration (lmi-26-0-0) is the clear choice because it dominates across all metrics at the same concurrency level (64).
Deploy from previously run recommendation job
In production workflows, you often generate recommendations in one session and deploy in another. For example, a data scientist might run the recommendation job during experimentation, while an MLOps pipeline deploys the result during a release cycle. Use ModelBuilder.from_recommendation_job(job_name) to hydrate a ModelBuilder from a completed job:
from sagemaker.serve import ModelBuilder
# Hydrate a fresh ModelBuilder from a completed recommendation job
mb = ModelBuilder.from_recommendation_job("my-rec-job-name")
print(f"Loaded {len(mb.recommendations)} recommendations")
print(mb.recommendations)
# Deploy the top-ranked recommendation
endpoint = mb.deploy(
role=ROLE,
wait=True,
auto_approve=True,
)Deploy a JumpStart model and benchmark it
After you have deployed your recommended configuration, the next step is to validate its performance under controlled conditions. Benchmarking confirms that the endpoint meets your latency and throughput requirements before serving production traffic. The SDK makes this straightforward: deploy a JumpStart model and run a synthetic load test in only a few lines of code.
import time, uuid
from sagemaker.core.jumpstart.configs import JumpStartConfig
from sagemaker.serve import ModelBuilder, start_benchmark
from sagemaker.train.configs import Compute
from sagemaker.serve import InferenceFramework, PerformanceTarget
uid = f"{int(time.time())}-{uuid.uuid4().hex[:8]}"
ep_name = f"demo-bench-ep-{uid}"
model_name = f"demo-bench-model-{uid}"
# Build and deploy a JumpStart endpoint
mb = ModelBuilder.from_jumpstart_config(
jumpstart_config=JumpStartConfig(model_id=MODEL_ID),
compute=Compute(instance_type=INSTANCE_TYPE),
role_arn=ROLE,
)
core_model = mb.build(model_name=model_name)
core_endpoint = mb.deploy(endpoint_name=ep_name)
# Benchmark with a synthetic workload
job = start_benchmark(
endpoint=core_endpoint,
tokenizer="google/gemma-4-e2b-it",
concurrency=1,
request_count=10,
prompt_input_tokens_mean=32,
output_tokens_mean=32,
streaming=True,
role=ROLE,
wait=True,
)
result = job.show_result()Reading benchmark results
After the benchmark completes, you need to understand whether your endpoint meets your service-level objectives. The benchmark returns a typed result object with a metrics accessor that gives you programmatic access to throughput, latency percentiles, and token-level timing. IDE autocomplete works on all fields.
# Well-known shortcuts — fully typed, IDE autocomplete works
print(f"Throughput avg: {result.metrics.request_throughput.avg} req/sec")
print(f"TTFT p99: {result.metrics.time_to_first_token.p99} ms")
print(f"E2E latency p90: {result.metrics.request_latency.p90} ms")
# Any metric AIPerf produced, by raw key
ott = result.metrics.get("output_token_throughput")
if ott:
print(f"Output token throughput p90: {ott.p90} {ott.unit}")Benchmark results can similarly be represented as a Python data frame.
import pandas as pd
pd.set_option("display.width", 200)
pd.set_option("display.max_columns", None)
pd.set_option("display.max_colwidth", 60)
result = job.show_result()
rows = []
for name, m in result.metrics.all_metrics.items():
rows.append({
"metric": name,
"unit": m.unit,
"avg": m.avg,
"p50": m.p50,
"p90": m.p90,
"p99": m.p99,
})
df = pd.DataFrame(rows).set_index("metric")
print(df)unit avg p50 p90 p99
metric
request_throughput requests/sec 3.841439 NaN NaN NaN
request_latency ms 256.288407 206.586304 257.917252 656.735558
request_count requests 10.000000 NaN NaN NaN
time_to_first_token ms 91.770545 23.977319 93.899204 636.935233
time_to_second_token ms 3.035445 3.400013 3.611624 3.670301
inter_token_latency ms 4.987234 5.518454 5.689482 5.695788
output_token_throughput tokens/sec 130.608919 NaN NaN NaN
output_token_throughput_per_user tokens/sec/user 1036.753582 181.210181 1041.238702 7969.310858
output_sequence_length tokens 34.000000 34.000000 35.000000 35.000000
input_sequence_length tokens 32.000000 32.000000 32.000000 32.000000
output_token_count tokens 34.000000 34.000000 35.000000 35.000000
inter_chunk_latency ms 5.307028 5.921907 6.133938 6.599335
total_output_tokens tokens 340.000000 NaN NaN NaN
benchmark_duration sec 2.603191 NaN NaN NaN
total_isl tokens 320.000000 NaN NaN NaN
total_osl tokens 340.000000 NaN NaN NaN
http_req_sending ms 0.504841 0.230543 0.527351 2.798082
http_req_waiting ms 91.130199 23.709262 93.193301 633.795432
http_req_data_received KB 7.954883 7.956055 7.970801 7.971592
http_req_connecting ms 0.257011 0.000000 0.257011 2.338797
http_req_connection_reused ratio 0.900000 1.000000 1.000000 1.000000
http_req_blocked ms 0.000000 0.000000 0.000000 0.000000
http_req_dns_lookup ms 0.042871 0.000000 0.042871 0.390126
http_req_chunks_received count
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み