ベースモデル(基礎となるAIモデル)をSageMaker(AWSが提供する機械学習サービス)のサーバーレストレーニングジョブ(構築・管理の手間をかけず実行される学習タスク)で調整するためのコードを生成します。 次のような場合に使用:ユーザーが「学習を開始する」「自分のモデルを調整したい」「学習の準備ができた」と述べた場合、または計画が調整段階に到達した場合 SFT(教師あり学習)、DPO(直接選好最適化)、RLVR、RLAIF(アルゴリズムによる学習強化)といった複数のトレーナー(学習エンジン)に対応しており、RLVR用の報酬関数とRAIAI用のカスタムプロンプト生成も含まれます。
Generates code that fine-tunes a base model using SageMaker serverless training jobs. Use when the user says "start training", "fine-tune my model", "I'm ready to train", or when the plan reaches the finetuning step. Supports SFT, DPO, RLVR, and RLAIF trainers, including RLVR Lambda reward function and RLAIF custom prompt creation.
このワークフローを開始する前に、以下を確認してください:
use_case_spec.md ファイルが存在すること
use-case-specification スキルを起動してから再開してくださいuse-case-specification スキルを起動せずに、ユースケース仕様の作成を提案してはいけません。ファインチューニング手法(SFT、DPO、RLVR、RLAIF、またはCPT/RFT(Nova向け))とベースモデルがすでに選択されていること
model-selection および/または finetuning-technique スキルを起動して不足情報を収集し、その後再開してくださいSageMakerHub で利用可能なベースモデル名が特定されていること
model-selection スキルを起動して取得してくださいmodel-selection が取得したモデル名のみを使用してください。同じモデルの一般的な名称とは異なる場合があります。SDK 環境が検証済みであること(SDKバージョン、リージョン、実行ロール)
sdk-getting-started スキルを起動してから再開してくださいトレーニングデータセットが、環境のデフォルトリージョンのバケットにアップロードされていること
ACCEPT_EULA を True に設定しないrun_cell が利用可能な場合は実行を提案する。利用できない場合は、セルを1つずつ実行するよう伝える(ipykernel が必要である旨も明記する)。python3 <スクリプト名>.py で実行するよう伝える⏸ ユーザーの応答を待つ。
references/code_output_guide.md を読んで出力フォーマットのルールを確認し、次にファインチューニング手法に対応するコードテンプレートを読む:
code_templates/sft.pycode_templates/dpo.pycode_templates/rlvr.pycode_templates/rlaif_builtin.pycode_templates/rlaif_custom_prompt.pyテンプレートは Python ファイルであり、各 # Cell N: Label コメントが新しいセクションの開始を示す。
このマーカーで分割し、あるマーカーから次のマーカーまでの内容を1つの出力単位とする。
code_output_guide.md のルールに従い、テンプレートからコードを記述するmeta- で始まらない場合):
ACCEPT_EULA = False の行を省略するaccept_eula=ACCEPT_EULA, の行を省略するmax_epochs または lr_warmup_steps_ratio を含むコードを省略する「Setup & Credentials」セルに以下を設定する:
BASE_MODEL
MODEL_PACKAGE_GROUP_NAME
use_case_spec.md を参照する)[a-zA-Z0-9](-*[a-zA-Z0-9]){0,62}customer-support-chatbot-v1ノートブックを保存する
references/rlvr_reward_function.md の「Helping Users Create Custom Reward Functions」セクションのワークフローに従うCUSTOM_REWARD_FUNCTION に、リワード関数の ARN を設定する(ユーザーから直接提供された ARN、または関数生成コードの evaluator.arn から取得した ARN)。references/rlaif_guide.md を読み、その指示に従う。
references/eula_links.md から選択したベースモデルの公式ライセンスリンクを調べるreferences/eula_links.md の表現に従い、ライセンスをユーザーに提示する。
OSS モデルの場合: 「このモデルは {License} の下でライセンスされています。ライセンス条項をこちらでご確認ください: {URL}」
Nova モデルの場合: 「このモデルは AWS サービス利用規約が適用されます: {URL}」meta- で始まるかどうか)
ACCEPT_EULA = True に設定し、生成されたノートブックの accept_eula=ACCEPT_EULA をアンコメントする。ユーザーが拒否した場合は ACCEPT_EULA = False のままにし、同意なしではトレーニングが失敗することを警告する。ACCEPT_EULA 変数と accept_eula パラメータはすでにノートブックから省略されているはず(ステップ 1.3 参照)。コードの生成後、実行を提案する。データセットやモデルによっては、トレーニングに数時間かかる場合があります。
ノートブックモード: run_cell が利用可能な場合は、セルの実行を提案する。利用できない場合は、ユーザー自身でセルを実行するよう伝える。
スクリプトモード: 以下の選択肢をユーザーに提示する:
「次のいずれかを選択してください:
- ご自身で実行する —
python scripts/[スクリプト名]で実行してください- 実行して完了まで待機する
- 実行を開始するが待機しない — ステータスは後で確認できます」
trainer.train(wait=True) は完了までブロックする。最終ステータスを報告する。wait=True を wait=False に変更し、実行してトレーニングジョブ名を報告する。ステータス確認:
describe-training-job --training-job-name NAME → TrainingJobStatus、FailureReason、SecondaryStatusTransitionslist-model-packages --model-package-group-name GROUP_NAME --sort-by CreationTime --sort-order Descending --max-results 1完了後の結果表示:
scripts/mlflow_reference.py をパターンとして MLflow メトリクスをクエリする重要:
すでにカスタマイズされたモデルをさらにファインチューニングしたい場合は、references/continuous_customization.md の手順に従う
rlvr_reward_function.md — Lambda リワード関数の作成ガイド(RLVR のみ)templates/rlvr_reward_function_source_template.py — オープンウェイトモデル向け Lambda リワード関数ソーステンプレート(RLVR のみ)templates/nova_rlvr_reward_function_source_template.py — Nova 2.0 Lite 向け Lambda リワード関数ソーステンプレート(RLVR のみ)code_templates/sft.py — 教師ありファインチューニング(SFT)の完全なノートブックテンプレート(OSS パス)code_templates/dpo.py — Direct Preference Optimization(DPO)の完全なノートブックテンプレート(OSS パス)code_templates/rlvr.py — 検証可能なリワードによる強化学習(RLVR)の完全なノートブックテンプレート(OSS パス)references/continuous_customization.md — すでにファインチューニング済みのモデルをさらにファインチューニングする手順rlaif_guide.md — RLAIF ファインチューニングオプションに関する手順rlaif_builtin.py — 組み込みジャッジプロンプトを使用する RLAIF のコードテンプレートrlaif_custom_prompt.py — カスタムジャッジプロンプトを使用する RLAIF のコードテンプレートBefore starting this workflow, verify:
A use_case_spec.md file exists
use-case-specification skill first, then resumeA fine-tuning technique (SFT, DPO, RLVR, RLAIF, or CPT/RFT (for Nova)) and base model have already been selected
model-selection and/or finetuning-technique skills to collect what's missing, then resumeA base model name available on SageMakerHub has been identified
model-selection skill to get itmodel-selection retrieves, as it may differ from other commonly used names for the same modelThe SDK environment has been verified (SDK version, region, execution role)
sdk-getting-started skill first, then resumeA training dataset uploaded to a bucket in the environment's default region.
run_cell is available, offer to run it. Otherwise, tell them to run cells one by one (mention ipykernel requirement).python3 <script>.py⏸ Wait for user.
Read references/code_output_guide.md for output format rules, then read the code template matching the finetuning strategy:
code_templates/sft.pycode_templates/dpo.pycode_templates/rlvr.pycode_templates/rlaif_builtin.pycode_templates/rlaif_custom_prompt.pyThe template is a Python file where each # Cell N: Label comment marks the start of a new section. Split on these markers — everything between one marker and the next becomes one unit of output.
code_output_guide.mdmeta-):
ACCEPT_EULA = False line from the config cellaccept_eula=ACCEPT_EULA, line from the trainer callmax_epochs or lr_warmup_steps_ratio from the Configure Trainer section and the Hyperparameter Overrides sectionIn the 'Setup & Credentials' cell, populate:
BASE_MODEL
MODEL_PACKAGE_GROUP_NAME
use_case_spec.md if needed)[a-zA-Z0-9](-*[a-zA-Z0-9]){0,62}customer-support-chatbot-v1Save notebook
references/rlvr_reward_function.md section "Helping Users Create Custom Reward Functions"CUSTOM_REWARD_FUNCTION in the Notebook with the ARN of the reward function (either given directly by the user, or from the function generation code as evaluator.arn).Read references/rlaif_guide.md and follow its instructions.
meta-)
ACCEPT_EULA = True and uncomment accept_eula=ACCEPT_EULA in the generated notebook. If the user declines, leave ACCEPT_EULA = False and warn that training will fail without acceptance.ACCEPT_EULA variable and accept_eula parameter should already be omitted from the notebook (see Step 1.3).After generating the code, offer to run it. Training can take hours depending on your dataset and model.
Notebook mode: If run_cell is available, offer to run the cells. Otherwise tell the user to run cells themselves.
Script mode: Present the user with options:
"Would you like me to:
- Leave it to you — run with
python scripts/[script_name]- Run it and wait until it's done
- Start it but don't wait — we can check status later"
trainer.train(wait=True) blocks until complete. Report final status.wait=True to wait=False in the script, execute, report the training job name.Checking status:
describe-training-job --training-job-name NAME → TrainingJobStatus, FailureReason, SecondaryStatusTransitionslist-model-packages --model-package-group-name GROUP_NAME --sort-by CreationTime --sort-order Descending --max-results 1Showing results after completion:
scripts/mlflow_reference.py as the pattern to query MLflow metricsCRITICAL:
If the user wants to finetune a model they had already customized, follow the instructions in references/continuous_customization.md
rlvr_reward_function.md - Lambda reward function creation guide (RLVR only)templates/rlvr_reward_function_source_template.py - Lambda reward function source template for open-weights models (RLVR only)templates/nova_rlvr_reward_function_source_template.py - Lambda reward function source template for Nova 2.0 Lite (RLVR only)code_templates/sft.py - Complete notebook template for Supervised Fine-Tuning (OSS path)code_templates/dpo.py - Complete notebook template for Direct Preference Optimization (OSS path)code_templates/rlvr.py - Complete notebook template for Reinforcement Learning from Verifiable Rewards (OSS path)references/continuous_customization.md - Instructions on fine-tuning an already fine-tuned model.rlaif_guide.md - instructions on RLAIF finetuning optionsrlaif_builtin.py - Code template for RLAIF with built-in judge promptrlaif_custom_prompt.py - Code template for RLAIF with custom judge prompt原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。