Skip to content
Development
Skill

/finetuning

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

From plugin
agent-plugins
85734 skills8 MCP
Install
$ npx -y skills add awslabs/agent-plugins --skill finetuning --agent claude-code

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.
  • Slash command/finetuning

Context preview

The summary Claude sees to decide when to auto-load this skill.

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

SKILL.md

finetuning.SKILL.md
name: finetuning
description: 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.
metadata:
  version: "1.0.0"

Prerequisites

Before starting this workflow, verify:

1. A `use_case_spec.md` file exists

  • If missing: Activate the `use-case-specification` skill first, then resume
  • DON'T EVER offer to create a use case spec without activating the use-case-specification skill.

2. A fine-tuning technique (SFT, DPO, RLVR, RLAIF, or CPT/RFT (for Nova)) and base model have already been selected

  • If missing: Activate the `model-selection` and/or `finetuning-technique` skills to collect what's missing, then resume
  • Don't make recommendations on the spot. You MUST activate the appropriate skill.

3. A base model name available on SageMakerHub has been identified

  • If missing: Activate the `model-selection` skill to get it
  • **Important:** Only use the model name that `model-selection` retrieves, as it may differ from other commonly used names for the same model

4. The SDK environment has been verified (SDK version, region, execution role)

  • If not done: Activate the `sdk-getting-started` skill first, then resume

5. A training dataset uploaded to a bucket in the environment's default region.

  • If not met: Help the user upload the dataset to the correct S3

---

Critical Rules

Code Generation Rules

  • ✅ Use EXACTLY the imports shown in each code template
  • ❌ Do NOT add additional imports even if they seem helpful
  • ❌ Do NOT create variables before they're needed in that section
  • 📋 Copy the code structure precisely - no improvisation
  • 🎯 Follow the minimal code principle strictly
  • ✅ When writing code, make sure the indentation and f strings are correct

User Communication Rules

  • ❌ NEVER offer to move on to a downstream skill while training is in progress (logically impossible)
  • ❌ NEVER set ACCEPT_EULA to True without explicit user confirmation in the conversation
  • ✅ Always mention both the number AND title of sections you reference
  • ✅ If user asks how to run (notebook): If `run_cell` is available, offer to run it. Otherwise, tell them to run cells one by one (mention ipykernel requirement).
  • ✅ If user asks how to run (script): Tell them to run with `python3 <script>.py`

---

Workflow

1. Code Generation Setup

1.1 Directory Setup

1. Identify project directory from conversation context

  • If unclear (multiple relevant directories exist) → Ask user which folder to use
  • If no project directory exists → activate the **directory-management** skill to set one up

⏸ Wait for user.

1.2 Select Code Template

Read `references/code_output_guide.md` for output format rules, then read the code template matching the finetuning strategy:

  • SFT → `code_templates/sft.py`
  • DPO → `code_templates/dpo.py`
  • RLVR → `code_templates/rlvr.py`
  • RLAIF with built-in rewards → `code_templates/rlaif_builtin.py`
  • RLAIF with custom prompt → `code_templates/rlaif_custom_prompt.py`

The 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.

1.3 Generate Code

1. Write the code from the template following the rules in `code_output_guide.md` 2. Use same order, dependencies, and imports as the template 3. DO NOT improvise or add extra code 4. If the model is **NOT** a Meta/Llama model (model ID does NOT start with `meta-`):

  • Omit the `ACCEPT_EULA = False` line from the config cell
  • Omit the `accept_eula=ACCEPT_EULA,` line from the trainer call

5. If the model is from the Nova family, omit any code containing `max_epochs` or `lr_warmup_steps_ratio` from the Configure Trainer section and the Hyperparameter Overrides section

1.4 Auto-Generate Configuration Values

**In the 'Setup & Credentials' cell, populate:**

1. **BASE_MODEL**

  • Use the exact SageMakerHub model name from context

2. **MODEL_PACKAGE_GROUP_NAME**

  • Generate from use case (read `use_case_spec.md` if needed)
  • Format rules:
  • Lowercase, alphanumeric with hyphens only
  • 1-63 characters
  • Pattern: `[a-zA-Z0-9](-*[a-zA-Z0-9]){0,62}`
  • Example: "Customer Support Chatbot" → `customer-support-chatbot-v1`

3. Save notebook

2. RLVR Reward Function (for RLVR only, skip this section if technique is SFT or DPO)

2.1 Check Reward Function Status

  • Ask if user has a reward function already, or would like help creating one.
  • If user says they have one → Ask for the SageMaker Hub Evaluator ARN. Only proceed to Section 2.3 once the user provides a valid Evaluator ARN. If they don't have it registered as a SageMaker Hub Evaluator, continue to 2.2.
  • If user says they do not have one → Continue to 2.2

2.2 Generate Reward Function From Template

1. Follow workflow in `references/rlvr_reward_function.md` section "Helping Users Create Custom Reward Functions"

2.3 Set CUSTOM_REWARD_FUNCTION value

1. Set the value for `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`).

3. RLAIF (for RLAIF only, skip this section if technique is not RLAIF)

Read `references/rlaif_guide.md` and follow its instructions.

4. EULA review and acceptance

1. Look up the official license link for the selected base model from references/eula_links.md 2. Display the license to the user following the phrasing in references/eula_links.md. For OSS models: "This model is licensed under **{License}**. Please review the license terms here: {URL}." For Nova models: "This model is subject to the AWS Service Terms: {URL}." 3. Check if the se

Read more
Ships withagent-plugins

Read this in other languages: 日本語 Generative AI can make mistakes. You should consider reviewing all output and costs generated by your chosen AI model and agentic coding assistant. See AWS Responsible AI Policy.

Get the whole plugin

Other skills on agent-plugins.