Repository navigation
perf(paro): replay calibration rows in larger optimizer steps (#5246) - #5279
Merged
Merged
Conversation
#5175 made every Paro module replay its full row budget, which restored the accuracy the pre-#5175 first-batch fallback had lost but multiplied the step count. The stage loop is launch-bound: each step issues ~40 host launches over a weight-sized tensor, so wall time tracks the number of steps, and the number of steps is ceil(train_rows / opt_batch_size) per epoch. Raise the default opt_batch_size from 64 to 128, so the 2048-row budget is replayed in 16 steps per epoch instead of 32. Every row is still visited exactly once per epoch (_chunk_rows slices contiguously and its chunks concatenate back to the sampled order), so this trades no calibration data for the lower launch count. Measured on Qwen2.5-0.5B-Instruct (128 C4 docs, 10+10 epochs, wikitext-2 PPL), both runs back-to-back on one RTX 4090: bs=64 171.9 s PPL 20.0788 bs=128 108.2 s PPL 19.9411 -> 1.59x faster, PPL not worse Adds two coverage guards for the invariant the speedup relies on: the chunker reproduces the row budget exactly, and a stage runs one step per chunk.
Qubitium
marked this pull request as ready for review
November 18, 2026 16:18
Qubitium
added a commit
that referenced
this pull request
Nov 19, 2026
…#5356) #5279 raised ParoConfig.opt_batch_size from 64 to 128 for speed, which halved the optimizer steps per epoch at a fixed LR. On Llama-3.2-1B-Instruct that cost 2.2% wikitext-2 PPL on the benchmark harness, giving back most of the accuracy #5175 had recovered. Scale the three stage LRs from the 64-row reference, so an opt-in larger step still moves proportionally further per epoch, and put the default back on the accuracy-tuned 64 rows. Measured on Llama-3.2-1B-Instruct (Paro 4-bit g128 fp16, 128 C4 docs, quantize -> save -> reload -> wikitext-2, 80x512): bs=64, 1x LR 20.0401 (reference) bs=128, 1x LR 20.4726 (+2.16%) bs=128, 2x LR 20.1953 (+0.77%) bs=128, 3x LR 20.1274 (+0.44%) bs=128, 4x LR 20.3361 (+1.48%) Linear LR scaling recovers most of the loss but not all of it: the remaining gap is the coarser best-state selection at half the validation checkpoints, which no LR can fix. The default therefore stays at 64, and the scaling keeps opt-in larger batches close to it. tests/test_paro.py: 249 passed. tests/test_paro_batch_lr_5306.py: 5 new tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5246.
Problem
#5175 made every Paro module replay its full sampled row budget (2112 rows by default) instead of silently training on the first batch. That restored the accuracy but multiplied the optimizer step count, and Paro quantize time went up ~1.7x.
The stage loop is launch-bound, not math-bound: each step issues ~40 host launches (rotation fwd/bwd, the fused quantize/dequantize STE, the loss,
AdamW) over a weight-sized tensor while the per-step GPU work is a few hundred microseconds. So wall time tracks the number of steps, and the number of steps isceil(train_rows / opt_batch_size)per epoch.flowchart LR subgraph before["Before: bs=64"] A1["2048 calibration rows"] --> B1["32 optimizer steps/epoch"] B1 --> C1["~40 host launches x 32"] C1 --> D1["171.9 s quantize"] end subgraph after["After: bs=128"] A2["2048 calibration rows"] --> B2["16 optimizer steps/epoch"] B2 --> C2["~40 host launches x 16"] C2 --> D2["108.2 s quantize"] end E["same rows, same order,<br/>visited once per epoch"] --- before E --- afterFix
ParoConfig.opt_batch_sizedefault 64 → 128. That halves the step count without dropping a single calibration row:_chunk_rowsslices the sampled rows contiguously and concatenating its chunks reproduces the sampled order exactly, so every row is still visited once per epoch. Only the number of rows that share one optimizer step changes.Two guards pin that invariant:
test_paro_chunk_rows_covers_every_row_exactly_once— concatenating the step chunks reproduces the row budget in order for divisible, ragged and oversized batches.test_paro_stage_runs_one_step_per_chunk_and_covers_each_epoch— a stage runs exactlyceil(rows / batch_size)steps per epoch and each epoch replays every training row once.docs/paro.mdgains a "Calibration step batching" section with the measurements.Evidence
Qwen2.5-0.5B-Instruct, 128 C4 calibration docs, 10 rotation + 10 finetune epochs, wikitext-2 PPL. Both runs back-to-back on the same RTX 4090 (GPU 4) on a shared host, same harness:
1.59x faster with no accuracy loss (PPL slightly better). The wider sweep from the same harness, for reference:
128 is the point where the speedup is large and PPL is still at its best; larger batches keep buying time but start costing accuracy.
Tests:
tests/test_paro.py194 passed, 50 skipped (CPU-only run; the two new guards plus the updated default assertion).uvx [email protected] check gptqmodel docs/eora tests setup.pyclean.Not verified / not in this PR
stage_cudagraph=Truetrains a different trajectory from the eager stage: on a 896x896 layer (2 rotation epochs, same seed)thetadiffers from eager by1.8e-1max abs. A candidate fix (in-graphzero_grad, warmup-state rewind, post-step LR schedule) narrows it to1.8e-1from3.0e-1but does not reach parity, so it is not shippable as an accuracy-preserving speed lever and is left out. That is the recommended follow-up if someone wants the remaining ~20%.