Finetuning

From awslabs/agent-plugins · View interactive version

Finetuning is an AI agent skill from the GitHub repository awslabs/agent-plugins. 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

How to use this skill

Skill file

Prerequisites

Before starting this workflow, verify:

  1. A use_case_spec.md file exists
  1. A fine-tuning technique (SFT, DPO, RLVR, RLAIF, or CPT/RFT (for Nova)) and base model have already been selected
  1. A base model name available on SageMakerHub has been identified
  1. The SDK environment has been verified (SDK version, region, execution role)
  1. A training dataset uploaded to a bucket in the environment's default region.

Critical Rules

Code Generation Rules

User Communication Rules


Workflow

1. Code Generation Setup

1.1 Directory Setup

  1. Identify project directory from conversation context

⏸ 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:

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-):
  1. 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
  1. MODEL_PACKAGE_GROUP_NAME
  1. Save notebook

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

2.1 Check Reward Function Status

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 selected base model is a Meta/Llama model (model ID starts with meta-)

5. Post-Generation

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:

1. Leave it to you — run with python scripts/[script_name]

2. Run it and wait until it's done

3. Start it but don't wait — we can check status later"

Checking status:

Showing results after completion:

CRITICAL:

6. Continuous Customization

If the user wants to finetune a model they had already customized, follow the instructions in references/continuous_customization.md


References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.