Nova 2.0 をファインチューニングする - Amazon SageMaker AI

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

Nova 2.0 をファインチューニングする

前提条件

トレーニングジョブを始める前に、以下の要件を確認してください。

  • トレーニングジョブの入力データと出力を格納する Amazon S3 バケット。両方に 1 つのバケットを使用することも、データタイプごとに個別のバケットを使用することもできます。バケットがトレーニング用の他のすべてのリソースを作成する AWS リージョン のと同じ にあることを確認します。詳細については、「汎用バケットの作成」を参照してください。

  • トレーニングジョブを実行するアクセス許可がある IAM ロール。必ず IAM ポリシーを AmazonSageMakerFullAccess にアタッチしてください。詳細については、「SageMaker 実行ロールの使用方法」を参照してください。

  • Amazon Nova の基本レシピについては、「Amazon Nova レシピの取得」を参照してください。

SFT とは

教師ありファインチューニング (SFT) は、ラベル付き入出力ペアを使用して言語モデルをトレーニングします。このモデルは、プロンプトとレスポンスで構成されるデモンストレーションの例から学習し、特定のタスク、指示、または望ましい動作に合わせて機能を改善します。

データ準備

概要:

Nova 2.0 SFT データは、Nova 1.0 と同じ Converse API 形式を使用し、オプションの推論コンテンツフィールドが追加されています。完全な形式の仕様については、以下を参照してください。

サポートされている機能

  • 入力タイプ – ユーザーコンテンツブロック内のテキスト、イメージ、またはビデオ

  • アシスタントコンテンツ – テキストのみのレスポンスと推論コンテンツ

  • データセット構成 – 同種である必要があります。オプションのいずれかを選択します。

    • テキストのみのターン

    • テキスト + イメージのターン

    • テキスト + ビデオのターン (ドキュメントの理解をサポート)

重要

同じデータセット内または異なるターン間でイメージと動画を混在させることはできません。

現在の制限事項

  • マルチモーダル推論コンテンツ – Converse 形式は画像ベースの推論コンテンツをサポートしていますが、Nova 2.0 SFT は reasoningText フィールドのテキストベースの推論コンテンツのみをサポートしています。

  • 検証セット – Nova 2.0 で SFT の検証データセットを指定することはできません。検証データセットを指定すると、トレーニング中は無視されます。この制限は、UI ベースのジョブ送信とプログラムによるジョブ送信の両方に適用されます。

サポートされているメディア形式

  • イメージ – PNG、JPEG、GIF

  • 動画 – MOV、MKV、MP4

データ形式の例

Text-only (Nova 1.0 compatible)
{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a digital assistant with a friendly personality" } ], "messages": [ { "role": "user", "content": [ { "text": "What country is right next to Australia?" } ] }, { "role": "assistant", "content": [ { "text": "The closest country is New Zealand" } ] } ] }
Text with reasoning (Nova 2.0)
{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a digital assistant with a friendly personality" } ], "messages": [ { "role": "user", "content": [ { "text": "What country is right next to Australia?" } ] }, { "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "I need to use my world knowledge of geography to answer this question" } } }, { "text": "The closest country to Australia is New Zealand, located to the southeast across the Tasman Sea." } ] } ] }
Image + text input
{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a helpful assistant." } ], "messages": [ { "role": "user", "content": [ { "image": { "format": "jpeg", "source": { "s3Location": { "uri": "s3://your-bucket/your-path/your-image.jpg", "bucketOwner": "your-aws-account-id" } } } }, { "text": "Which country is highlighted in the image?" } ] }, { "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "I will determine the highlighted country by examining its location on the map and using my geographical knowledge" } } }, { "text": "The highlighted country is New Zealand" } ] } ] }
Video + text input
{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a helpful assistant." } ], "messages": [ { "role": "user", "content": [ { "video": { "format": "mp4", "source": { "s3Location": { "uri": "s3://your-bucket/your-path/your-video.mp4", "bucketOwner": "your-aws-account-id" } } } }, { "text": "What is shown in this video?" } ] }, { "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "I will analyze the video content to identify key elements" } } }, { "text": "The video shows a map with New Zealand highlighted" } ] } ] }

ツール呼び出し

Nova 2.0 SFT は、ツール呼び出しパターンに関するモデルのトレーニングをサポートしているため、モデルは外部ツールまたは関数をいつ、どのように呼び出すかを学習できます。

ツール呼び出しのデータ形式

ツール呼び出しトレーニングデータには、使用可能なツールを定義するtoolConfigセクションと、ツールの使用パターンを示す会話ターンが含まれます。

サンプル入力

{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are an expert in composing function calls." } ], "toolConfig": { "tools": [ { "toolSpec": { "name": "getItemCost", "description": "Retrieve the cost of an item from the catalog", "inputSchema": { "json": { "type": "object", "properties": { "item_name": { "type": "string", "description": "The name of the item to retrieve cost for" }, "item_id": { "type": "string", "description": "The ASIN of item to retrieve cost for" } }, "required": [ "item_id" ] } } } }, { "toolSpec": { "name": "getItemAvailability", "description": "Retrieve whether an item is available in a given location", "inputSchema": { "json": { "type": "object", "properties": { "zipcode": { "type": "string", "description": "The zipcode of the location to check in" }, "quantity": { "type": "integer", "description": "The number of items to check availability for" }, "item_id": { "type": "string", "description": "The ASIN of item to check availability for" } }, "required": [ "item_id", "zipcode" ] } } } } ] }, "messages": [ { "role": "user", "content": [ { "text": "I need to check whether there are twenty pieces of the following item available. Here is the item ASIN on Amazon: id-123. Please check for the zipcode 94086" } ] }, { "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "The user wants to check how many pieces of the item with ASIN id-123 are available in the zipcode 94086" } } }, { "toolUse": { "toolUseId": "getItemAvailability_0", "name": "getItemAvailability", "input": { "zipcode": "94086", "quantity": 20, "item_id": "id-123" } } } ] }, { "role": "user", "content": [ { "toolResult": { "toolUseId": "getItemAvailability_0", "content": [ { "text": "[{\"name\": \"getItemAvailability\", \"results\": {\"availability\": true}}]" } ] } } ] }, { "role": "assistant", "content": [ { "text": "Yes, there are twenty pieces of item id-123 available at 94086. Would you like to place an order or know the total cost?" } ] } ] }

ツール呼び出しの要件

トレーニングデータを呼び出すツールを作成するときは、次の要件に従ってください。

要件 説明
ToolUse 配置 ToolUse はアシスタントターンにのみ表示する必要があります
ToolResult の配置 ToolResult はユーザーのターンにのみ表示する必要があります
ToolResult 形式 ToolResult はテキストまたは JSON のみである必要があります。Nova モデルでは他のモダリティはサポートされていません
inputSchema 形式 toolSpec 内の inputSchema は有効な JSON Schema オブジェクトである必要があります
toolUseId マッチング 各 ToolResult は、前述のアシスタント toolUseIdの有効な ToolUse を参照し、各 toolUseId は会話ごとに 1 回だけ使用する必要があります。

重要な注意事項

  • ツール定義がすべてのトレーニングサンプルで一貫していることを確認する

  • このモデルは、提供したデモンストレーションからツール呼び出しパターンを学習します。

  • 各ツールを使用するタイミングと使用しないタイミングのさまざまな例を含める

ドキュメント理解

Nova 2.0 SFT はドキュメントベースのタスクのトレーニングをサポートしているため、モデルは PDF ドキュメントに関する質問を分析して回答する方法を学習できます。

ドキュメントを理解するためのデータ形式

ドキュメントの理解トレーニングデータには、ユーザーコンテンツブロックのドキュメント参照が含まれ、モデル学習ではドキュメントコンテンツを抽出し、その理由を説明します。

サンプル入力

{ "schemaVersion": "bedrock-conversation-2024", "messages": [ { "role": "user", "content": [ { "text": "What are the ways in which a customer can experience issues during checkout on Amazon?" }, { "document": { "format": "pdf", "source": { "s3Location": { "uri": "s3://my-bucket-name/path/to/documents/customer_service_debugging.pdf", "bucketOwner": "123456789012" } } } } ] }, { "role": "assistant", "content": [ { "text": "Customers can experience issues with 1. Data entry, 2. Payment methods, 3. Connectivity while placing the order. Which one would you like to dive into?" } ], "reasoning_content": [ { "text": "I need to find the relevant section in the document to answer the question.", "type": "text" } ] } ] }

