figures / unit6-multi-harness-setup.html
sergiopaniego's picture
sergiopaniego HF Staff
U6 multi-harness setup figure
4d570bc verified
Raw History Blame Contribute Delete
17.1 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>One model, four harnesses, one trainer</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: One model, four harnesses, one trainer -->
<div class="fig-multi-setup"></div>
<style>
.fig-multi-setup { position: relative; color: var(--text-color); font-size: 14px; }
.fig-multi-setup svg { display: block; width: 100%; overflow: visible; }
.fig-multi-setup svg .mh-hit { cursor: pointer; outline: none; }
.fig-multi-setup .fig-note { margin: 10px 0 0; line-height: 1.45; font-size: 15px; }
</style>
<script>
Embed.mount('fig-multi-setup', (ctx) => {
const NS = 'http://www.w3.org/2000/svg';
// The setup of the multi-harness runs in the FineEnvs guide (https://huggingface.co/spaces/FineEnvs/multi-harness-rl),
// chapters "How the framework works" and "Training": vLLM serves the policy on one GPU, the trainer (TRL async GRPO)
// runs on another and sends it new weights, the OpenEnv server runs Harbor's tasks with one sandbox per rollout
// and its capture proxy, and Harbor's verifier gives the reward. One harness per GRPO group of eight.
// How each harness finds the proxy comes from the guide's harness-seams embed (openenv/harbor/seams.py).
const HARNESSES = [
{ name: 'OpenCode', note: "reads the proxy's URL and its run's session id from a config file written into its sandbox." },
{ name: 'Claude Code', note: 'gets them from environment variables. It rewrites its own history so often that each of its runs became about 8 training sequences, against about 1 for the other harnesses.' },
{ name: 'Codex', note: "gets them from environment variables set only for the agent's run, so the session id never reaches the task's test." },
{ name: 'Mini-SWE-Agent', note: "gets them from environment variables set only for the agent's run. Before training, LFM2.5-2.6B solved 62% of the held-out tasks in it and 33% in Claude Code." },
];
let active = 0, width = 640, C = null;
const svg = document.createElementNS(NS, 'svg');
const note = document.createElement('p');
note.className = 'fig-note';
note.setAttribute('aria-live', 'polite');
ctx.root.append(svg, note);
ctx.describe("The multi-harness setup. On one side, Harbor starts every run in its own sandbox, and the runs use four unmodified harnesses: OpenCode, Claude Code, Codex and Mini-SWE-Agent. A GRPO group is 8 runs of one task, all in the same harness. Each sandbox also holds the task's test. Every harness sends its model calls to the same capture proxy, which tells the runs apart by their session id, forwards each call to one vLLM server that serves the model being trained, and keeps the token ids vLLM returns. The proxy sends the traces from every harness to one async GRPO trainer in TRL. Each task's test gives the run's reward, which also goes to the trainer. The trainer sends the new weights back to the vLLM server, so every harness calls the updated model. Select a harness to see how it finds the proxy: OpenCode from a config file written into its sandbox, Claude Code from environment variables, Codex and Mini-SWE-Agent from environment variables set only for the agent's run.");
const measure = document.createElement('canvas').getContext('2d');
const textW = (s, size, weight = 400) => { measure.font = `${weight} ${size}px ${Hand.FONT}`; return measure.measureText(s).width; };
function wrap(text, maxW, size, weight) {
const out = [];
text.split(' ').forEach((w) => {
const last = out[out.length - 1];
if (last && textW(last + ' ' + w, size, weight) <= maxW) out[out.length - 1] = last + ' ' + w;
else out.push(w);
});
return out;
}
function writeNote(k) {
note.replaceChildren();
const strong = document.createElement('strong');
strong.textContent = HARNESSES[k].name;
note.append(strong, ` ${HARNESSES[k].note} All 8 runs of a group use ${HARNESSES[k].name}.`);
}
function setActive(k) {
if (k === active) return;
active = k;
draw();
writeNote(active);
}
function draw() {
if (!C) return;
const narrow = width < 600;
const W = width;
const harness = { fill: C.greySoft, stroke: C.grey };
const model = Hand.role(C, 'assistant');
const sd = (k) => 7000 + k;
// --- geometry -------------------------------------------------------------------------------
const laneH = narrow ? 44 : 50, laneGap = narrow ? 10 : 12;
const frameX = 1, frameTop = 1;
const lanesTop = frameTop + (narrow ? 32 : 46);
let frameW, laneX, laneW, P, V, T, frameBottom;
if (narrow) {
frameW = W - 2;
} else {
frameW = Math.round(W * 0.4);
}
laneX = frameX + 10;
laneW = frameW - (narrow ? 44 : 26); // room for the stacked outlines behind each sandbox (and the bus when narrow)
const lanes = HARNESSES.map((_, k) => ({ x: laneX, y: lanesTop + k * (laneH + laneGap), w: laneW, h: laneH }));
const lanesBottom = lanes[3].y + laneH;
frameBottom = lanesBottom + (narrow ? 34 : 36);
if (narrow) {
const rail = 26; // left margin for the reward line
const rowTop = frameBottom + 50;
const colGap = 40;
const colW = Math.floor((W - rail - colGap) / 2);
P = { x: rail, y: rowTop, w: colW, h: 84 };
V = { x: rail + colW + colGap, y: rowTop, w: W - rail - colW - colGap - 1, h: 84 };
T = { x: 1, y: rowTop + 84 + 50, w: rail + colW - 1, h: 58 };
} else {
const g1 = Math.max(60, Math.round(W * 0.1)), wP = Math.round(W * 0.2), g2 = Math.max(54, Math.round(W * 0.085));
P = { x: frameX + frameW + g1, y: lanesTop, w: wP, h: lanesBottom - lanesTop };
const vx = P.x + wP + g2, vw = W - vx - 1;
const bh = Math.round((P.h - 48) / 2);
V = { x: vx, y: lanesTop, w: vw, h: bh };
T = { x: vx, y: lanesBottom - bh, w: vw, h: bh };
}
const H = narrow ? T.y + T.h + 28 : frameBottom + 30;
svg.replaceChildren();
svg.setAttribute('viewBox', `0 0 ${W} ${H}`);
svg.setAttribute('height', H);
const base = document.createElementNS(NS, 'g'), hits = document.createElementNS(NS, 'g');
svg.append(base, hits);
const h = Hand.create(base, { seed: 61 });
// --- Harbor and the sandboxes ---------------------------------------------------------------
h.rect(frameX, frameTop, frameW, frameBottom - frameTop, { stroke: C.muted, width: 1.2, dashed: true, seed: sd(1) });
h.text(frameX + 10, frameTop + 21, 'Harbor', { size: 15, weight: 600, color: C.ink });
h.text(frameX + 10 + textW('Harbor', 15, 600) + 8, frameTop + 21, narrow ? 'a sandbox per run' : 'starts each run', { size: 13, color: C.muted });
if (!narrow) h.text(frameX + 10, frameTop + 38, 'in its own sandbox', { size: 13, color: C.muted });
const chipW = Math.ceil(textW("task's test", 12.5) + 14);
lanes.forEach((L, k) => {
const on = k === active;
// two outlines behind: the other runs of the same group, each in its own sandbox
[6, 3].forEach((o, j) => h.rect(L.x + o, L.y + o, L.w, L.h, { stroke: C.border, width: 1, dashed: true, fill: C.bg, seed: sd(10 + 4 * k + j) }));
h.rect(L.x, L.y, L.w, L.h, { fill: on ? C.yellowSoft : C.bg, stroke: on ? C.ink : C.grey, width: on ? 1.8 : 1.1, dashed: !on, seed: sd(30 + k) });
const hw = L.w - chipW - 22, hy = L.y + 7, hh = L.h - 14;
h.rect(L.x + 7, hy, hw, hh, { fill: harness.fill, stroke: harness.stroke, width: 1.1, seed: sd(40 + k) });
h.text(L.x + 7 + hw / 2, hy + hh / 2 + 5, HARNESSES[k].name, { size: 14, anchor: 'middle', color: C.ink, weight: on ? 600 : 400 });
const cx = L.x + L.w - chipW - 7;
h.rect(cx, hy + (hh - 24) / 2, chipW, 24, { fill: C.greenSoft, stroke: C.green, width: 1.1, seed: sd(50 + k) });
h.text(cx + chipW / 2, hy + hh / 2 + 4.5, "task's test", { size: 12.5, anchor: 'middle', color: C.greenText });
});
h.text(frameX + 10, frameBottom - 12, '8 runs per GRPO group, one harness', { size: 12.5, color: C.muted });
// --- proxy, vLLM and trainer ------------------------------------------------------------------
const centered = (B, lines) => {
const lh = 17, y0 = B.y + B.h / 2 - ((lines.length - 1) * lh) / 2 + 5;
lines.forEach(([t, size, color, weight], i) => h.text(B.x + B.w / 2, y0 + i * lh, t, { size, color, weight, anchor: 'middle' }));
};
const inner = (B) => B.w - 14;
h.rect(P.x, P.y, P.w, P.h, { fill: C.greySoft, stroke: C.ink, width: 1.3, seed: sd(60) });
centered(P, [
...wrap('capture proxy', inner(P), 15, 600).map((t) => [t, 15, C.ink, 600]),
...wrap('one session id per run', inner(P), 12.5).map((t) => [t, 12.5, C.muted]),
...(narrow ? [] : wrap('keeps the token ids', inner(P), 12.5).map((t) => [t, 12.5, C.muted])),
]);
h.rect(V.x, V.y, V.w, V.h, { fill: model.fill, stroke: model.stroke, width: 1.3, seed: sd(61) });
centered(V, [['vLLM', 15, C.ink, 600], ...wrap('the one model being trained', inner(V), 12.5).map((t) => [t, 12.5, C.muted])]);
h.rect(T.x, T.y, T.w, T.h, { fill: C.greySoft, stroke: C.grey, width: 1.3, seed: sd(62) });
centered(T, [...wrap('async GRPO trainer', inner(T), 15, 600).map((t) => [t, 15, C.ink, 600]), ['TRL', 12.5, C.muted]]);
const lab = (x, y, t, o = {}) => h.text(x, y, t, { size: 12.5, color: C.muted, anchor: 'middle', ...o });
const pair = (a, b, c, d, col, w, k, off) => {
// the call goes one way, the reply comes back, side by side
const dx = d - b !== 0 ? off : 0, dy = d - b !== 0 ? 0 : off;
h.arrow([[a - dx, b - dy], [c - dx, d - dy]], { stroke: col, width: w, head: 7, seed: sd(k) });
h.arrow([[c + dx, d + dy], [a + dx, b + dy]], { stroke: col, width: w, head: 7, seed: sd(k + 1) });
};
if (narrow) {
// every sandbox reaches the proxy, the active one in bold
lanes.forEach((L, k) => {
const on = k === active;
h.line(L.x + L.w + 10, L.y + L.h / 2, frameX + frameW - 14, L.y + L.h / 2, { stroke: on ? C.purple : C.muted, width: on ? 1.8 : 1.1, seed: sd(70 + k) });
});
const busX = frameX + frameW - 14;
h.line(busX, lanes[0].y + lanes[0].h / 2, busX, frameBottom, { stroke: C.muted, width: 1.1, seed: sd(75) });
const px = P.x + P.w / 2;
h.line(busX, frameBottom, busX, frameBottom + 18, { stroke: C.muted, width: 1.1, seed: sd(76) });
h.line(busX, frameBottom + 18, px + 6, frameBottom + 18, { stroke: C.muted, width: 1.1, seed: sd(77) });
pair(px, frameBottom + 18, px, P.y - 3, C.purple, 1.6, 78, 6);
lab(px + 14, frameBottom + 38, 'model calls', { anchor: 'start' });
const ym = P.y + P.h / 2;
pair(P.x + P.w + 3, ym, V.x - 3, ym, C.purple, 1.6, 80, 7);
// proxy -> trainer, the traces
h.arrow([[px, P.y + P.h + 3], [px, T.y - 3]], { stroke: C.ink, width: 1.4, head: 7, seed: sd(82) });
lab(px + 7, P.y + P.h + 30, 'traces', { anchor: 'start', color: C.ink });
// trainer -> vLLM, the new weights
const vx = V.x + V.w / 2, ty = T.y + T.h / 2;
h.line(T.x + T.w + 3, ty, vx, ty, { stroke: C.purple, width: 1.6, seed: sd(84) });
h.arrow([[vx, ty], [vx, V.y + V.h + 3]], { stroke: C.purple, width: 1.6, head: 7, seed: sd(85) });
lab(vx, ty + 20, 'new weights', { color: C.purpleText });
// reward, from the tests down the left rail
h.arrow([[12, frameBottom + 3], [12, T.y - 3]], { stroke: C.green, width: 1.6, head: 7, seed: sd(86) });
lab(19, T.y - 10, 'reward', { anchor: 'start', color: C.greenText });
} else {
lanes.forEach((L, k) => {
const on = k === active;
pair(L.x + L.w + 9, L.y + L.h / 2, P.x - 3, L.y + L.h / 2, on ? C.purple : C.muted, on ? 1.8 : 1.1, 90 + 2 * k, 6);
});
lab((frameX + frameW + P.x) / 2, lanesTop - 8, 'model calls');
const g2c = (P.x + P.w + V.x) / 2;
const y1 = V.y + V.h / 2;
pair(P.x + P.w + 3, y1, V.x - 3, y1, C.purple, 1.6, 100, 7);
lab(g2c, y1 - 13, 'calls');
lab(g2c, y1 + 23, 'token ids');
const y2 = T.y + T.h / 2;
h.arrow([[P.x + P.w + 3, y2], [T.x - 3, y2]], { stroke: C.ink, width: 1.4, head: 7, seed: sd(102) });
lab(g2c, y2 - 9, 'traces', { color: C.ink });
const ax = V.x + 18;
h.arrow([[ax, T.y - 3], [ax, V.y + V.h + 3]], { stroke: C.purple, width: 1.6, head: 7, seed: sd(103) });
lab(ax + 9, (T.y + V.y + V.h) / 2 + 4, 'new weights', { anchor: 'start', color: C.purpleText });
// reward: from under the sandboxes to the trainer, below the proxy
const ry = frameBottom + 12, tx = T.x + T.w / 2;
h.line(frameX + frameW / 2, frameBottom + 2, frameX + frameW / 2, ry, { stroke: C.green, width: 1.6, seed: sd(104) });
h.line(frameX + frameW / 2, ry, tx, ry, { stroke: C.green, width: 1.6, seed: sd(105) });
h.arrow([[tx, ry], [tx, T.y + T.h + 3]], { stroke: C.green, width: 1.6, head: 7, seed: sd(106) });
lab(P.x + P.w / 2, ry + 18, "reward from each task's test", { color: C.greenText });
}
// --- hover, tap and keyboard targets -----------------------------------------------------------
lanes.forEach((L, k) => {
const r = document.createElementNS(NS, 'rect');
r.setAttribute('x', L.x); r.setAttribute('y', L.y); r.setAttribute('width', L.w + 6); r.setAttribute('height', L.h + 6);
r.setAttribute('fill', 'transparent');
r.setAttribute('class', 'mh-hit');
r.setAttribute('tabindex', '0');
r.setAttribute('role', 'button');
r.setAttribute('aria-pressed', String(k === active));
r.setAttribute('aria-label', `${HARNESSES[k].name}: how it finds the proxy`);
r.addEventListener('pointerover', () => setActive(k), { signal: ctx.signal });
r.addEventListener('click', () => setActive(k), { signal: ctx.signal });
r.addEventListener('focus', () => setActive(k), { signal: ctx.signal });
hits.appendChild(r);
});
}
// Keep the note as tall as its longest text, so the iframe height doesn't change on hover.
function layout() {
draw();
let tallest = 0;
HARNESSES.forEach((_, k) => { note.style.minHeight = ''; writeNote(k); tallest = Math.max(tallest, note.offsetHeight); });
writeNote(active);
note.style.minHeight = tallest + 'px';
}
if (document.fonts && document.fonts.ready) document.fonts.ready.then(() => { if (!ctx.signal.aborted) layout(); });
return ({ width: w }) => { width = w; C = Hand.colors(ctx.root); layout(); };
}, { deps: [] });
</script>
</div>
</body>
</html>