06 · Test the training stack
Compare supervised, preference and reward stages on the same invoices, then decide which checkpoint earns the next trial.
- Part 2
- Compare training stages
- Model
Qwen/Qwen2.5-0.5B-Instruct- Data
- Course Invoice v1, visible text with separately stored gold records
- Hardware
- Tesla T4, in Google Colab
You own the invoice-to-ledger extraction check. In this synthetic Course Invoice v1 notice, the fee subtotal and tax add to €825.36. The supplier has printed €826.37 as the amount requested. Which figure belongs in the extraction record, and what should accounts payable review?
Ref SF-228773 / EUR Service fee notice, 2026-05-10 Sample Supplier 4464 Unit 31,75 / 9 times / Cable sleeve Unit 74,11 / 6 times / Cooling filter Fee subtotal 730,41 Plus tax 94,95 Amount requested 826,37
Reveal the amount to extract
Store total_minor: 82637 because the extraction contract copies the amount printed on the notice. Send the €1.01 difference for reconciliation. Check the line items too. The cable sleeve has quantity 9 and a unit price of 3,175 cents.
Supervised fitting accounts for most of the measured gain
Exact records, percentage-point change on 240 held-out invoices
159.2 pp · 95% interval 41.7 to 75.8 pp
1.3 pp · 95% interval -2.1 to 4.2 pp
0.0 pp · 95% interval 0.0 to 0.0 pp
0.0 pp · 95% interval 0.0 to 0.0 pp
1.3 pp · 95% interval -2.1 to 4.2 pp
Grade the whole invoice
Every tuned checkpoint copies 82,637 cents from SF-228773 and produces valid JSON. Each also swaps quantity and unit price. The cable sleeve becomes quantity 3,175 at 9 cents, and the cooling filter has the same kind of swap. The two factors still multiply to the same amount. Matching a total and passing the schema can therefore conceal a record that would enter the wrong inventory quantities.
Compare the expected record with all five outputs
SF-228773 · held-out notice
- Expected
- {"invoice_id":"SF-228773","issued_on":"2026-05-10","supplier":"Sample Supplier 4464","currency":"EUR","line_items":[{"description":"Cable sleeve","quantity":9,"unit_minor":3175},{"description":"Cooling filter","quantity":6,"unit_minor":7411}],"subtotal_minor":73041,"tax_minor":9495,"total_minor":82637}
- Prompted base
- ```json { "invoice_id": "SF-228773", "issued_on": "2026-05-10", "supplier": "Sample Supplier 4464", "currency": "EUR", "line_items": [ { "description": "Cable sleeve", "quantity": 31, "unit_minor": 9 }, { "description": "Cooling filter", "quantity": 6, "unit_minor": 6 }, { "description": "Total", "quantity": 0, "unit_minor": 0 } ], "subtotal_minor": 730.41, "tax_minor": 94.95, "total_minor": 826.37 } ```
- SFT
- {"invoice_id":"SF-228773","issued_on":"2026-05-10","supplier":"Sample Supplier 4464","currency":"EUR","line_items":[{"description":"Cable sleeve","quantity":3175,"unit_minor":9},{"description":"Cooling filter","quantity":7411,"unit_minor":6}],"subtotal_minor":73041,"tax_minor":9495,"total_minor":82637}
- SFT → DPO
- {"invoice_id":"SF-228773","issued_on":"2026-05-10","supplier":"Sample Supplier 4464","currency":"EUR","line_items":[{"description":"Cable sleeve","quantity":3175,"unit_minor":9},{"description":"Cooling filter","quantity":7411,"unit_minor":6}],"subtotal_minor":73041,"tax_minor":9495,"total_minor":82637}
- SFT → GRPO
- {"invoice_id":"SF-228773","issued_on":"2026-05-10","supplier":"Sample Supplier 4464","currency":"EUR","line_items":[{"description":"Cable sleeve","quantity":3175,"unit_minor":9},{"description":"Cooling filter","quantity":7411,"unit_minor":6}],"subtotal_minor":73041,"tax_minor":9495,"total_minor":82637}
- SFT → DPO → GRPO
- {"invoice_id":"SF-228773","issued_on":"2026-05-10","supplier":"Sample Supplier 4464","currency":"EUR","line_items":[{"description":"Cable sleeve","quantity":3175,"unit_minor":9},{"description":"Cooling filter","quantity":7411,"unit_minor":6}],"subtotal_minor":73041,"tax_minor":9495,"total_minor":82637}
The independent evaluator compares each greedy record with the fixture, including the printed total and every ordered line. It keeps exact record match, validity and row F1 separate. Supervised fine-tuning (SFT) on checked demonstrations produced 142 additional exact records, a gain of 59.2 points with a 95% family-bootstrap interval from 41.7 to 75.8 points.
The swap in SF-228773 is easy to miss because the monetary arithmetic still balances at line level. The product is unchanged when the factors trade places. A stock update that reads the quantity would act on 3,175 sleeves. A financial check against the amount alone would see a plausible calculation. I’d show those fields independently in a review screen so the person signing off can compare the recorded quantity and price with their source columns. The whole-record scorer catches the swap because it checks the fields in place.
Save the exact response, the fixture and the natural stop flag together. If the output parsed and stopped naturally, start with the mismatch between the stored and visible fields. If the output stopped at the token cap, record the incomplete response and inspect the decoding budget. Those observations can lead to different fixes. Changing the reward for a semantic mistake on an incomplete answer gives little information about whether the model would have produced the right record with enough room to finish.
Compare each reward stage with its parent
Comparing each changed stage with its own unchanged parent helps separate the effect of that stage from improvements already earned earlier in the pipeline.
Train one SFT adapter and merge it into the base. Extend that checkpoint with DPO, then merge the DPO adapter as a second parent. Attach a fresh GRPO adapter to each parent. Both GRPO arms use the same training prompt IDs, learning rate and update budget, with fresh optimisers. The saved lineage identifies the weights that entered each stage. Verified run report
# Seal the merged SFT parent so both later comparisons have a known starting point.
warm_merged = merge_adapter(MODEL_ID, warm_path, "06-sft-merged")
warm_stage = record_stage(base_parent, warm_path, warm_merged)
warm_parent = warm_stage["merged"]Let E be exact-record rate on the same invoices, and let S, D and G denote the SFT, DPO and GRPO stages in order. The interaction asks whether the gain from GRPO changes when DPO comes first.
Reward training ties both starting checkpoints
Exact-record rates before and after matched GRPO
2SFT
Interaction 0.0 pp · 95% 0.0 to 0.0 pp
SFT → DPO
Interaction 0.0 pp · 95% 0.0 to 0.0 pp
| Candidate relative to named parent | Exact records gained | Exact records lost | Tied decisions |
|---|---|---|---|
| SFT against Prompted base | 142 | 0 | 98 |
| SFT → DPO against SFT | 7 | 4 | 229 |
| SFT → GRPO against SFT | 0 | 0 | 240 |
| SFT → DPO → GRPO against SFT → DPO | 0 | 0 | 240 |
The two reward comparisons matter because each parent enters the reward stage already able to do some extraction. If we only compared the full stack with SFT, the gains and losses introduced by DPO would be visible again in the final checkpoint. The matched parent comparison shows where they appeared. Keep the checkpoint lineage and the actual invoice identifiers alongside the headline so you can tell whether the additional stage carried the gain or inherited it.
Both gains were zero, and every invoice contributed zero to the interaction. The 0.0-to-0.0-point interval describes these uniform outcomes on the observed families, under these settings. The lab has one seed and ten reward updates per arm.
Ai2’s Tülu 3 reports its 8B development MATH score rising from 31.5 after SFT to 42.0 after DPO and 43.7 at the final stage. BigCodeBench fell from 11.5 to 9.5 to 7.4 across the same checkpoints. Save the intermediates and score each skill you plan to keep. Tülu 3 used PPO for its reward stage. Tülu 3, Table 31
Inspect the invoice layouts
Familiar layouts came from unseen suppliers using formats represented in training. Novel layouts were held out during fitting. The independent branch generated a separate synthetic format. Every tuned checkpoint got zero independent invoices completely right, even though mean row F1 was 88.9% there.
Familiar layouts remain easier after every training stage
Measured exact records and mean row F1 by invoice layout
3familiar · 96 invoices
Blue · exact record Orange · mean row F1
novel · 96 invoices
Blue · exact record Orange · mean row F1
independent · 48 invoices
Blue · exact record Orange · mean row F1
| Checkpoint | Familiar exact | Novel exact | Independent exact |
|---|---|---|---|
| Prompted base | 0/96 | 0/96 | 0/48 |
| SFT | 91/96 | 51/96 | 0/48 |
| SFT → DPO | 92/96 | 53/96 | 0/48 |
| SFT → GRPO | 91/96 | 51/96 | 0/48 |
| SFT → DPO → GRPO | 92/96 | 53/96 | 0/48 |
The familiar check asks whether a format learnt from one group of suppliers carries to unseen suppliers using a similar format. The novel check asks whether it carries to layouts held out from fitting. The independent branch uses another synthetic format. A single pooled rate can hide the failure on that branch, especially if a deployment mostly receives templates the team already knows. When choosing where to collect more examples, open mistakes from each slice first. The label prefix in SF-375561 suggests a concrete case to include in development, while the good row score gives a reason to preserve the extractor’s line-item behaviour.
SF-375561 · independent-layout invoice excerpt
- Source
- Biller Sample Supplier 8052 / As of 2025-03-27 / USD
- Expected field
- "supplier":"Sample Supplier 8052"
- Observed SFT field
- "supplier":"Biller Sample Supplier 8052"
On SF-375561, SFT got the rows right and copied the heading word Biller into the supplier field. That one extra word fails exact scoring. Teaching roster · Raw outputs and field scores
Check what the preference stage teaches
Direct preference optimisation (DPO) compares two responses to the same prompt. Here the chosen record for training invoice SF-651508 copies the printed amount. The rejected record changes only the last cent, from 82,830 to 82,831. Both completions have 109 tokens including the end marker. The tokenizer and collator checks apply across all 96 selected pairs.
Inspect the source and both exact responses
Sample Supplier 3103 billing memo / 2025-12-09 Account invoice SF-651508 [EUR] 4 x Meter label @ 146,22 per unit 1 x Bench calibration @ 148,13 per unit Total due 828,30 including tax 95,29; net amount 733,01.
SF-651508 · matched training pair
- Chosen
- {"invoice_id":"SF-651508","issued_on":"2025-12-09","supplier":"Sample Supplier 3103","currency":"EUR","line_items":[{"description":"Meter label","quantity":4,"unit_minor":14622},{"description":"Bench calibration","quantity":1,"unit_minor":14813}],"subtotal_minor":73301,"tax_minor":9529,"total_minor":82830}
- Rejected
- {"invoice_id":"SF-651508","issued_on":"2025-12-09","supplier":"Sample Supplier 3103","currency":"EUR","line_items":[{"description":"Meter label","quantity":4,"unit_minor":14622},{"description":"Bench calibration","quantity":1,"unit_minor":14813}],"subtotal_minor":73301,"tax_minor":9529,"total_minor":82831}
# Keep the rejected record valid while ensuring it fails the extraction check.
candidate = wrong_candidate(record)
assert score_record(packed(record), invoice)["exact"]
assert score_record(packed(candidate), invoice)["valid"]
assert not score_record(packed(candidate), invoice)["exact"]For prompt x, let the two responses be y+ and y−. The margin compares the policy’s chosen-minus-rejected log-probability difference with the same difference under the frozen SFT parent. Score only completion tokens through the end marker.
DPO changes eleven exact judgements
Paired outcomes excluding the prompted-base comparison
4DPO minus SFT
7 improved · 4 regressed · 138 tied correct · 91 tied wrong
GRPO minus SFT
0 improved · 0 regressed · 142 tied correct · 98 tied wrong
GRPO after DPO
0 improved · 0 regressed · 145 tied correct · 95 tied wrong
combined minus SFT
7 improved · 4 regressed · 138 tied correct · 91 tied wrong
The equal-length pair makes it easier to see what supervision we supplied. Both answers show the same supplier, dates and rows. Only the payable amount changes. The optimiser therefore sees examples of which total to prefer after the model has produced a plausible record. It hasn't been given a contrast between two ways of reading a quantity. To target that error, a proposed pair could preserve the visible invoice and swap quantity with unit price in the rejected answer. Test whether that mutation still yields valid JSON and fails exact scoring. Keep the generated-invoice evaluation to learn whether the model uses that distinction when choosing tokens for itself.
DPO fixed seven exact judgements and broke four. All 229 remaining invoices tied their SFT judgement, including 94 that both checkpoints got wrong. The +1.3-point average sits within the measured uncertainty. A one-cent preference pair targets a different error from the swapped line-item fields in SF-228773.
Pick the reward rate on development data
Fit each probe on the screen pool and score it on 12 separate development invoices. Select by exact match, then row F1, then the smaller learning rate. Neither the 240 teaching invoices nor the 120 reserved release invoices enter that decision.
# Prefer exact match, then row F1, then the smaller learning rate.
def select_rate(screen):
return max(screen, key=lambda rate: (*lr_score(screen[rate]["development"]), -rate))Both rates tie on the development screen
Twelve development invoices per probe
58e-06 · selected
12/12 exact · 100.0% row F1
18.81 trainer seconds
2e-05
12/12 exact · 100.0% row F1
17.72 trainer seconds
Both probes scored 12/12 exactly and had mean row F1 of 100%. The fixed tie-break picked 8e-6. In NVIDIA’s development comparison, adding GRPO to SFT moved its Nemotron Parse score from 66.24 to 71.38 across 2,078 ParseBench pages and reduced generation-cap hits from 185 to 35. Track record quality and termination separately to see where a reward stage helps. NVIDIA, Figure 3 and measurement notes
Check whether rollouts can teach
Group relative policy optimisation (GRPO) samples four responses for a prompt. A deterministic reward checks fields, rows and natural completion. Group-relative advantages compare responses within the group. When all four receive the same reward, the group supplies no relative preference signal. DeepSeekMath also sampled groups for GRPO, using a learned reward model and 64 samples per prompt in its math setting. DeepSeekMath, Sections 4.1 and 4.2
Both parents sample groups with zero reward variance
Ten prompt groups per arm · four completions in each group
6SFT → GRPO
10/10 at full mean reward · 10/10 tied · 0 cap hits
SFT → DPO → GRPO
10/10 at full mean reward · 10/10 tied · 0 cap hits
The reward closure keeps the observed rewards for the group and records the share of groups whose rewards are identical. The saved notebook reports that alongside termination and completion length. Here is how the closure makes sure it compares responses for the same invoice. A group is tied when every reward in it takes the same value.
# Group completions from the same invoice before checking reward spread.
rewards = [item[kind] for item in pairs]
groups = [rewards[i:i + GROUP_SIZE] for i in range(0, len(rewards), GROUP_SIZE)]
if (len(groups) != 1 or len(groups[0]) != GROUP_SIZE or len(record_key) != GROUP_SIZE
or len(set(record_key)) != 1 or len(set(gold)) != 1):
raise ValueError("Expected one group of four completions for a single invoice.")Before another reward fit, I’d run the verifier against known wrong records from the training format, then sample the parent’s responses on a development pool. If the verifier distinguishes the mutations but sampled groups still tie, look at which prompts and completions the policy is seeing. If the verifier gives the wrong records full credit, fix the reward before sampling more often. Neither change needs the held-out teaching roster for fitting. Use it to ask whether the resulting checkpoint gets more genuinely correct invoices through the same evaluation boundary.
Every sampled group under both parents had mean reward 1.0 and zero within-group reward variance. Both arms recorded ten completed optimiser updates and zero cap hits. The tied teaching scores are consistent with that absence of ranking signal on the training rollouts. The worked notice is held out and its swapped fields did not appear in those sampled groups.
The full stack adds trainer time for the same score as DPO
Cumulative fitted-stage seconds by checkpoint
7Separate overhead · 25.00 s preflight wall time · 36.53 s probe trainer time
What to keep
| Decision | Evidence to use |
|---|---|
| Keep SFT as the extraction reference | It reached 142/240 exact against 0/240 from Prompted base. |
| Keep DPO as a candidate for targeted evaluation | It reached 145/240, with a paired 95% interval of −2.1 to +4.2 points relative to SFT. |
| Defer the GRPO extensions under these settings | Both added fitted-stage time and tied every exact judgement against their respective parents. |
| Hold independent layouts for review | Every tuned checkpoint got 0/48 independent records completely right. |
- Preserve the printed payable amount. Keep the discrepancy on SF-228773 visible for reconciliation.
- Check quantity and unit price independently. Matching monetary arithmetic cannot reveal a swap of the factors.
- Save weights at each stage. Keep the parent and optimiser setup identifiable so you can attribute a change to the intended stage.
- Report paired gains and losses. Checkpoint replacement can send some correct invoices back to manual review even when the overall score rises.
- Check the reward spread before extending the fit. Full-credit ties across the sampled groups offer no within-group ranking.
- Next to try, not tested here: Add checked line-field preference pairs and evaluate the consequence on the matched novel layout slice.
How it was built
| Item | Setting |
|---|---|
| Base model | Qwen2.5-0.5B-Instruct at revision 7ae557604adf67be50417f59c2c2f167def9a775, seed 42. |
| Data | Synthetic Course Invoice v1. Fixed pools of 288 SFT invoices, 96 selected DPO pairs, 64 GRPO prompts and 32 screen prompts. |
| Test | 12 development invoices and 240 teaching invoices across 20 supplier families. A separate 120-invoice release roster stays sealed. Intervals use a paired family bootstrap. |
| Method | Merge SFT into the base, fit DPO against the merged SFT parent, then apply a fresh GRPO adapter separately to the SFT and SFT → DPO parents. |
| Training | 32 SFT updates, 20 DPO updates, ten reward updates per parent at 8e-6. One disposable long-input update per stage checks the memory budget. The FP16 DPO scaler starts at 1.0. |
| Decoding | Greedy evaluation with a 256-token cap. Reward training samples four responses per prompt at temperature 0.8. |
| Hardware | Tesla T4 with PyTorch 2.14.1+cu130, Transformers 4.51.3, PEFT 0.15.2, TRL 0.19.1, Accelerate 1.6.0 and Datasets 3.6.0. |
Time and cost. SFT took 24.12 seconds at 3.39 GiB peak allocated and DPO took 18.62 seconds at 2.17 GiB. GRPO took 62.49 seconds after SFT and 57.57 seconds after DPO, both at 3.35 GiB. The unmerged stage adapter weight files are 3,557,696 bytes each. These timings exclude setup, merges and evaluation. The full notebook execution receipt records 1,284.701 seconds.
Executed notebook · Run report and checkpoint lineage · T4 profile · Teaching roster · Raw outputs
Run it yourself
The saved execution took 1,284.701 seconds on the T4. Start with section 8 for the whole-record grade and layout breakdown. Find SF-228773 in the raw outputs and verify that the tuned methods preserve the printed total while swapping the line fields. Notebook sections 2 and 6 describe the preference stage, section 5 explains the rate screen, and section 7 produces the rollout check. Predict the result before changing one cell at a time.
- In section 2, replace the one-cent mutation with a line-field mutation. First predict whether the fitted stage will reduce swaps on novel layouts. Keep the pair-length check and inspect the raw quantity and unit-price fields in the matched evaluation.
- In section 5, predict how a shorter generation cap would affect the development ranking. Lower the cap for evaluation of both probes and inspect the development exact scores and natural stop flags.
- In section 7, predict whether the other screened learning rate would change the reward spread. Try it for both GRPO parents, keeping the prompt IDs and update budget matched. Compare the recorded share of tied groups before looking at exact scores.
How is this page?
Last updated on