Spaces:
Running

precisionpatch / index.html
doraking's picture
writeup: final header and links
f356eb1 verified
Raw History Blame Contribute Delete
8.58 kB
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>PrecisionPatch</title>
<style>
:root { --bg:#fff; --ink:#1b1f24; --muted:#5a6370; --line:#d9dee4; --code:#f4f6f8; --accent:#1d6a85; }
@media (prefers-color-scheme: dark) { :root { --bg:#111418; --ink:#e6eaee; --muted:#9aa4af; --line:#2a3139; --code:#1a1f25; --accent:#62b3d0; } }
body { margin:0; background:var(--bg); color:var(--ink); font:16px/1.65 system-ui,-apple-system,"Segoe UI",sans-serif; }
main { max-width:760px; margin:0 auto; padding:24px 16px 64px; }
h1 { font-size:1.6em; line-height:1.3; } h2 { margin-top:1.8em; border-bottom:1px solid var(--line); padding-bottom:.2em; }
a { color:var(--accent); } img { max-width:100%; background:#fff; border:1px solid var(--line); border-radius:6px; }
table { border-collapse:collapse; width:100%; font-size:.95em; display:block; overflow-x:auto; }
th,td { border:1px solid var(--line); padding:6px 8px; text-align:left; }
code { background:var(--code); padding:1px 4px; border-radius:4px; font-size:.9em; }
pre { background:var(--code); padding:12px; border-radius:6px; overflow-x:auto; } pre code { padding:0; }
</style></head><body><main><h1>PrecisionPatch: teaching a 4B model to propose floating-point fixes that a verifier can certify</h1>
<p>Team lead: @dorakingx · White Circle Halo Competition, track <code>ft-hf</code> · 2026-12-03</p>
<p>Code: <a href="https://github.com/dorakingx/halo/tree/precisionpatch/simulation">github.com/dorakingx/halo, branch <code>precisionpatch</code></a> · Model: <a href="https://huggingface.co/doraking/precisionpatch-qwen3-4b-lora">doraking/precisionpatch-qwen3-4b-lora</a> · Data: <a href="https://huggingface.co/datasets/doraking/precisionpatch-data">doraking/precisionpatch-data</a></p>
<h2>What and why</h2>
<p><code>sqrt(x+1) - sqrt(x)</code> loses almost every significant bit for large <code>x</code>; <code>1/(sqrt(x+1) + sqrt(x))</code> is the same real
function and stays accurate. Tools such as Herbie find rewrites like this by search. Recent work prompted large LLMs
for the same job and found that their rewrites were often not equivalent: they changed constants, dropped branches or
shrank the input domain (Nguyen et al., arXiv 2604.04854).</p>
<p>We asked a narrower question: <strong>if a small model may only edit what is safe to edit, and every answer is checked by an
independent verifier, does post-training it with Halo on verified rewrites make it useful?</strong></p>
<h2>Method</h2>
<p><strong>Task.</strong> A program over 1–3 binary64 variables (<code>+ - * / sqrt log exp log1p expm1 fabs</code>, optional guards <code>x &lt; c</code>).
The model sees the program with guards fixed and constants referred to by ID, the input box of each branch and the
current error, and answers with JSON: a new body per branch, or "keep". It cannot touch guards, constants or domains.</p>
<p><strong>Verifier (the part that makes an answer count).</strong></p>
<ol>
<li>The answer must parse in a restricted grammar (no new literals beyond small integers, no new branches).</li>
<li>It is <em>certified</em> only if a chain of sound rewrite rules (57, each with side conditions proved by interval
arithmetic on the branch's box) turns the original into it; a different real value at any checked input is a proof
of non-equivalence and rejects it.</li>
<li>Error is <code>log2(1 + ULP distance)</code> against the correctly rounded binary64 value of the original real expression,
enclosed with arb or mpmath interval arithmetic (the two backends agree bit for bit on 15,488 reference values).
The candidate is chosen on 256 probe inputs and scored once on 4,096 disjoint audit inputs.</li>
</ol>
<p>An answer is an <strong>effective improvement</strong> if it is certified, lowers the audit mean error by at least max(0.1 bit, 10%),
does not raise the 95th percentile and creates no NaN/inf.</p>
<p><strong>Data and split.</strong> 915 FPCore programs from FPBench and Herbie's benchmark suite give 310 eligible tasks, 301 after removing exact duplicates. Tasks are
grouped by expression skeleton (up to commutativity and variable renaming) and source function, and whole groups go to
one split: 54 test tasks in 40 groups, 10 dev tasks, the rest train. The training set (1,471 rows) uses train tasks
and generated variants only; each answer is the rule-search or Herbie candidate the verifier certified, or "keep".
Generated tasks that collide with any dev/test task were dropped.</p>
<p><strong>Training.</strong> <code>Qwen/Qwen3-4B-Instruct-2507</code> (rev <code>cdbee75f</code>), LoRA r 64 on all projections, 2 epochs, Halo 1.3.0
<code>scripts/training/sft.py</code>, one H200 on Hugging Face Jobs: 42 optimizer steps, about 90 seconds per run.</p>
<p><strong>Protocol.</strong> The design, split and analysis were fixed and committed before the test split was opened. Each method
proposes up to 8 candidates (1 greedy + 7 sampled); 3 training seeds × 3 sampling seeds for SFT, 3 sampling seeds for
the base model.</p>
<h2>Results (held-out test split, 54 tasks, 40 groups)</h2>
<table>
<thead>
<tr>
<th>Method</th>
<th>effective-improvement rate (k = 8)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Base model</td>
<td>0.000</td>
</tr>
<tr>
<td>Base model, two worked examples in the prompt</td>
<td>0.019</td>
</tr>
<tr>
<td><strong>After Halo SFT</strong></td>
<td><strong>0.113</strong></td>
</tr>
<tr>
<td>Rule beam search over the same rewrite rules (no LLM)</td>
<td>0.167</td>
</tr>
<tr>
<td>Herbie 2.3, outputs inside the same contract</td>
<td>0.074</td>
</tr>
</tbody>
</table>
<p>Paired per-task differences with 95% group-bootstrap intervals:</p>
<ul>
<li>SFT − Base: <strong>+0.113 [+0.029, +0.218]</strong> — the pre-registered primary contrast, positive.</li>
<li>SFT − few-shot Base: +0.095 [−0.002, +0.206]; SFT − rule search: −0.053 [−0.167, +0.051];
SFT − Herbie: +0.039 [−0.039, +0.128] — all intervals contain 0.</li>
<li>Per training seed (k = 8, mean of 3 sampling seeds): 0.130, 0.105, 0.105. The released adapter is training seed 0,
the recipe's seed fixed at design time, so the evaluation command below gives 0.130 for it and 0.000 for the base
model.</li>
</ul>
<p><img alt="Test results" src="main_test.png" /></p>
<p>What changed in the model: 58% of the base model's answers were valid in the answer grammar and none was certified; after SFT
97% are valid and 10.7% of all candidates are certified. On 7 of 54 tasks SFT finds an effective fix (for example
<code>exp(a·x) − 1 → expm1(a·x)</code>, <code>log(1 + eˣ) → log1p(eˣ)</code>, <code>sqrt(x+1) − sqrt(x) → 1/(sqrt(x+1) + sqrt(x))</code>).</p>
<p><strong>What this does not show.</strong> The fine-tuned model is not better than a plain rule search over the same rules; the
search solves 9 tasks, 5 of them the same. Herbie's own outputs improve more programs numerically, but most of them
use new constants, <code>fma</code> or Taylor approximations and fall outside the contract. The benchmarks are public, so "held
out" means held out from our training, not unseen by the base model.</p>
<h2>Reproduce</h2>
<pre><code class="language-bash"># in the Halo image (hopper-1.3.0), from the repository root
python scripts/training/sft.py simulation/configs/sft_qwen3_4b_lora_teacher_v1.yaml --seed=0 --report_to=none
python simulation/scripts/eval_model.py --model doraking/precisionpatch-qwen3-4b-lora --split test --sampling-seed 0
python simulation/scripts/eval_model.py --model Qwen/Qwen3-4B-Instruct-2507 --split test --sampling-seed 0
</code></pre>
<p>The baselines and the pre-registered analysis: <code>simulation/scripts/pilot.py</code> and <code>simulation/analysis/main_analysis.py</code>.</p>
<h2>Third-party material</h2>
<ul>
<li>Model: Qwen/Qwen3-4B-Instruct-2507, revision <code>cdbee75f17c01a7cc42f958dc650907174af0554</code> (Apache-2.0).</li>
<li>Benchmarks: FPBench <code>408c85c0</code> and Herbie <code>bench/</code> <code>884621aa</code> (MIT). Baseline and teacher: Herbie 2.3.</li>
<li>Libraries: Halo 1.3.0, python-flint 0.7.1, mpmath 1.3.0.</li>
</ul>
<h2>Platforms used</h2>
<ul>
<li><strong>Hugging Face Jobs</strong>: all training and evaluation, 1× H200, 1.1 GPU-hours in total ($5.50 of competition credits);
a private storage bucket for code and checkpoints.</li>
<li><strong>Hugging Face Hub</strong>: model and dataset repositories, and this writeup.</li>
<li>Herbie, the rule search and the analysis ran on a laptop CPU.</li>
</ul></main></body></html>