

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

# プロファイラーの可用性の変更
<a name="profiler-availability-change"></a>

**注記**  
サポート終了通知: 2027 年 6 月 30 日に、 AWS は Amazon SageMaker Profiler のサポートを終了します。2027 年 6 月 30 日以降、プロファイラーコンソールまたはプロファイラーリソースにアクセスできなくなります。

## Amazon SageMaker Profiler の置き換え
<a name="profiler-replacing"></a>

現在 SageMaker Profiler を使用している場合は、このガイダンスに従って代替サービスに移行します。

## 概要
<a name="profiler-overview"></a>

Amazon SageMaker Profiler は、カーネル実行、カーネル起動、同期オペレーション、メモリオペレーション、CPU 開始起動と GPU カーネル実行の間のレイテンシーなど、トレーニング中の GPU および CPU アクティビティを詳細に可視化しました。このガイドでは、既存のプロファイラー設定を削除し、パフォーマンス診断をトレーニングするためにフレームワークネイティブプロファイラー、TensorBoard、Amazon CloudWatch を採用する方法について説明します。

PyTorch および TensorFlow ワークロードの場合、フレームワークネイティブプロファイラーと TensorBoard の組み合わせにより、オープンソースエコシステムへの直接統合による同等のカーネルレベルの可視性が提供されます。Amazon CloudWatch は、設定可能なアラームによるシステムレベルのリソースモニタリングを提供します。これらのツールを組み合わせることで、SageMaker Profiler のトレーニングパフォーマンス診断に代わる方法が提供されます。

## 機能マッピング
<a name="profiler-capability-mapping"></a>


| プロファイラー機能 | 置換後の値 | 
| --- | --- | 
| GPU カーネルトレース、CPU/GPU 使用率、同期分析、カーネルlaunch-to-execution  | PyTorch Profiler / TensorFlow Profiler \+ TensorBoard | 
| データローダーと入力パイプラインのプロファイリング | フレームワークプロファイラー \+ TensorBoard | 
| システムリソースのモニタリング (CPU、GPU、メモリ、ディスク) | Amazon CloudWatch | 
| カスタムオペレーションの注釈 | Framework Profiler の注釈 | 
| プロファイラー UI タイムラインの視覚化 | TensorBoard プロファイラープラグイン | 

## ステップ 1: プロファイラー設定を削除する
<a name="profiler-step1-remove"></a>

### トレーニングスクリプトから smprof 注釈を削除する
<a name="profiler-remove-smprof"></a>

トレーニングスクリプトで SageMaker Profiler Python モジュール (`smprof` または以前の `smppy`) を使用している場合は、以下を削除します。
+ `import smprof`\+ または `import smppy as smprof`-
+ `SMProfiler.instance()`, `SMProf.configure()`, `SMProf.start_profiling()`, `SMProf.stop_profiling()`
+ すべての`smprof.annotate()`コンテキストマネージャーと / `smprof.annotation_begin()` `smprof.annotation_end()`呼び出し

### トレーニング設定から ProfilerConfig を削除する
<a name="profiler-remove-config"></a>

SageMaker トレーニング設定から `profiler_config`パラメータを削除します。

```
# Remove this configuration
# V2
from sagemaker import ProfilerConfig, Profiler

profiler_config = ProfilerConfig(
    profile_params = Profiler(cpu_profiling_duration=3600)
)

# V3
from sagemaker.core.debugger.profiler_config import ProfilerConfig
from sagemaker.core.debugger.profiler import Profiler
```

### Amazon S3 でプロファイラー出力を削除する
<a name="profiler-delete-s3-output"></a>

SageMaker Profiler は、トレーニングジョブの`rule-output`パスの下にプロファイルデータを保存しました。

```
s3://<output-path>/<training-job-name>/rule-output/
```

履歴プロファイリングデータが不要になった場合は、このプレフィックスを削除します。トレーニングジョブログとモデルアーティファクトは影響を受けません。

### SageMaker Profiler Python パッケージを削除する (手動でインストールされている場合)
<a name="profiler-remove-package"></a>

`smprof` パッケージを `requirements.txt`またはカスタム Docker コンテナに追加した場合は、 を参照する行をすべて削除します`smppy.s3.amazonaws.com`。

### CloudWatch ロググループを削除する (オプション)
<a name="profiler-delete-cloudwatch-logs"></a>

でプロファイラールール処理によって作成された CloudWatch ロググループを確認します`/aws/sagemaker/ProcessingJobs`。ストレージコストを削減する必要がなくなった場合は、これらを削除します。

### IAM ポリシーを確認する
<a name="profiler-review-iam"></a>