ドキュメント理解の制限事項

制限 Details
サポートされている形式 PDF ファイルのみ
最大ドキュメントサイズ 10 MB
モダリティミキシング サンプルにはドキュメントとテキストを含めることができますが、ドキュメントを他のモダリティ (イメージ、ビデオ) と混在させることはできません。

ドキュメントを理解するためのベストプラクティス

  • ドキュメントが明確にフォーマットされ、テキストが抽出可能であることを確認する

  • さまざまなドキュメントタイプと質問形式をカバーするさまざまな例を提供する

  • モデルがドキュメント分析パターンを学習するのに役立つ推論コンテンツを含める

動画理解

Nova 2.0 SFT はビデオベースのタスクのトレーニングをサポートし、モデルがビデオコンテンツに関する質問を分析して応答する方法を学習できるようにします。

動画理解のためのデータ形式

ビデオ理解トレーニングデータには、ユーザーコンテンツブロック内のビデオ参照が含まれ、モデル学習はビデオコンテンツに関する情報と理由を抽出します。

サンプル入力

{ "schemaVersion": "bedrock-conversation-2024", "messages": [ { "role": "user", "content": [ { "text": "What are the ways in which a customer can experience issues during checkout on Amazon?" }, { "video": { "format": "mp4", "source": { "s3Location": { "uri": "s3://my-bucket-name/path/to/videos/customer_service_debugging.mp4", "bucketOwner": "123456789012" } } } } ] }, { "role": "assistant", "content": [ { "text": "Customers can experience issues with 1. Data entry, 2. Payment methods, 3. Connectivity while placing the order. Which one would you like to dive into?" } ], "reasoning_content": [ { "text": "I need to find the relevant section in the video to answer the question.", "type": "text" } ] } ] }

動画理解の制限事項

制限 Details
最大ビデオサイズ 50MB
最大動画再生時間 15 分
サンプルあたりの動画 サンプルごとに許可される動画は 1 つだけです。同じサンプル内の複数の動画はサポートされていません
モダリティミキシング サンプルには動画とテキストを含めることができますが、動画を他のモダリティ (画像、ドキュメント) と組み合わせることはできません。

サポートされているビデオ形式

  • MOV

  • MKV

  • MP4

動画理解のベストプラクティス

  • ビデオを簡潔に保ち、タスクに関連するコンテンツに集中させる

  • モデルが意味のある情報を抽出するのに動画の品質が十分であることを確認する

  • 動画コンテンツの特定の側面を参照する明確な質問を提供する

  • さまざまな動画タイプと質問形式をカバーするさまざまな例を含める

推論モードと非推論モード

推論コンテンツについて

推論コンテンツ (chain-of-thought) は、最終的な回答を生成する前にモデルの中間思考ステップをキャプチャします。次にassistantreasoningContentフィールドを使用して、これらの推論トレースを含めます。

損失の計算方法

  • 推論コンテンツを使用 – トレーニング損失には、推論トークンと最終出力トークンの両方が含まれます。

  • 推論コンテンツなし – トレーニング損失は最終的な出力トークンでのみ計算されます

マルチターン会話では、複数のアシスタントターンreasoningContentにまたがって を含めることができます。

フォーマットガイドライン

  • 推論コンテンツにプレーンテキストを使用する

  • タスクで特に必要な場合</thinking>を除いて、 <thinking>や などのマークアップタグは避けてください。

  • 推論の内容が明確で、問題解決プロセスに関連していることを確認する

推論モードを有効にするタイミング

次の場合にトレーニング設定reasoning_enabled: trueで を設定します。

  • トレーニングデータに推論トークンがある

  • 最終的な出力を生成する前に、モデルで思考トークンを生成したい

  • 複雑な推論タスクのパフォーマンスを向上させる必要がある

で理由のないデータセットで Nova をトレーニングすることは許可reasoning_enabled = trueされています。ただし、Nova は主に推論を適用せずにデータに表示されるレスポンスを生成することを学習するため、モデルが推論機能を失う可能性があります。理由のないデータセットで Nova をトレーニングしたいが、推論中に推論を期待する場合は、トレーニング中に推論を無効にし (reasoning_enabled = false)、推論のために有効にすることができます。このアプローチでは推論時に推論を使用できますが、推論を使用しない場合と比較してパフォーマンスの向上は保証されません。一般的に、推論データセットを使用する場合はトレーニングと推論の両方の推論を有効にし、理由のないデータセットを使用する場合は両方の推論を無効にします。

