Amazon SageMaker AI を用いた MLflow へのストリーミングベンチマークおよび推薦結果の送信
Amazon SageMaker AI は、生成 AI モデルのベンチマークおよび推奨結果を MLflow にリアルタイムでストリーミングする統合機能を追加し、実験追跡の効率化と再現性を大幅に向上させた。
キーポイント
MLflow 統合による自動ストリーミング機能の追加
SageMaker AI の最適化推論推奨ジョブおよびベンチマークジョブの結果が、自動的にサーバーレスの SageMaker MLflow アプリにリアルタイムで転送されるようになった。
データサイロの解消と反復サイクルの加速
手動でのデータ収集や設定不要により、異なる実験結果を MLflow 上で横並び比較することが可能になり、開発プロセスが効率化される。
生成 AI ベンチマークの複雑性への対応
GPU インスタンスタイプ、並列化戦略、スペキュラティブ・ディコーディングなどの多様なパラメータを評価する際の試行錯誤プロセスをデータ駆動型に転換する。
実行ロールの権限要件
ベンチマークおよび推奨ジョブを実行するには、SageMaker、MLflow アプリへのアクセス、エンドポイントの呼び出し、および S3 出力書き込みのための特定の IAM 権限が必要です。
MLflow 統合に必要なアクセス
追跡情報を SageMaker MLflow App に公開するためには、sagemaker-mlflow:* や sagemaker:CallMlflowAppApi などの特定の権限が実行ロールに付与されている必要があります。
MLflow アプリの検証と実験名の設定
SageMaker MLflow App が作成済みであることを確認し、ベンチマークと推薦ジョブで共有できる実験名を定義して結果を一元管理します。
出力設定によるメトリクス自動ストリーミング
OutputConfig の MlflowConfig を指定することで、SageMaker がベンチマークのメトリクス、パラメータ、チャートを自動的に MLflow アプリにストリーミングします。
重要な引用
That complexity is exactly why we introduced optimized generative AI inference recommendations for Amazon SageMaker AI: to help teams move from manual trial-and-error to guided, data-driven optimization and benchmarking.
This integration reduces data silos, accelerates iteration cycles, and brings full reproducibility to your inference optimization workflows.
The role should include the following permissions:
Amazon SageMaker AI uses the execution role to run the benchmark and recommendation jobs.
"The key field is MlflowConfig in OutputConfig. This tells SageMaker to stream benchmark metrics, parameters, and charts directly into your SageMaker MLflow App."
"Using the same MlflowExperimentName for both jobs makes it easier to compare results in one place."
影響分析・編集コメントを表示
影響分析
この発表は、大規模な生成 AI モデルの評価プロセスにおける運用上のボトルネック(データ断絶と手動作業)を解消する重要な一歩です。エンジニアが設定やツールの選択に費やす時間を削減し、より多くのリソースをモデルの最適化自体に集中できる環境を提供することで、業界全体の開発スピード向上に寄与します。
編集コメント
生成 AI の実装において、モデル選定や設定の試行錯誤は時間がかかる課題ですが、この統合によりデータ管理の負担が劇的に軽減されます。特に大規模な推論環境を構築する現場では、即座に導入を検討すべき機能です。
生成 AI モデルのベンチマークを行うチームは、本番環境への展開前に、数十種類の GPU インスタンスタイプやサービングコンテナ、並列化戦略、推測デコーディングなどの最適化技術を評価することがよくあります。実務者は、設定に関する意思決定に数週間を費やし、試したこと、成功した方法、その理由を手作業で組み立てることに追われることがあります。この複雑さがまさに、Amazon SageMaker AI 向けの最適化された生成 AI 推論推奨機能を導入した理由です。これは、チームが手動の試行錯誤から、ガイド付きでデータ駆動型の最適化とベンチマークへと移行できるよう支援するためです。
本日、MLflow 統合を追加しました。これにより、チームは AI ベンチマークおよび推奨結果を単一の場所にストリーミングしてすべての実験を追跡できます。この統合によりデータのサイロが解消され、反復サイクルが加速し、推論最適化ワークフローに完全な再現性がもたらされます。
本記事では、新しい MLflow 統合を使用して、Amazon SageMaker AI の最適化された推論推奨ジョブおよび Amazon SageMaker AI ベンチマークジョブ を活用し、実験データを統一された追跡インターフェースに自動的にストリーミングする方法を学びます。
この統合により、メトリクス、パラメータ、チャートがサーバーレスの Amazon SageMaker MLflow App にリアルタイムでストリーミングされ、統一された実験追跡体験を提供します。
ソリューション概要
今回のリリースにより、最適化された推論推奨ジョブまたはベンチマークジョブを提出すると、Amazon SageMaker AI が自動的に結果を選択した SageMaker MLflow アプリにストリーミングします。同じ MLflow 実験に対して複数のジョブを提出し、MLflow 実験ビューでそれらを選択して手動でのデータ加工なしで並列比較することが可能になります。
以下の図は、ベンチマークおよび推奨ジョブと MLflow をセットアップする方法を示しています:

既存の推奨ジョブおよびベンチマークジョブに MLflow をセットアップするには、以下の手順に従います:
- MLflow アプリの作成: AWS アカウントで Amazon SageMaker Studio を開き、MLflow に移動して「Create MLflow App」を選択します。
- 権限の付与: 実行ロールに対して、MLflow アプリ ARN に sagemaker-mlflow:* を追加します。
- ベンチマークまたは推奨ジョブを作成する際に MlflowConfig を渡します。
手動でのデータ統合を不要に: ネイティブの MLflow 統合により、複数のジョブからのベンチマークおよび推奨結果が、同じ実験名の下で自動的に統合されます。これにより、別々の実行間でメトリクス、ログ、設定を手動で収集する必要性がなくなります。その後、インスタンスタイプ、モデル構成、バッチサイズ、または推測的デコーディングがパフォーマンスにどのように影響するかを理解するために、実行結果を並べて比較できます。例えば、ml.g4dn.12xlarge 上の qwen2-0.5b と ml.p4d.24xlarge 上のものを比較することが可能です。
長時間実行されるジョブのリアルタイム監視: ベンチマークおよび推奨ジョブには数時間かかることがあります。完了を待って視認性がないまま過ごすのではなく、メトリクスが MLflow UI にライブでストリーミングされるのを今や確認できます。各構成がテストされるたびにレイテンシとスループットメトリクスが更新され、開始から終了までプロセスを追跡可能になります。メトリクスセクションには生データ(ライブ)メトリクスを公開しており、ジョブの終了時だけでなく時間経過とともに更新されます。これらのメトリクスを使用して、推奨ジョブでのスループットが期待通りかどうかを確認し、そうでない場合は早期に停止できます。
完全な監査証跡の維持: 実験の実行は、ジョブパラメータ、タイムスタンプ、チェックポイント時のメトリクス、および生成されたアーティファクトという文脈全体を記録します。この監査証跡は数ヶ月間照会可能かつ再現可能です。どの構成変更が改善をもたらしたかを追跡し、パフォーマンスの頭打ちを特定し、完全な文脈を持って過去の決定を見直すことができます。
より良いコラボレーションとガバナンス: 共有された MLflow の実験は、最適化活動における唯一の信頼できる情報源となります。チームメンバーは、何が試され、何が成功し、何が失敗したかをレビューでき、重複する作業を減らし、シフト間やチームメンバー間の意思疎通を支援します。
技術的なウォークスルー:SageMaker AI のベンチマークと推奨事項を MLflow で追跡
この例では、顧客が ml.g6.12xlarge インスタンス上の OpenAI 互換サービングスタックを使用して、Qwen/Qwen2-0.5B-Instruct を Amazon SageMaker AI リアルタイムエンドポイントにデプロイしています。チームは以下の 2 つの質問に答えようとしています:既存の Qwen エンドポイントが軽量なチャットボットのワークロードでどのようにパフォーマンスを発揮するか、およびより長いプロンプトとレスポンスを伴う大規模なワークロードに対してどのような構成を使用すべきかです。
評価の再現性を確保するため、ベンチマークジョブと推奨ジョブの両方が、メトリクス、パラメータ、チャートを同じ SageMaker MLflow 実験に書き込みます。ベンチマークジョブは既存の SageMaker エンドポイントを評価します。一方、推奨ジョブは Amazon Simple Storage Service (Amazon S3) に保存された Qwen モデルアーティファクトのデプロイオプションを評価し、ランク付けされた構成を返します。ここでは、ml.g6.12xlarge インスタンス上で Qwen/Qwen2-0.5B-Instruct を使用して MLflow を設定し、レイテンシ最適化のための推奨事項とベンチマークの両方を活用する方法を示すウォークスルーノートブックを使用します。
エンドツーエンドのウォークスルーには、エンドポイントの準備状況、モデルサイズ、ワークロード構成、インスタンスの利用可能性、および推奨ジョブの検索空間に応じて、通常 45〜120 分 かかります。
前提条件
この ノートブック では、ベンチマークおよび推奨ジョブの実験追跡のために MLflow アプリを設定する方法を順を追って説明します。このノートブックを実行して始めるには、以下の手順を完了する必要があります。
- Amazon SageMaker AI 上で開発環境として Amazon SageMaker Studio を設定してください。
- SageMaker Unified Studio (SageMaker Unified Studio → MLflow → Create MLflow App) から SageMaker MLflow アプリを作成してください。
- ベンチマークジョブ用に、OpenAI 互換モデルを実行している SageMaker エンドポイント(すでに InService 状態)が必要です。以下の図に示すように、Amazon SageMaker JumpStart Studio UI から Qwen 2 0.5B モデルをデプロイして始めることができます:
- 推奨ジョブ用の Amazon S3 に保存されたモデルアーティファクトが必要です。
- AmazonSageMakerFullAccess の権限に加え、MLflow およびエンドポイント呼び出しアクセスのためのインラインポリシーを持つ AWS Identity and Access Management (IAM) 実行ロールが必要です。IAM ロールの作成手順については、添付のノートブックを参照してください。
重要な考慮事項
- この統合機能は SageMaker MLflow Apps をサポートしており、自己ホスト型の MLflow 追跡サーバーへ結果をストリーミングするものではありません。
- MLflow のネストされた実行(nested run)機能を有効にするには、tooling.version を 0.8.0 以降に設定してください。
- レコメンデーションジョブは内部で独自のエンドポイントをプロビジョニングするため、検索空間を制限する特別な理由がない限り、ComputeSpec.InstanceTypes を指定する必要はありません。実行ロールには、必要な SageMaker、MLflow、Amazon S3、およびエンドポイント呼び出しの権限を含める必要があります。S3 出力バケットは、ジョブと同じリージョンに存在している必要があります。
AIRecommendationJob を含む追加例を備えた完全なエンドツーエンドのノートブックについては、ステップバイステップチュートリアルをご覧ください。
ステップ 1: 環境の設定
まず、環境変数を設定し、SageMaker クライアントを初期化します。
import json
import time
import uuid
import boto3
import botocore.config
# これらの値はご自身の環境に合わせて更新してください
REGION = "us-west-2"
ACCOUNT_ID = ""
MLFLOW_APP_ARN = "arn:aws:sagemaker:us-west-2::mlflow-app/"
ENDPOINT_NAME = "my-model-endpoint"
sm = boto3.client(
"sagemaker",
region_name=REGION,
config=botocore.config.Config(
retries={"mode": "standard", "max_attempts": 15}
),
)
# S3 出力バケットは、ジョブと同じリージョンに存在している必要があります
S3_OUTPUT_BUCKET = f"mlflow-sagemaker-{REGION}-{ACCOUNT_ID}"ステップ 2:実行ロールの解決
Amazon SageMaker AI は、ベンチマークおよび推奨ジョブを実行するために実行ロールを使用します。このロールには、SageMaker にアクセスし、エンドポイントを呼び出し、ジョブ出力を Amazon S3 に書き込み、SageMaker MLflow アプリに追跡情報を公開する権限が必要です。ノートブック を参照して IAM ロールを作成してください。
ロールには以下の権限を含める必要があります:
権限領域 必要なアクセス
SageMaker ジョブ実行 AmazonSageMakerFullAccess、またはスコープを限定した同等のもの
MLflow 統合 sagemaker-mlflow:*, sagemaker:CallMlflowAppApi, sagemaker:DescribeMlflowApp
エンドポイント呼び出し sagemaker:InvokeEndpoint, sagemaker:InvokeEndpointWithResponseStream
S3 出力 設定された出力バケットへの読み書きアクセス
ROLE_NAME = "tutorial-exec-role"
iam = boto3.client("iam")
role = iam.get_role(RoleName=ROLE_NAME)["Role"]
ROLE_ARN = role["Arn"]
print(f"Role ARN: {ROLE_ARN}")
実行ロールの信頼ポリシーを構成して、SageMaker がこのロールを引き受けることを許可してください。環境によっては、ロールの作成方法や引き渡し方に応じて、アカウントのルートプリンシパルを含める必要がある場合もあります。
ステップ 3:MLflow アプリの検証と実験名の定義
次に、SageMaker MLflow App が利用可能であることを確認します。その後、ベンチマークジョブおよび推奨ジョブ用の共有実験名と一意の実行名を定義してください。
両方のジョブで同じ MlflowExperimentName を使用することで、結果を一つの場所で比較しやすくなります。
MLflow アプリの可用性を確認する
app = sm.describe_mlflow_app(Arn=MLFLOW_APP_ARN)
MLFLOW_APP_URL = app["Url"]
assert app["Status"] in ("Created", "Updated")
print(f"MLflow URL: {MLFLOW_APP_URL}")
共有実験と一意の実行名を定義する
MLFLOW_EXPERIMENT = "gemma-experiments"
SESSION_UID = uuid.uuid4().hex[:6]
BENCH_RUN_NAME = f"benchmark-{SESSION_UID}"
REC_RUN_NAME = f"recommendation-{SESSION_UID}"
ステップ 4:ベンチマークジョブの送信
SageMaker AI ベンチマークジョブは、ワークロード仕様を使用して既存のエンドポイントを評価します。この例では、ワークロードは OpenAI 互換 API スキーマを使用した NVIDIA AIPerf を利用しています。
重要なフィールドは OutputConfig の MlflowConfig です。これにより、SageMaker はベンチマークのメトリクス、パラメータ、およびチャートを SageMaker MLflow App に直接ストリーミングするように指示されます。
トークナイザーはデプロイされたモデルと完全に一致させる必要があります。
tooling.version=0.8.0 は、MLflow のネストされたラン(run)サポートのための最小要件です。
TOKENIZER = "Qwen/Qwen2-0.5B-Instruct"
bench_workload = {
"benchmark": {"type": "aiperf"},
"parameters": {
"model": TOKENIZER,
"concurrency": 1,
"request_count": 3,
"streaming": True,
"prompt_input_tokens_mean": 32,
"prompt_input_tokens_stddev": 8,
"output_tokens_mean": 16,
"output_tokens_stddev": 4,
"random_seed": 42,
},
"tooling": {
"api_standard": "openai",
"version": "0.8.0",
},
}
BENCH_CONFIG = f"mlflow-bench-cfg-{SESSION_UID}"
BENCH_JOB = f"mlflow-bench-job-{SESSION_UID}"
sm.create_ai_workload_config(
AIWorkloadConfigName=BENCH_CONFIG,
AIWorkloadConfigs={
"WorkloadSpec": {
"Inline": json.dumps(bench_workload)
}
},
)
sm.create_ai_benchmark_job(
AIBenchmarkJobName=BENCH_JOB,
AIWorkloadConfigIdentifier=BENCH_CONFIG,
RoleArn=ROLE_ARN,
BenchmarkTarget={
"Endpoint": {
"Identifier": ENDPOINT_NAME
}
},
OutputConfig={
"S3OutputLocation": f"s3://{S3_OUTPUT_BUCKET}/mlflow-tutorial/{BENCH_JOB}/",
"MlflowConfig": {
"MlflowResourceArn": MLFLOW_APP_ARN,
"MlflowExperimentName": MLFLOW_EXPERIMENT,
"MlflowRunName": BENCH_RUN_NAME,
},
},
)
print(f"Benchmark job submitted: {BENCH_JOB}")
ステップ 5:推薦ジョブの送信
SageMaker AI の推薦ジョブは、デプロイ構成を評価し、ワークロードとパフォーマンス目標に基づいて推奨オプションを提案します。ベンチマークジョブとは異なり、推薦ジョブは評価プロセス中に内部で独自のエンドポイントをプロビジョニングします。
以下の例では、ベンチマークジョブと同じ MLflow 実験名を使用しているため、両方のランが SageMaker MLflow アプリ上で一緒に表示されます。
rec_workload = {
"benchmark": {"type": "aiperf"},
"parameters": {
"prompt_input_tokens_mean": 1600,
"prompt_input_tokens_stddev": 200,
"output_tokens_mean": 600,
"output_tokens_stddev": 100,
"request_count": 100,
},
"tooling": {
"api_standard": "openai",
"version": "0.8.0",
},
}
REC_CONFIG = f"mlflow-rec-cfg-{SESSION_UID}"
REC_JOB = f"mlflow-rec-job-{SESSION_UID}"
sm.create_ai_workload_config(
AIWorkloadConfigName=REC_CONFIG,
AIWorkloadConfigs={
"WorkloadSpec": {
"Inline": json.dumps(rec_workload)
}
},
)sm.create_ai_recommendation_job(
AIRecommendationJobName=REC_JOB,
ModelSource={
"S3": {
"S3Uri": MODEL_S3_URI
}
},
OutputConfig={
"S3OutputLocation": f"s3://{S3_OUTPUT_BUCKET}/mlflow-tutorial/{REC_JOB}/",
"MlflowConfig": {
"MlflowResourceArn": MLFLOW_APP_ARN,
"MlflowExperimentName": MLFLOW_EXPERIMENT,
"MlflowRunName": REC_RUN_NAME,
},
},
RoleArn=ROLE_ARN,
AIWorkloadConfigIdentifier=REC_CONFIG,
PerformanceTarget={
"Constraints": [
{
"Metric": "ttft-ms"
}
]
},
OptimizeModel=False,
)
print(f"Recommendation job submitted: {REC_JOB}")
Step 6: Compare results in MLflow
ジョブが完了したら、SageMaker MLflow App を開き、設定した実験(experiment)に移動してください。以下のコードは、ノートブック内で MLflow アプリへの URL を取得するためのものです。
print(f"Open: {MLFLOW_APP_URL}")
実験ビューでは、親ランは子ラン間の関係性を示すために存在する空のプレースホルダーです。ネストされたメトリクス(metrics)を表示するには、各親ランを展開する必要があります。
benchmark- -> AIPerf ベンチマークメトリクスを用いた単一実行
recommendation- -> 順位付けされた推奨設定を含むネストされた実行ツリー
子実行にはモデルのメトリクスが含まれています。推奨ジョブのメトリクスを確認するには、MLflow Runs ページに移動し、推奨ジョブの親実行を展開して、並列度(concurrency)行が表示されるまでネストされた子実行を順次展開してください。ベンチマークメトリクスは、以下の図に示すように、各並列度実行の Metrics カラムに表示されます:

推奨結果のアーティファクトを検証するには、Concurrency=4 実行を開き、Artifacts タブを選択します。アーティファクトファイルツリーで exports を展開し、outputs.json を選択してください。プレビューパネルには、アーティファクトファイルパスと JSON 出力が表示され、セッション ID、リクエストのタイミング、出力トークン数、リクエストレイテンシ、レスポンステキストなどのリクエストレベルのフィールドが含まれています(以下の図参照):

Runs ページで、比較したいベンチマーク実行(例:Concurrency=32、Concurrency=16、Concurrency=8、Concurrency=4 の各行)を選択し、Compare を選択して、期間、スループット、出力トークン数、リクエストレイテンシにわたるメトリクスの違いを表示します(以下の図参照):
Metrics セクションでは、「Show diff only」トグルを使用して、変更されたメトリクスのみを表示できます。このテーブルは、選択したベンチマークまたはレコメンデーションジョブの結果間における、ベンチマーク期間やエンドツーエンドの出力トークンスループットなどのベンチマークメトリクスを比較します(以下の図参照):

リソースのクリーンアップ
継続的な課金を避けるために、リソース y
原文を表示
Teams benchmarking generative AI models often evaluate dozens of GPU instance types, serving containers, parallelism strategies, and optimization techniques such as speculative decoding before deploying to production. Practitioners can spend weeks navigating configuration decisions and manually piecing together what they tried, what worked, and why. That complexity is exactly why we introduced optimized generative AI inference recommendations for Amazon SageMaker AI: to help teams move from manual trial-and-error to guided, data-driven optimization and benchmarking.
Today, we are adding MLflow integration so teams can stream AI benchmark and recommendation results into a single place to track every experiment. This integration reduces data silos, accelerates iteration cycles, and brings full reproducibility to your inference optimization workflows.
In this post, you learn how to use the new MLflow integration with Amazon SageMaker AI optimized inference recommendation jobs and Amazon SageMaker AI benchmark jobs to automatically stream experiment data into a unified tracking interface.
This integration streams metrics, parameters, and charts into your serverless Amazon SageMaker MLflow App in real time and you get a unified experiment tracking experience.
Solution overview
With this release, when you submit an optimized inference recommendation job or a benchmarking job, Amazon SageMaker AI automatically streams results into a SageMaker MLflow app of your choice. Submit multiple jobs to the same MLflow experiment, and you can select them in the MLflow experiment view to compare side by side, with no manual data wrangling required.
The following diagram shows how you can set up MLflow with your benchmarking and recommendation jobs:

You follow these steps to set up MLflow with your existing recommendations and benchmarking jobs:
- Create an MLflow App: In your AWS account, open Amazon SageMaker Studio. Then go to MLflow and choose Create MLflow App.
- Grant permissions: Add sagemaker-mlflow:* on the MLflow App ARN to your job’s execution role.
- Pass MlflowConfig when creating your benchmark or recommendation job.
Benefits of this implementation
Some of the benefits of this implementation are:
Eliminate manual data consolidation: With native MLflow integration, benchmark and recommendation results from multiple jobs are consolidated under the same experiment name automatically. This removes the need to manually collect metrics, logs, and configurations across separate runs. You can then compare runs side by side to understand how instance type, model configuration, batch size, or speculative decoding affects performance. For example, you can compare qwen2-0.5b on ml.g4dn.12xlarge versus ml.p4d.24xlarge.
Monitor long-running jobs in real time: Benchmark and recommendation jobs can take hours. Rather than waiting for completion without visibility, you can now watch metrics stream live into the MLflow UI. Latency and throughput metrics update as each configuration is tested, giving you an observable process from start to finish. We publish live metrics in the metrics section, and they update over time instead of being published only at the end of the job. You can use these metrics to check whether throughput is as expected in the recommendation job and stop it early if it is not.
Maintain a complete audit trail: Experiment runs capture the full context: job parameters, timestamps, metrics at checkpoints, and emitted artifacts. This audit trail stays queryable and reproducible for months. You can trace which configuration changes drove improvements, identify performance plateaus, and revisit past decisions with full context.
Better collaboration and governance: A shared MLflow experiment becomes the single source of truth for an optimization effort. Team members can review what’s been tried, what worked, and what didn’t, which reduces duplicated effort and supports informed handoffs between shifts or team members.
Technical walkthrough: Track SageMaker AI benchmarking and recommendations in MLflow
In this example, a customer has deployed Qwen/Qwen2-0.5B-Instruct to an Amazon SageMaker AI real-time endpoint using an OpenAI-compatible serving stack on ml.g6.12xlarge. The team has two questions to answer: how the existing Qwen endpoint performs for a lightweight chatbot workload, and what configuration to use for a larger workload with longer prompts and responses.
To make the evaluation reproducible, both the benchmark job and recommendation job write metrics, parameters, and charts to the same SageMaker MLflow experiment. The benchmark job evaluates an existing SageMaker endpoint. The recommendation job evaluates deployment options for the Qwen model artifact stored in Amazon Simple Storage Service (Amazon S3) and returns ranked configurations. We will use a walkthrough notebook to show you how you can set up MLflow with both recommendations using Qwen/Qwen2-0.5B-Instruct on ml.g6.12xlarge instance for latency optimization
The end-to-end walkthrough typically takes 45–120 minutes, depending on endpoint readiness, model size, workload configuration, instance availability, and recommendation job search space.
Prerequisites
This notebook walks you through how you can set up your MLflow app for benchmark and recommendations jobs experiment tracking. You need to complete the following steps to get started with running this notebook.
- Set up Amazon SageMaker Studio for your development environment on Amazon SageMaker AI.
- Create a SageMaker MLflow App from SageMaker Unified Studio (SageMaker Unified Studio → MLflow → Create MLflow App).
- A SageMaker endpoint running an OpenAI-compatible model (already InService) for the benchmark job. You can deploy the Qwen 2 0.5B model from the Amazon SageMaker JumpStart Studio UI to get started as shown in the following diagram:
- A model artifact in Amazon S3 for the recommendation job.
- An AWS Identity and Access Management (IAM) execution role with AmazonSageMakerFullAccess plus inline policies for MLflow and endpoint invoke access. See the accompanying notebook for IAM role creation steps.
Key considerations
- This integration supports SageMaker MLflow Apps and does not stream results to self-hosted MLflow tracking servers.
- Set tooling.version to 0.8.0 or later to use MLflow nested run support.
- Recommendation jobs provision their own endpoints internally, so do not pass ComputeSpec.InstanceTypes unless you have a specific reason to constrain the search space. The execution role must include the required SageMaker, MLflow, Amazon S3, and endpoint invocation permissions. The S3 output bucket must be in the same Region as the job.
For the complete end-to-end notebook, including additional examples with AIRecommendationJob, see the step-by-step tutorial.
Step 1: Set up your environment
Start by setting your environment variables and initializing the SageMaker client.
import json
import time
import uuid
import boto3
import botocore.config
# Update these values for your environment
REGION = "us-west-2"
ACCOUNT_ID = ""
MLFLOW_APP_ARN = "arn:aws:sagemaker:us-west-2::mlflow-app/"
ENDPOINT_NAME = "my-model-endpoint"
sm = boto3.client(
"sagemaker",
region_name=REGION,
config=botocore.config.Config(
retries={"mode": "standard", "max_attempts": 15}
),
)
# The S3 output bucket must be in the same Region as the job
S3_OUTPUT_BUCKET = f"mlflow-sagemaker-{REGION}-{ACCOUNT_ID}"Step 2: Resolve the execution role
Amazon SageMaker AI uses the execution role to run the benchmark and recommendation jobs. It must have permissions to access SageMaker, invoke endpoints, write job output to Amazon S3, and publish tracking information to the SageMaker MLflow App. Follow the notebook to create the IAM roles.
The role should include the following permissions:
Permission area
Required access
SageMaker job execution
AmazonSageMakerFullAccess, or a scoped equivalent
MLflow integration
sagemaker-mlflow:*, sagemaker:CallMlflowAppApi, sagemaker:DescribeMlflowApp
Endpoint invocation
sagemaker:InvokeEndpoint, sagemaker:InvokeEndpointWithResponseStream
S3 output
Read/write access to the configured output bucket
ROLE_NAME = "tutorial-exec-role"
iam = boto3.client("iam")
role = iam.get_role(RoleName=ROLE_NAME)["Role"]
ROLE_ARN = role["Arn"]
print(f"Role ARN: {ROLE_ARN}")Configure the execution role trust policy to allow SageMaker to assume the role. In some environments, you may also need to include the account root principal depending on how the role is created and passed.
Step 3: Verify the MLflow App and define experiment names
Next, verify that the SageMaker MLflow App is available. Then define a shared experiment name and unique run names for the benchmark and recommendation jobs.
Using the same MlflowExperimentName for both jobs makes it easier to compare results in one place.
# Verify that the MLflow App is available
app = sm.describe_mlflow_app(Arn=MLFLOW_APP_ARN)
MLFLOW_APP_URL = app["Url"]
assert app["Status"] in ("Created", "Updated")
print(f"MLflow URL: {MLFLOW_APP_URL}")
# Define a shared experiment and unique run names
MLFLOW_EXPERIMENT = "gemma-experiments"
SESSION_UID = uuid.uuid4().hex[:6]
BENCH_RUN_NAME = f"benchmark-{SESSION_UID}"
REC_RUN_NAME = f"recommendation-{SESSION_UID}"Step 4: Submit the benchmark job
A SageMaker AI benchmark job evaluates an existing endpoint using a workload specification. In this example, the workload uses NVIDIA AIPerf with an OpenAI-compatible API schema.
The key field is MlflowConfig in OutputConfig. This tells SageMaker to stream benchmark metrics, parameters, and charts directly into your SageMaker MLflow App.
# Tokenizer MUST match the deployed model.
# tooling.version=0.8.0 is the minimum for MLflow nested run support.
TOKENIZER = "Qwen/Qwen2-0.5B-Instruct"
bench_workload = {
"benchmark": {"type": "aiperf"},
"parameters": {
"model": TOKENIZER,
"concurrency": 1,
"request_count": 3,
"streaming": True,
"prompt_input_tokens_mean": 32,
"prompt_input_tokens_stddev": 8,
"output_tokens_mean": 16,
"output_tokens_stddev": 4,
"random_seed": 42,
},
"tooling": {
"api_standard": "openai",
"version": "0.8.0",
},
}
BENCH_CONFIG = f"mlflow-bench-cfg-{SESSION_UID}"
BENCH_JOB = f"mlflow-bench-job-{SESSION_UID}"
sm.create_ai_workload_config(
AIWorkloadConfigName=BENCH_CONFIG,
AIWorkloadConfigs={
"WorkloadSpec": {
"Inline": json.dumps(bench_workload)
}
},
)
sm.create_ai_benchmark_job(
AIBenchmarkJobName=BENCH_JOB,
AIWorkloadConfigIdentifier=BENCH_CONFIG,
RoleArn=ROLE_ARN,
BenchmarkTarget={
"Endpoint": {
"Identifier": ENDPOINT_NAME
}
},
OutputConfig={
"S3OutputLocation": f"s3://{S3_OUTPUT_BUCKET}/mlflow-tutorial/{BENCH_JOB}/",
"MlflowConfig": {
"MlflowResourceArn": MLFLOW_APP_ARN,
"MlflowExperimentName": MLFLOW_EXPERIMENT,
"MlflowRunName": BENCH_RUN_NAME,
},
},
)
print(f"Benchmark job submitted: {BENCH_JOB}")Step 5: Submit the recommendation job
SageMaker AI recommendation jobs evaluate deployment configurations and recommend options based on your workload and performance target. Unlike benchmark jobs, recommendation jobs provision their own endpoints internally during the evaluation process.
The following example uses the same MLflow experiment name as the benchmark job, so both runs appear together in the SageMaker MLflow App.
rec_workload = {
"benchmark": {"type": "aiperf"},
"parameters": {
"prompt_input_tokens_mean": 1600,
"prompt_input_tokens_stddev": 200,
"output_tokens_mean": 600,
"output_tokens_stddev": 100,
"request_count": 100,
},
"tooling": {
"api_standard": "openai",
"version": "0.8.0",
},
}
REC_CONFIG = f"mlflow-rec-cfg-{SESSION_UID}"
REC_JOB = f"mlflow-rec-job-{SESSION_UID}"
sm.create_ai_workload_config(
AIWorkloadConfigName=REC_CONFIG,
AIWorkloadConfigs={
"WorkloadSpec": {
"Inline": json.dumps(rec_workload)
}
},
)
sm.create_ai_recommendation_job(
AIRecommendationJobName=REC_JOB,
ModelSource={
"S3": {
"S3Uri": MODEL_S3_URI
}
},
OutputConfig={
"S3OutputLocation": f"s3://{S3_OUTPUT_BUCKET}/mlflow-tutorial/{REC_JOB}/",
"MlflowConfig": {
"MlflowResourceArn": MLFLOW_APP_ARN,
"MlflowExperimentName": MLFLOW_EXPERIMENT,
"MlflowRunName": REC_RUN_NAME,
},
},
RoleArn=ROLE_ARN,
AIWorkloadConfigIdentifier=REC_CONFIG,
PerformanceTarget={
"Constraints": [
{
"Metric": "ttft-ms"
}
]
},
OptimizeModel=False,
)
print(f"Recommendation job submitted: {REC_JOB}")Step 6: Compare results in MLflow
After the jobs complete, open the SageMaker MLflow App and navigate to the experiment you configured. The following code gives you the URL to your MLflow app in the notebook.
print(f"Open: {MLFLOW_APP_URL}")In the experiment view, the parent runs are empty placeholders that exist to show relationships between child runs. You need to expand each parent run to view the nested metrics.
benchmark- -> Single run with AIPerf benchmark metrics
recommendation- -> Nested run tree with ranked recommendation configurationsThe child runs contain the model metrics. To review recommendation job metrics, go to the MLflow Runs page, expand the recommendation job parent run, and then expand the nested child runs until the concurrency rows are visible. The benchmark metrics appear in the Metrics columns for each concurrency run as shown in the following diagram:

To inspect recommendations artifacts, open the Concurrency=4 run and choose the Artifacts tab. In the artifact file tree, expand exports and select outputs.json. The preview panel shows the artifact file path and JSON output, including request-level fields such as session ID, request timing, output token count, request latency, and response text as shown in the following diagram:

On the Runs page, select the benchmark runs you want to compare, such as the Concurrency=32, Concurrency=16, Concurrency=8, and Concurrency=4 rows. Choose Compare to view metric differences across duration, throughput, output token count, and request latency as shown in the following diagram:

In the Metrics section, use the Show diff only toggle to view only changed metrics. The table compares benchmark metrics such as benchmark duration and end-to-end output token throughput across the selected benchmark or recommendation job results as shown in the following diagram:

Clean up resources
To avoid ongoing charges, delete the resources y
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み