Spaces:
Running
Running
sergiopaniego HF Staff
Brand teal accent, readable text colors, U4 nudge redesign, U7 figures
39824c1 verified Download unit6-capture-graph.html from training-agents-course/figures: direct link, hf CLI and curl.
- Browser
- Download file 14.6 kB
-
https://huggingface.co/spaces/training-agents-course/figures/resolve/main/unit6-capture-graph.html
- Command line
-
hf download hf://spaces/training-agents-course/figures/unit6-capture-graph.html
-
curl -L -o unit6-capture-graph.html https://huggingface.co/spaces/training-agents-course/figures/resolve/main/unit6-capture-graph.html
14.6 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>From captured calls to trained tokens</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: From captured calls to trained tokens --> | |
| <div class="fig-capture-graph"></div> | |
| <style> | |
| .fig-capture-graph { position: relative; color: var(--text-color); font-size: 14px; } | |
| .fig-capture-graph svg { display: block; width: 100%; overflow: visible; } | |
| .fig-capture-graph .fig-controls { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; } | |
| .fig-capture-graph button { | |
| font: inherit; font-size: 14px; height: 30px; padding: 0 12px; border-radius: 6px; cursor: pointer; | |
| color: var(--text-color); background: var(--surface-bg); border: 1px solid var(--border-color); | |
| } | |
| .fig-capture-graph button[aria-pressed="true"] { border-color: var(--primary-color); } | |
| .fig-capture-graph button:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; } | |
| .fig-capture-graph .cg-hit { fill: transparent; cursor: pointer; outline: none; } | |
| .fig-capture-graph .cg-hit:focus-visible { stroke: var(--primary-color); stroke-width: 2; } | |
| .fig-capture-graph .cg-stats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-top: 10px; } | |
| .fig-capture-graph .cg-stats div { display: flex; flex-direction: column; } | |
| .fig-capture-graph .cg-stats b { font-size: 18px; font-weight: 600; } | |
| .fig-capture-graph .cg-stats span { font-size: 13px; color: var(--muted-color); } | |
| .fig-capture-graph .fig-note { margin: 10px 0 0; min-height: 4.4em; line-height: 1.45; color: var(--text-color); } | |
| @media (max-width: 560px) { .fig-capture-graph .fig-note { min-height: 10.2em; } } | |
| </style> | |
| <script> | |
| Embed.mount('fig-capture-graph', (ctx) => { | |
| const NS = 'http://www.w3.org/2000/svg'; | |
| // One OpenCode run as OpenEnv's capture graph records it (capture/graph.py, roles from export.py _assign_roles). | |
| // Sampled counts of root A and the abandoned attempt come from the example rollout in the multi-harness RL | |
| // article (1,108 sampled of 10,002 tokens). The title call and root B are illustrative. | |
| const CALLS = [ | |
| { n: 1, lane: 'A', role: 'agent', label: 'tool call', sampled: 79, | |
| why: 'Its prompt extends no earlier call, so it starts root A. The request carries OpenCode\'s tool manifest, so the path is labelled agent. Its 79 sampled tokens get loss mask 1, its prompt (system prompt and task) is context with mask 0.' }, | |
| { n: 2, lane: 'aux', role: 'auxiliary', label: 'title, no tools', sampled: 12, illustrative: true, | |
| why: 'OpenCode asks the model for a short session title. The prompt is different and extends nothing, so it is its own root, and it sends no tool manifest. Other paths in this run use tools, so a toolless path is labelled auxiliary and none of its tokens train.' }, | |
| { n: 3, lane: 'A', role: 'agent', label: 'tool call', sampled: 331, parent: 1, | |
| why: 'Its prompt starts with every token of call 1, prompt and reply, followed by the tool result. So call 1 is its parent. Agent work: 331 sampled tokens trained, the tool result is context.' }, | |
| { n: 4, lane: 'A', role: 'agent', label: 'tool call', sampled: 90, parent: 3, | |
| why: 'Extends call 3. Agent work: 90 sampled tokens trained. Calls 5 and 6 both extend this call, so the graph has a fork here.' }, | |
| { n: 5, lane: 'D', role: 'discarded', label: 'abandoned attempt', sampled: 143, parent: 4, | |
| why: 'The harness threw this reply away and asked again with the same prompt (call 6). Call 6 continued and this one has no children, so the graph marks it discarded. Training it would credit the reward to a reply the agent never used, so its 143 tokens are left out.' }, | |
| { n: 6, lane: 'A', role: 'agent', label: 'tool call', sampled: 396, parent: 4, | |
| why: 'Same parent as call 5, and this attempt continued. That shape (two siblings, only one with children) is how the proxy sees a retry without asking the harness. Agent work: 396 sampled tokens trained.' }, | |
| { n: 7, lane: 'A', role: 'agent', label: 'tool call', sampled: 212, parent: 6, | |
| why: 'The last call of root A. Root A becomes one training sequence of 10,002 tokens: 1,108 sampled tokens with mask 1 (11%) and 8,894 tokens of context with mask 0.' }, | |
| { n: 8, lane: 'B', role: 'agent', label: 'tool call', sampled: 160, illustrative: true, | |
| why: 'OpenCode compacted its context: the history was replaced with a summary. The new prompt is not a token prefix extension of call 7, so the graph starts root B. It still carries the tool manifest, so it is agent work with the same reward as root A.' }, | |
| { n: 9, lane: 'B', role: 'agent', label: 'final answer', sampled: 140, illustrative: true, parent: 8, | |
| why: 'The final answer, with no tool call. The request still carries the tool manifest, so the path is agent and these tokens train. OpenEnv keeps final answers trainable unless a task masks them.' }, | |
| ]; | |
| const SEQ_B_TOTAL = 4000; // illustrative | |
| const SEQ_A_TOTAL = 10002; | |
| let mask = false, selected = 0, width = 640, fromKey = 0; | |
| const controls = document.createElement('div'); | |
| controls.className = 'fig-controls'; | |
| const toggle = document.createElement('button'); | |
| toggle.type = 'button'; | |
| toggle.textContent = 'Loss mask'; | |
| toggle.addEventListener('click', () => { mask = !mask; draw(); }, { signal: ctx.signal }); | |
| controls.append(toggle); | |
| const svg = document.createElementNS(NS, 'svg'); | |
| const stats = document.createElement('div'); | |
| stats.className = 'cg-stats'; | |
| const note = document.createElement('p'); | |
| note.className = 'fig-note'; | |
| note.setAttribute('aria-live', 'polite'); | |
| ctx.root.append(controls, svg, stats, note); | |
| ctx.describe('An example run of a coding agent like OpenCode, as the capture proxy records it: nine model calls in the order they arrived. Root A is the agent working with tools (calls 1, 3, 4, 6, 7). Call 2 is a title generator with no tools, its own root, labelled auxiliary. Call 5 is an attempt the harness abandoned and retried as call 6, labelled discarded. After a context compaction, calls 8 and 9 start root B, still agent work, ending with the final answer. With the loss mask on, only the sampled tokens of agent calls train: 2 training sequences, 1,408 trained tokens out of 14,002.'); | |
| const fmt = (x) => x.toLocaleString('en-US'); | |
| const agent = CALLS.filter((c) => c.role === 'agent'); | |
| const trained = agent.reduce((a, c) => a + c.sampled, 0); | |
| const total = SEQ_A_TOTAL + SEQ_B_TOTAL; | |
| stats.innerHTML = [ | |
| [CALLS.length, 'calls captured'], [3, 'roots'], [2, 'training sequences'], | |
| [`${fmt(trained)} of ${fmt(total)}`, `trained tokens (${Math.round(trained / total * 100)}%)`], | |
| ].map(([v, l]) => `<div><b>${v}</b><span>${l}</span></div>`).join(''); | |
| function select(i, key) { selected = selected === i ? 0 : i; fromKey = key ? i : 0; draw(); fromKey = 0; } | |
| function draw() { | |
| toggle.setAttribute('aria-pressed', String(mask)); | |
| const C = Hand.colors(ctx.root); | |
| svg.replaceChildren(); | |
| const h = Hand.create(svg, { seed: 6 }); | |
| const narrow = width < 560; | |
| const lanes = narrow | |
| ? { A: 50, D: 78, aux: 108, B: 144 } | |
| : { A: 84, D: 130, aux: 186, B: 246 }; | |
| const labelX = narrow ? 172 : 286; | |
| const top = narrow ? 34 : 50, rowH = 34, gap = 30; | |
| const rowY = (c) => top + (c.n - 1) * rowH + (c.n >= 8 ? gap : 0) + rowH / 2; | |
| const H = top + CALLS.length * rowH + gap + 4; | |
| svg.setAttribute('viewBox', `0 0 ${width} ${H}`); | |
| svg.setAttribute('height', H); | |
| const heads = narrow | |
| ? [['A', 'A'], ['aux', 'aux'], ['B', 'B']] | |
| : [['A', 'root A'], ['aux', 'title'], ['B', 'root B']]; | |
| heads.forEach(([k, t]) => h.text(lanes[k], 16, t, { size: 14, anchor: 'middle', color: C.ink })); | |
| if (!narrow) [['A', 'agent'], ['aux', 'auxiliary'], ['B', 'agent']] | |
| .forEach(([k, t]) => h.text(lanes[k], 34, t, { size: 13, anchor: 'middle', color: C.muted })); | |
| h.text(labelX, 16, mask ? 'sampled tokens' : 'what the call returned', { size: 14, color: C.muted }); | |
| // Edges: a parent is the call whose prompt + reply is a token prefix of this call's prompt. | |
| const byN = Object.fromEntries(CALLS.map((c) => [c.n, c])); | |
| CALLS.filter((c) => c.parent).forEach((c) => { | |
| const p = byN[c.parent]; | |
| const x1 = lanes[p.lane], y1 = rowY(p) + 9, x2 = lanes[c.lane], y2 = rowY(c) - 9; | |
| if (c.role === 'discarded') { | |
| h.path(`M${x1 + 6},${y1 - 2} Q${x2},${y1 + 2} ${x2},${y2}`, { stroke: C.red, width: 1.4, dashed: true }); | |
| } else { | |
| h.line(x1, y1, x2, y2, { stroke: C.purple, width: 1.6 }); | |
| } | |
| }); | |
| // Compaction: no token prefix link, a new root. | |
| const c7 = byN[7], c8 = byN[8]; | |
| const gy = rowY(c7) + rowH / 2 + gap / 2; | |
| h.arrow([[lanes.A, rowY(c7) + 10], [lanes.A + 18, gy], [lanes.B, rowY(c8) - 11]], { stroke: C.grey, width: 1.3, dashed: true, head: 8 }); | |
| h.text(labelX, gy + 5, width < 660 ? 'compaction: new root' : 'compaction: history replaced by a summary, new root', { size: 14, color: C.muted }); | |
| const barMax = narrow ? 56 : 150, maxS = Math.max(...CALLS.map((c) => c.sampled)); | |
| CALLS.forEach((c) => { | |
| const x = lanes[c.lane], y = rowY(c); | |
| const style = c.role === 'agent' ? { ...Hand.role(C, 'assistant') } | |
| : c.role === 'auxiliary' ? { stroke: C.grey, fill: C.greySoft, dashed: true, fillStyle: 'hachure' } | |
| : { stroke: C.red, fill: C.redSoft }; | |
| h.text(0, y + 5, narrow ? `${c.n}` : `call ${c.n}`, { size: 14, color: C.muted }); | |
| if (selected === c.n) h.circle(x, y, 30, { stroke: C.ink, width: 1.6 }); | |
| h.circle(x, y, 18, { stroke: style.stroke, fill: style.fill, fillStyle: style.fillStyle, dashed: style.dashed, width: 1.6 }); | |
| if (!mask) { | |
| h.text(labelX, y + 5, c.label, { size: 14, color: c.role === 'agent' ? C.ink : c.role === 'discarded' ? C.redText : C.muted }); | |
| } else { | |
| const w = Math.max(4, c.sampled / maxS * barMax); | |
| const train = c.role === 'agent'; | |
| h.rect(labelX, y - 8, w, 16, train | |
| ? { stroke: C.purple, fill: C.purple, width: 1.2, radius: 3 } | |
| : c.role === 'auxiliary' | |
| ? { stroke: C.grey, fill: C.greySoft, fillStyle: 'hachure', dashed: true, width: 1.2, radius: 3 } | |
| : { stroke: C.red, fill: C.redSoft, width: 1.2, radius: 3 }); | |
| h.text(labelX + w + 6, y + 5, `+${c.sampled} ${train ? 'trained' : 'left out'}`, | |
| { size: 14, color: train ? C.ink : c.role === 'discarded' ? C.redText : C.muted }); | |
| } | |
| const hit = document.createElementNS(NS, 'rect'); | |
| hit.setAttribute('class', 'cg-hit'); | |
| hit.setAttribute('x', 0); hit.setAttribute('y', y - rowH / 2 + 1); | |
| hit.setAttribute('width', width); hit.setAttribute('height', rowH - 2); | |
| hit.setAttribute('rx', 6); | |
| hit.setAttribute('tabindex', '0'); | |
| hit.setAttribute('role', 'button'); | |
| hit.setAttribute('aria-label', `Call ${c.n}: ${c.role}`); | |
| hit.setAttribute('aria-pressed', String(selected === c.n)); | |
| hit.addEventListener('click', () => select(c.n, false), { signal: ctx.signal }); | |
| hit.addEventListener('keydown', (e) => { | |
| if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); select(c.n, true); } | |
| }, { signal: ctx.signal }); | |
| svg.appendChild(hit); | |
| }); | |
| const c = byN[selected]; | |
| if (c) { | |
| note.innerHTML = `<b>Call ${c.n}: ${c.role}.</b> ${c.why}${c.illustrative ? ' (Token count illustrative.)' : ''}`; | |
| } else if (mask) { | |
| note.textContent = 'Only the sampled tokens of agent calls train (purple). Prompts and tool results stay in the sequence as context with mask 0. The title call (auxiliary) and the abandoned attempt (discarded) are not trained.'; | |
| } else { | |
| note.textContent = 'Each node is one model call, in the order the proxy received it. A call links to the earlier call whose prompt and reply its own prompt starts with. Click a call to see its role and why.'; | |
| } | |
| if (fromKey) svg.querySelectorAll('.cg-hit')[fromKey - 1].focus({ preventScroll: true }); | |
| } | |
| return ({ width: w }) => { width = w; draw(); }; | |
| }, { deps: [] }); | |
| </script> | |
| </div> | |
| </body> | |
| </html> | |