次のreasoning_enabled: false場合に を設定します。

  • トレーニングデータに推論トークンがない

  • 明示的な推論ステップの恩恵を受けない単純なタスクをトレーニングしている

  • 速度を最適化し、トークン使用量を削減したい

推論データの生成

データセットに推論トレースがない場合は、Nova Premier のような推論可能なモデルを使用して作成できます。入力と出力のペアをモデルに提供し、推論プロセスを取得して推論拡張データセットを構築します。

トレーニングに推論トークンを使用する

推論モードを有効にしてトレーニングすると、モデルは内部推論を最終回答から分離することを学習します。トレーニングプロセス:

  • 入力、推論、回答のデータをトリプルとして整理します

  • 推論トークンと回答トークンの両方からの標準次トークン予測損失を使用して最適化

  • レスポンスを生成する前に、モデルに内部的に理由を説明するよう促します

効果的な推論コンテンツ

高品質の推論コンテンツには、以下を含める必要があります。

  • 中間的な思考と分析

  • 論理的な控除と推論ステップ

  • Step-by-stepの問題解決アプローチ

  • ステップと結論の明示的な関係

これは、モデルが「回答する前に考える」能力を開発するのに役立ちます。

データセット準備ガイドライン

サイズと品質

  • 推奨サイズ – 2,000~10,000 サンプル

  • 最小サンプル – 200

  • Priority – 数量よりも品質。例が正確で注釈が付いていることを確認します。

  • アプリケーションの連携 — データセットは本番稼働用ユースケースを厳密に反映する必要があります。

多様性

次のようなさまざまな例を含めます。

  • 予想される入力の全範囲をカバーする

  • さまざまな難易度を表す

  • エッジケースとバリエーションを含める

  • パターンを絞り込むためのオーバーフィットの防止

出力フォーマット

アシスタントレスポンスで必要な出力形式を明確に指定します。

  • JSON の構造

  • テーブル

  • CSV 形式

  • アプリケーションに固有のカスタム形式

マルチターンの会話

マルチターンデータセットの場合、次の点に注意してください。

  • 損失は、ユーザーのターンではなく、アシスタントのターンでのみ計算されます。

  • 各アシスタントレスポンスは適切にフォーマットする必要があります

  • 会話のターン全体で一貫性を維持する

品質チェックリスト

  • 十分なデータセットサイズ (2K~10K サンプル)

  • すべてのユースケースをカバーするさまざまな例

  • 明確で一貫した出力フォーマット

  • 正確なラベルと注釈

  • 本番シナリオの代表者

  • 矛盾やあいまいさがない

データのアップロード

データセットは、SageMaker トレーニングジョブがアクセスできるバケットにアップロードする必要があります。適切なアクセス許可の設定については、「前提条件」を参照してください。

トレーニングジョブの開始

ハイパーパラメータの選択とレシピの更新

Nova 2.0 のセットアップは、Nova 1.0 のセットアップとほぼ同じです。入力データが S3 にアップロードされたら、ファインチューニングフォルダの SageMaker Hyperpod Recipes のレシピを使用します。Nova 2.0 では、ユースケースに基づいて更新できる主要なハイパーパラメータの一部を以下に示します。以下は、Nova 2.0 SFT PEFT レシピの例です。

Nova トレーニングとの厳密な互換性のために、SageMaker PySDK の v2.254.1 を使用してください。SDK を v3.0 バージョンにアップグレードすると、重大な変更が発生します。SageMaker PySDK の v3 のサポートは間もなく開始されます。

サンプル入力

