figures / unit1-five-ways.html
sergiopaniego's picture
sergiopaniego HF Staff
Update figures: U2 errors (Job 4), U5 paired and eval reward, U6 course results, U7 why-paired and submission flow
e7f17af verified
Raw History Blame Contribute Delete
7.84 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Five ways to train an agent</title>
<!-- Generated by build.py from fragments/. Runtime and theme tokens come from the research-article template. -->
<link rel="stylesheet" href="runtime/variables.css">
<script>
// The iframe can't read the course page's theme, so follow ?theme= if given, else the OS setting.
(function () {
const forced = new URLSearchParams(location.search).get('theme');
const mq = matchMedia('(prefers-color-scheme: dark)');
const apply = () => document.documentElement.setAttribute('data-theme', forced || (mq.matches ? 'dark' : 'light'));
apply();
if (!forced) mq.addEventListener('change', apply);
})();
</script>
<script src="runtime/color-palettes.js"></script>
<script src="runtime/rough.js"></script>
<script src="runtime/hand.js"></script>
<script src="runtime/embed-runtime.js"></script>
<style>
html, body { margin: 0; padding: 0; }
/* An opaque card with its own background, so it stays readable whatever theme the course page uses */
body { background: transparent; }
.figure-card { font-family: 'Source Sans 3', var(--default-font-family); color: var(--text-color); background: var(--page-bg);
border: 1px solid var(--border-color); border-radius: 10px; padding: 12px 14px 10px; }
</style>
<script>
// Clean look by default, in Source Sans. ?style=hand brings back the old hand-drawn look for comparison:
// it loads Excalifont and uses it for the whole card.
if (new URLSearchParams(location.search).get('style') === 'hand') {
const st = document.createElement('style');
st.textContent = "@font-face { font-family: 'Excalifont'; src: url('runtime/fonts/Excalifont-Regular.woff2') format('woff2'); font-display: swap; }" +
".figure-card { font-family: 'Excalifont', 'Source Sans 3', var(--default-font-family); }";
document.head.appendChild(st);
} else {
document.documentElement.classList.add('style-clean');
const l = document.createElement('link'); l.rel = 'stylesheet';
l.href = 'https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;600;700&display=swap';
document.head.appendChild(l);
}
</script>
</head>
<body>
<div class="figure-card">
<!-- title: Five ways to train an agent -->
<div class="fig-five-ways"></div>
<style>
.fig-five-ways { position: relative; color: var(--text-color); font-size: 14px; }
.fig-five-ways svg { display: block; width: 100%; overflow: visible; }
</style>
<script>
Embed.mount('fig-five-ways', (ctx) => {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
ctx.root.appendChild(svg);
// Same order and wording as the table on the Unit 0 introduction page.
const UNITS = [
{ unit: 'Unit 2', method: 'SFT', body: 'copies traces of a stronger model' },
{ unit: 'Unit 3', method: 'Distillation', body: "matches a teacher's predictions" },
{ unit: 'Unit 4', method: 'RL', body: 'learns from a score on its own attempts' },
{ unit: 'Unit 5', method: 'RL environments', body: 'learns from acting over several turns' },
{ unit: 'Unit 6', method: 'Async RL and harnesses', body: 'trains asynchronously and covers real agent harnesses' },
];
const EXAMPLE = 'Running example: Qwen3-1.7B solving Python problems in Units 1 to 4, Qwen3.5-2B answering questions about data files in Units 5 and 6';
ctx.describe('Five units in order. Units 2 to 5 each train the agent with a different signal, and Unit 6 changes how the training runs. Unit 2, SFT, copies traces of a stronger model. Unit 3, distillation, matches a teacher\'s predictions. Unit 4, RL, learns from a score on its own attempts. Unit 5, RL environments, learns from acting over several turns. Unit 6, async RL and harnesses, trains asynchronously and covers real agent harnesses. The running example is Qwen3-1.7B solving Python problems with run_python in Units 1 to 4, and Qwen3.5-2B answering questions about data files in Units 5 and 6.');
const measure = document.createElement('canvas').getContext('2d');
function wrap(text, maxW, size) {
measure.font = `${size}px ${Hand.FONT}`;
const out = [];
text.split(' ').forEach((w) => {
const last = out[out.length - 1];
if (last && measure.measureText(last + ' ' + w).width <= maxW) out[out.length - 1] = last + ' ' + w;
else out.push(w);
});
return out;
}
if (document.fonts) document.fonts.load(`14px ${Hand.FONT}`).then(() => ctx.rerender());
return ({ width: fullW }) => {
const width = fullW - 4;
const C = Hand.colors(ctx.root);
svg.replaceChildren();
const h = Hand.create(svg, { seed: 11 });
const narrow = width < 560;
const card = { fill: C.greySoft, stroke: C.ink, width: 1.2 };
let H;
if (!narrow) {
const gap = 26, cw = (width - 4 * gap) / 5, head = 15, size = 14, lh = size * 1.25;
const bodies = UNITS.map((u) => wrap(u.body, cw - 16, size));
const methods = UNITS.map((u) => wrap(u.method, cw - 12, head + 1));
const mLines = Math.max(...methods.map((m) => m.length));
const bLines = Math.max(...bodies.map((b) => b.length));
const top = 4, ch = 20 + head + mLines * (head + 1) * 1.25 + 14 + bLines * lh + 8;
UNITS.forEach((u, i) => {
const x = i * (cw + gap), cx = x + cw / 2;
h.rect(x, top, cw, ch, card);
h.text(cx, top + 24, u.unit, { size: head, anchor: 'middle', color: C.muted });
h.text(cx, top + 24 + (head + 1) * 1.3, methods[i].join('\n'), { size: head + 1, anchor: 'middle', color: C.ink });
const by = top + 24 + (head + 1) * 1.3 + mLines * (head + 1) * 1.25 + 14;
h.text(cx, by, bodies[i].join('\n'), { size, anchor: 'middle', color: C.muted });
if (i < 4) h.arrow([[x + cw + 4, top + ch / 2], [x + cw + gap - 4, top + ch / 2]], { stroke: C.ink, width: 1.4, head: 8 });
});
const ex = wrap(EXAMPLE, width - 32, 15), ey = top + ch + 24, eh = 22 + ex.length * 19;
h.rect(0, ey, width, eh, { fill: C.greySoft, stroke: C.ink, width: 1.2 });
h.text(width / 2, ey + eh / 2 - (ex.length - 1) * 9.5 + 5, ex.join('\n'), { size: 15, anchor: 'middle', color: C.ink });
H = ey + eh + 4;
} else {
const size = 14, lh = size * 1.25, gap = 22, headW = Math.min(150, width * 0.38);
const bodyW = width - headW - 24;
let y = 2;
UNITS.forEach((u, i) => {
const body = wrap(u.body, bodyW, size);
const method = wrap(u.method, headW - 14, 16);
const ch = Math.max(16 + 19 + method.length * 20, 20 + body.length * lh) + 4;
h.rect(0, y, width, ch, card);
h.text(12, y + 24, u.unit, { size: 14, color: C.muted });
h.text(12, y + 24 + 20, method.join('\n'), { size: 16, color: C.ink });
h.line(headW, y + 8, headW, y + ch - 8, { stroke: C.border, width: 1 });
h.text(headW + 12, y + ch / 2 - (body.length - 1) * lh / 2 + 5, body.join('\n'), { size, color: C.muted });
y += ch;
if (i < 4) h.arrow([[width / 2, y + 3], [width / 2, y + gap - 3]], { stroke: C.ink, width: 1.4, head: 7 });
y += gap;
});
const ex = wrap(EXAMPLE, width - 28, 15), eh = 22 + ex.length * 19;
y += 2;
h.rect(0, y, width, eh, { fill: C.greySoft, stroke: C.ink, width: 1.2 });
h.text(width / 2, y + eh / 2 - (ex.length - 1) * 9.5 + 5, ex.join('\n'), { size: 15, anchor: 'middle', color: C.ink });
H = y + eh + 4;
}
svg.setAttribute('viewBox', `-2 0 ${fullW} ${H}`);
svg.setAttribute('height', H);
};
}, { deps: [] });
</script>
</div>
</body>
</html>