プロファイラーの使用専用のアクセス許可を付与した IAM ポリシーを削除します。
+ `s3:GetObject` / `s3:PutObject`プロファイラーのルール出力パスの範囲
+ プロファイラーのサポートのみを目的としてトレーニングジョブにアタッチされたロール

トレーニングジョブまたは CloudWatch モニタリングに必要なポリシーを保持します。

### 依存オートメーションを無効にする
<a name="profiler-disable-automation"></a>

Profiler 出力を消費したオートメーションを更新または削除します。
+ Profiler データを処理した Step Functions ワークフロー
+ Profiler 出力によってトリガーされる Amazon EventBridge ルール
+ プロファイラー S3 パスから読み取るトレーニング後のプロセッサ

## ステップ 2: 置き換えを設定する
<a name="profiler-step2-configure"></a>

### フレームワークレベルのプロファイリングを有効にする
<a name="profiler-enable-framework"></a>

フレームワークの組み込みプロファイラーを使用するようにトレーニングスクリプトを更新します。PyTorch プロファイラーと TensorFlow プロファイラーはどちらも TensorBoard と直接統合され、タイムラインビュー、カーネル統計、パフォーマンスレコメンデーションなどの視覚化が可能です。

**PyTorch:**

```
import torch
from torch.profiler import profile, schedule, tensorboard_trace_handler

with profile(
    activities=[torch.profiler.ProfilerActivity.CPU, torch.profiler.ProfilerActivity.CUDA],
    schedule=schedule(wait=1, warmup=1, active=3, repeat=1),
    on_trace_ready=tensorboard_trace_handler("./tensorboard/logs"),
    record_shapes=True,
    profile_memory=True,
    with_stack=True
) as prof:
    for step, batch in enumerate(train_loader):
        inputs, labels = batch
        outputs = model(inputs)
        loss = criterion(outputs, labels)
        loss.backward()
        optimizer.step()
        prof.step()
```

特定のオペレーションに注釈を付けるには ( を置き換える`smprof.annotate()`):

```
with torch.profiler.record_function("forward_pass"):
    outputs = model(inputs)

with torch.profiler.record_function("backward_pass"):
    loss.backward()
```

**TensorFlow:**

```
import tensorflow as tf

tf.profiler.experimental.start("./tensorboard/logs")
model.fit(train_dataset, epochs=5)
tf.profiler.experimental.stop()
```

**注記**  
SageMaker Profiler と同様に、トレーニングジョブ全体のプロファイリングはお勧めしません。オーバーヘッドを最小限に抑えるために、ステップの代表的なサブセット (数百まで) をプロファイリングします。

### TensorBoard で視覚化する
<a name="profiler-visualize-tensorboard"></a>

TensorBoard を起動して、プロファイリング結果、実行タイムライン、パフォーマンスに関する推奨事項を表示します。

```
tensorboard --logdir=./tensorboard/logs
```

TensorBoard Profiler プラグインは、SageMaker Profiler UI と同等の GPU カーネルタイムラインと、カーネル統計、実行概要、入力パイプライン分析、パフォーマンスレコメンデーションを提供します。SageMaker AI のマネージド TensorBoard については、[Amazon SageMakerの TensorBoard](https://docs.aws.amazon.com/sagemaker/latest/dg/tensorboard-on-sagemaker.html)」を参照してください。Managed TensorBoard には SageMaker ドメインが必要で、一部のリージョンで利用できます。

### システムモニタリングとアラートに Amazon CloudWatch を使用する
<a name="profiler-cloudwatch"></a>

Amazon CloudWatch は、CPU、GPU、メモリ、ディスクなどのトレーニングジョブのリソース使用率メトリクスをリアルタイムでキャプチャします。また、リソースのボトルネック、使用率の低さ、予期しないスパイクを検出するための設定可能なアラーム、トレーニング実行全体でシステムメトリクスを組み合わせたダッシュボードをサポートしています。詳細な手順については、[Amazon CloudWatch Metrics for Monitoring and Analyzing Training Jobs](https://docs.aws.amazon.com/sagemaker/latest/dg/training-metrics.html)」を参照してください。または、トレーニングスクリプトから MLflow に直接システムパフォーマンスメトリクスを記録して、実験メトリクスとともに統合追跡することもできます。

## 既存のデータの処理
<a name="profiler-existing-data"></a>
+ **S3 のトレーニングログとアーティファクト** – トレーニングジョブの出力とモデルアーティファクトは引き続きアクセスできます。これらはプロファイラーから独立しています。
+ **プロファイラートレースデータ** – 履歴プロファイリングデータは、削除する`rule-output/`まで の S3 に残ります。
+ **CloudWatch メトリクス** – CloudWatch に既に存在する履歴システムメトリクスは、アカウントの[保持設定](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html#SettingLogRetention)に従って保持されます。