!pip install sagemaker==2.254.1
run: name: {peft_recipe_job_name} model_type: amazon.nova-2-lite-v1:0:256k model_name_or_path: {peft_model_name_or_path} data_s3_path: {train_dataset_s3_path} # SageMaker Hyperpod (SMHP) only and not compatible with SageMaker Training jobs. Note replace my-bucket-name with your real bucket name for SMHP job replicas: 4 # Number of compute instances for training, allowed values are 4, 8, 16, 32 output_s3_path: "" # Output artifact path (Hyperpod job-specific; not compatible with standard SageMaker Training jobs). Note replace my-bucket-name with your real bucket name for SMHP job training_config: max_steps: 10 # Maximum training steps. Minimal is 4. save_steps: 10 # How many training steps the checkpoint will be saved. Should be less than or equal to max_steps save_top_k: 1 # Keep top K best checkpoints. Note supported only for SageMaker HyperPod jobs. Minimal is 1. max_length: 32768 # Sequence length (options: 8192, 16384, 32768 [default], 65536) global_batch_size: 32 # Global batch size (options: 32, 64, 128) reasoning_enabled: true # If data has reasoningContent, set to true; otherwise False lr_scheduler: warmup_steps: 15 # Learning rate warmup steps. Recommend 15% of max_steps min_lr: 1e-6 # Minimum learning rate, must be between 0.0 and 1.0 optim_config: # Optimizer settings lr: 1e-5 # Learning rate, must be between 0.0 and 1.0 weight_decay: 0.0 # L2 regularization strength, must be between 0.0 and 1.0 adam_beta1: 0.9 # Exponential decay rate for first-moment estimates, must be between 0.0 and 1.0 adam_beta2: 0.95 # Exponential decay rate for second-moment estimates, must be between 0.0 and 1.0 peft: # Parameter-efficient fine-tuning (LoRA) peft_scheme: "lora" # Enable LoRA for PEFT lora_tuning: alpha: 64 # Scaling factor for LoRA weights ( options: 32, 64, 96, 128, 160, 192), lora_plus_lr_ratio: 64.0

レシピには、Nova 1.0 とほぼ同じハイパーパラメータも含まれています。注目すべきハイパーパラメータは次のとおりです。

  • max_steps – ジョブを実行するステップの数。通常、1 つのエポック (データセット全体で 1 回実行) の場合、ステップ数 = データサンプル数/グローバルバッチサイズ。ステップ数が大きく、グローバルバッチサイズが小さいほど、ジョブの実行に時間がかかります。

  • reasoning_enabled – データセットの推論モードを制御します。オプション:

    • true: 推論モードを有効にします (高推論に相当)

    • false: 推論モードを無効にします

    注: SFT の場合、推論の労力レベルをきめ細かく制御することはできません。を設定すると、完全な推論機能reasoning_enabled: trueが有効になります。

  • peft.peft_scheme – これを「lora」に設定すると、PEFT ベースのファインチューニングが有効になります。null (引用符なし) に設定すると、フルランクのファインチューニングが有効になります。

トレーニングジョブを開始する

from sagemaker.pytorch import PyTorch # define OutputDataConfig path if default_prefix: output_path = f"s3://{bucket_name}/{default_prefix}/{sm_training_job_name}" else: output_path = f"s3://{bucket_name}/{sm_training_job_name}" output_kms_key = "<KMS key arn to encrypt trained model in Amazon-owned S3 bucket>" # optional, leave blank for Amazon managed encryption recipe_overrides = { "run": { "replicas": instance_count, # Required "output_s3_path": output_path }, } estimator = PyTorch( output_path=output_path, base_job_name=sm_training_job_name, role=role, disable_profiler=True, debugger_hook_config=False, instance_count=instance_count, instance_type=instance_type, training_recipe=training_recipe, recipe_overrides=recipe_overrides, max_run=432000, sagemaker_session=sagemaker_session, image_uri=image_uri, output_kms_key=output_kms_key, tags=[ {'Key': 'model_name_or_path', 'Value': model_name_or_path}, ] ) print(f"\nsm_training_job_name:\n{sm_training_job_name}\n") print(f"output_path:\n{output_path}")
from sagemaker.inputs import TrainingInput train_input = TrainingInput( s3_data=train_dataset_s3_path, distribution="FullyReplicated", s3_data_type="Converse", ) estimator.fit(inputs={"validation": val_input}, wait=False)
注記

検証データセットの受け渡しは、Nova 2.0 の教師ありファインチューニングではサポートされていません。

ジョブを開始するには:

  • データセットパスとハイパーパラメータを使用してレシピを更新する

  • ノートブックで指定されたセルを実行してトレーニングジョブを送信する

ノートブックはジョブの送信を処理し、ステータスの追跡を提供します。