Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

Fine-Tuning and RL for Agents

Free · sign in to start and track progress

1 · Decide and prepare

  • 1Prompt, optimise or train?
  • 2Training data from traces

    Exercise answers

    • Answer: Turn teacher trajectories into a TRL dataset
    • Answer: Audit the set against the test split

2 · Supervised and preference fine-tuning

  • 3SFT with LoRA on a free GPU
  • 4Preference optimisation

3 · Reinforcement learning for agents

  • 5GRPO in practice
  • 6Designing rewards
  • 7Multi-turn RL environments
  • 8Reward hacking, regressions and shipping
CapstoneTrain a triage model, then decide whether to ship itReference implementation

Module 1 · Decide and prepare · Lesson 2

Training data from traces

Turning agent trajectories, grader verdicts and eval failures into a supervised fine-tuning set, with chat templates and loss masks, rejection sampling and corrected failures, open-weight teachers whose terms allow it, balance by failure mode, and a leakage audit against the frozen test split.

80 min 1 video 3 exercises 8-question quiz Answers
Setup for the exercises:Install Claude CodePython with uvGet an OpenRouter keyLocal models with OllamaRun Hugging Face models on CPU

By the end of this lesson you can

  • Convert a multi-turn tool-calling trajectory into a conversational training row, and verify which tokens carry loss under the student's own chat template
  • Filter trajectories with code graders (rejection sampling, as in STaR and ReST-EM), and decide which failures to correct, drop or keep as negatives
  • Generate synthetic inputs and teacher trajectories with an open-weight model whose licence and host terms allow training on its outputs, recording provenance on every example
  • Rebalance a filtered set by failure mode, and size it for quality rather than volume
  • Prove that a training set is disjoint from the frozen test split with exact and near-duplicate checks, and test the check itself on planted leaks

On this page

  • One example is a whole trajectory
  • Chat templates: how messages become tokens
  • Loss masks: which tokens teach
  • Worked example: how much of the example teaches
  • Where good trajectories come from
  • Rejection sampling
  • Corrected failures
  • Negatives
  • An open-weight teacher, and provenance on every row
  • Synthetic inputs from specs
  • Balance by failure mode
  • A leakage audit against the frozen test split
  • Misconceptions and limits
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01One example is a whole trajectory
  2. 02Chat templates: how messages become tokens
  3. 03Loss masks: which tokens teach
  4. 04Where good trajectories come from
  5. 05Synthetic inputs from specs
  6. 06Balance by failure mode
  7. 07A leakage audit against the frozen test split
  8. 08Misconceptions and limits
  9. 09Connections
  10. 10Summary

Sources & further reading

STaR: Bootstrapping Reasoning With ReasoningPaper · Zelikman, Wu, Mu, Goodman · Stanford · 2022The loop behind grader-filtered training data: generate, keep what reaches the right answer, fine-tune, repeat, and retry failures with the correct answer as a hint (rationalisation). Section 3 has both steps.
  • Beyond Human Data: Scaling Self-Training for Problem-Solving with Language ModelsPaper · Singh, Co-Reyes, Agarwal et al. · Google DeepMind · 2023ReST-EM (TMLR): sample, filter with binary correctness feedback, fine-tune, repeat. It scaled with model size and beat fine-tuning on human-written data alone on maths and code.
  • Learning From Failure: Integrating Negative Examples when Fine-tuning Large Language Models as AgentsPaper · Wang, Li, Han, Zhang, Baldwin · 2024Agent fine-tuning that keeps failed trajectories, marked as such, instead of throwing them away. Read it for the argument that failures carry signal; this course keeps them for preference pairs.
  • FireAct: Toward Language Agent Fine-tuningPaper · Chen, Shu, Shareghi, Collier, Narasimhan, Yao · 2023Fine-tuning a 7B model on 500 agent trajectories from a stronger model raised its HotpotQA score by 77%, and more diverse trajectories helped further. The case for training on traces rather than input-output pairs.
  • LIMA: Less Is More for AlignmentPaper · Zhou, Liu, Xu, Iyer, Sun et al. · Meta · 20231,000 carefully curated examples were enough to teach a 65B model specific response formats. The evidence for curating hard before collecting more.
  • Deduplicating Training Data Makes Language Models BetterPaper · Lee, Ippolito, Nystrom, Zhang, Eck, Callison-Burch, Carlini · Google · 2021ACL 2022. Near-duplicates are common in standard datasets, including between train and validation splits. Read the sections on near-duplicate detection, which is the basis of the leakage audit here.
  • Chat TemplatesDocs · Hugging FaceWhich model families get a patched training template from TRL, what the patch changes (generation markers for assistant-only loss, prefix-preserving thinking blocks), and the Qwen3.5 templates used in this course.
  • Free · sign in to start

    Sign in to keep reading.

    Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

    • 10 more sections
    • 3 hands-on exercises
    • A 8-question quiz
    • Progress, quiz scores and bookmarks