RL Fine-Tuning Qwen4 to Patch Security Bugs (2027)

Read the Hugging Face TRL cyber recipe line by line, build and verify a defensive task, compute GRPO rewards and advantages by hand, plan an AsyncGRPO run with cost controls, and judge a before and after evaluation with an exact paired test

A cybersecurity course from ibl.ai (self-paced, 10 to 12 hours, free). A hands-on, self-paced course for ML engineers, security engineers and AppSec leads who want an open-weight model, run on hardware they control, to get measurably better at patching vulnerable code, triaging reports and auditing authorization policy. Read the published recipe, build a verified task, compute rewards and advantages, plan a run, and test whether the model really improved.

Last updated:

Course description

RL Fine-Tuning Qwen4 to Patch Security Bugs (2027) teaches the Hugging Face TRL recipe that trains a LoRA adapter on Qwen4-35B-A3B with AsyncGRPO against the UltraCyber dataset of execution-verified defensive tasks: repairing vulnerable code, reproducing a reported crash for triage, and auditing Cedar and OpenFGA authorization policy, each scored by hidden tests in an offline sandbox. You will read the recipe page, recipe.yaml and the launch script line by line; build a small verified task of your own and prove its controls; compute the reward and the group-normalised advantage by hand; plan a run on Hugging Face Jobs with a smoke run, a budget ceiling and stop conditions; and judge a before and after evaluation with an exact McNemar test. The published recipe had not been run as written when this course was verified; every result quoted comes from an earlier canary run with a different setup or from the Hugging Face blog's run, and the course names the differences. Four local labs run on a laptop with no GPU and no account; every job command is marked untested. The capstone is your own training and evaluation plan for a defensive adapter. ibl.ai wrote the course; Hugging Face, the TRL maintainers, the Qwen team and the dataset's authors did not write, review or endorse it. Last verified 2026-12-05.

About this course

Hugging Face publishes a TRL recipe, "Train Qwen4 for Cyber", that fine-tunes the open-weight Qwen4-35B-A3B with reinforcement learning so that it gets better at defensive security work: patching vulnerable code, reproducing a reported crash so it can be triaged, and auditing authorization policy. The tasks come from the UltraCyber dataset, where every task carries a deterministic verifier and a verified reference solution, and the trainer is TRL's AsyncGRPO. This course takes that recipe apart: what a task is and what "solved" means, how a pass or fail becomes a gradient, how the run is laid out across two GPUs and what each setting does, and how to tell whether the model actually got better. When this course was verified, the recipe page said it had not yet been run as written on Hugging Face Jobs; every result quoted here comes from an earlier canary run with a different setup, or from the Hugging Face blog's run, and each is read with its sample size and paired test. Every version, flag and setting comes from the recipe, the dataset card, the TRL, vLLM and Hugging Face Jobs documentation and the papers as of 2026-12-05. ibl.ai wrote this course; Hugging Face, the TRL maintainers, the Qwen team and the dataset's authors did not write, review or endorse it.

What you will be able to do

  1. Read the Hugging Face TRL cyber recipe for Qwen4-35B-A3B line by line, its project page, recipe.yaml and launch script, and explain what each setting controls and what changing it would do.
  2. Explain how a verified task works in the Harbor format the UltraCyber dataset card describes, and why the No-Op and Oracle controls, the fresh-sandbox replay, leak scrubbing and the holdout screen exist, using CWE as the vocabulary for what each task fixes.
  3. Build a small verified defensive task of your own on a laptop, with a vulnerable function you wrote, hidden tests with legitimate and harmless hostile inputs, a reference fix and a verifier that proves No-Op scores 0 and Oracle scores 1 on two runs.
  4. Compute the published reward and the GRPO group-normalised advantage by hand and in numpy, explain why groups with identical rewards carry no signal, and describe what the asynchronous trainer, the staleness bound and a LoRA adapter change about a run.
  5. Plan an AsyncGRPO run on Hugging Face Jobs with a smoke run first, a budget ceiling, a job timeout, checkpoints, resume, the signals to watch and written stop conditions, without launching anything you have not budgeted.
  6. Judge a before and after evaluation with held-out tasks and an exact McNemar test stated in advance, choose a checkpoint, check for regressions, and write the evaluation report, model card and release sign-off for a defensive adapter.

Who this course is for

Roles: ML engineers, security engineers and AppSec leads who want an open-weight model, run on hardware they control, to get measurably better at defensive work, and who must be able to tell whether it really did.

Before you start: comfort with Python and a terminal, a working idea of what fine-tuning and a LoRA adapter are, and basic familiarity with common software weaknesses such as path traversal. The labs need Python 3.9 or later; Lab 2 and Lab 4 install pinned numpy, scipy and statsmodels in a virtual environment. Everything runs locally on a laptop with no GPU and no account; no lab launches a paid job.

Format

Time: about 10 to 12 hours, self-paced. Level: advanced. Hands-on: four labs (build a verified task and prove its controls; compute rewards and group advantages for groups of 8; write a run plan from the recipe; reproduce the canary's exact McNemar p-values and find how many discordant pairs a result needs), with an AI tutor that coaches each step from the output you paste.

Structure: a Start here section, four content sections (the task and the verifier; reward and GRPO; the run; evaluation, checkpoint choice and release) of readings, worked examples, templates and labs, each ending in an AI assessment, and a capstone in which you write a training and evaluation plan for a defensive adapter, followed by a reading list.

Grading: the four section AI assessments count for 60 percent of the grade and the capstone assessment for 40 percent. The pass mark is 70 percent.

Currency

Last verified 2026-12-05 against the TRL recipes Space, the UltraCyber dataset card, the AsyncGRPO trainer documentation, the Qwen4-35B-A3B model card and the Hugging Face Jobs documentation.

This guidance is changing. The recipe, the dataset, TRL, vLLM, the model and Hugging Face Jobs all move quickly, so re-check the linked sources before relying on any page or template, and train and evaluate only on systems and code you own or are authorized in writing to use. This course is training, not a security assessment of your systems.

Outline

  1. Section 0 · Start here

    • 0.1 Welcome and orientation
  2. Section 1 · The task and the verifier: what "solved" means

    • 1.1 Why reinforcement learning, and what a task is
    • 1.2 Verifier controls and the vocabulary of weaknesses
    • 1.3 Section 1 assessment
  3. Section 2 · From pass or fail to a gradient: reward and GRPO

    • 2.1 The reward and the group
    • 2.2 Signal, asynchrony and adapters
    • 2.3 Section 2 assessment
  4. Section 3 · The run: model, serving, harness, job

    • 3.1 Model, serving and harness
    • 3.2 Settings, launch and cost
    • 3.3 Section 3 assessment
  5. Section 4 · Did it get better? Evaluation, checkpoint choice and release

    • 4.1 Held-out sets and paired tests
    • 4.2 Choosing and releasing an adapter
    • 4.3 Section 4 assessment
  6. Section 5 · Capstone and wrap-up

    • 5.1 Capstone: A training and evaluation plan for a defensive adapter
    • 5.2 Capstone assessment
    • 5.3 Reading list