Skip to content

Diff-style SFT export for repair turns (cut token waste) - #55

Merged
ai-hpc merged 1 commit into
mainfrom
feat/diff-style-repair-export
Jul 26, 2026
Merged

Diff-style SFT export for repair turns (cut token waste)#55
ai-hpc merged 1 commit into
mainfrom
feat/diff-style-repair-export

Conversation

@ai-hpc

@ai-hpc ai-hpc commented Jul 26, 2026

Copy link
Copy Markdown
Member

Implements the last item from the dataset-quality critique: multi-turn episodes re-emit the whole ~100-line kernel on every repair even when <10% of lines change (~⅓ of repairs), wasting most of the tokens.

What it does

New opt-in export mode that renders repair/optimize assistant turns as a unified diff against the previous attempt, keeping the <think> rationale:

  • episodes.render_repair_as_diff + episode_to_messages(repair_style="full" | "diff")
  • hf_dataset threads repair_style through trajectory_to_messages_record / publish_bundle_to_hf; diff rows are tagged metadata.repair_style="diff"
  • sparkproof-publish-dataset --repair-style {full,diff} (default full, so nothing changes unless asked)

Trust boundary untouched

This is an export-view transform only. The raw/attested trajectories.jsonl, code_sha256, and Merkle leaves keep the complete runnable code — validation and verification are unaffected. Falls back to full content when a repair has no code delta.

Measured savings (real data)

On the live sparkproof-mining multi-turn rows (17 rows / 22 repair turns): repair-turn size drops ~23% (~30.2K → ~23.4K tokens). Honest caveat: modest here because this batch's repairs have a 15% median churn (some are large rewrites); for the many <10%-churn repairs the reduction is far larger. A consumer (SparkDistill) opts in and applies the patch to reconstruct full code.

Tests (+5, 381 total, ruff clean)

diff render (reasoning preserved, shrinks, no-change fallback), episode diff vs full-default, trajectory record marks repair_style and emits diffs.

Multi-turn episodes re-emitted the full ~100-line kernel on every repair even
when only a few lines changed (~1/3 of repairs change <10% of lines). Add an
opt-in export mode that renders repair/optimize assistant turns as a unified
diff against the previous attempt, preserving the <think> rationale.

- episodes.render_repair_as_diff + episode_to_messages(repair_style="full"|"diff").
- hf_dataset.trajectory_to_messages_record / publish_bundle_to_hf thread
  repair_style; diff rows are marked metadata.repair_style="diff".
- sparkproof-publish-dataset --repair-style {full,diff} (default full).

Export-view only: the raw/attested trajectories.jsonl, code_sha256, and Merkle
leaves keep the complete runnable code, so the trust boundary is untouched. On
the current merged data this cuts repair-turn size ~23% (more for small-diff
repairs); no-op fallback to full when a repair has no code delta.

Tests: diff render (reasoning kept, shrinks, no-change fallback), episode diff
vs full, trajectory record marks repair_style + emits diffs.
@ai-hpc
ai-hpc merged commit 6494aad into main Jul 26, 2026
1 check passed
@ai-hpc
ai-hpc deleted the feat/diff-style-repair-export branch July 26, 2026 09:26
@ai-hpc ai-hpc mentioned this pull request Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant