Skip to content

perf(paro): replay calibration rows in larger optimizer steps (#5246) - #5279

Merged
Qubitium merged 1 commit into
mainfrom
fix/5246-paro-quant-speed
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5246-paro-quant-speed

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

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 is ceil(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 --- after
Loading

Fix

ParoConfig.opt_batch_size default 64 → 128. That halves the step count without dropping a single calibration row: _chunk_rows slices 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 exactly ceil(rows / batch_size) steps per epoch and each epoch replays every training row once.

docs/paro.md gains 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:

step batch steps/epoch quantize wikitext-2 PPL
64 32 171.9 s 20.0788
128 (new default) 16 108.2 s 19.9411

1.59x faster with no accuracy loss (PPL slightly better). The wider sweep from the same harness, for reference:

step batch 160 192 256
quantize 87.7 s 77.5 s 61.8 s
PPL 19.97 20.05 20.19

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.py 194 passed, 50 skipped (CPU-only run; the two new guards plus the updated default assertion). uvx [email protected] check gptqmodel docs/eora tests setup.py clean.

Not verified / not in this PR

  • The CUDA-graph stage is not made part of this change. While investigating, I measured that stage_cudagraph=True trains a different trajectory from the eager stage: on a 896x896 layer (2 rotation epochs, same seed) theta differs from eager by 1.8e-1 max abs. A candidate fix (in-graph zero_grad, warmup-state rewind, post-step LR schedule) narrows it to 1.8e-1 from 3.0e-1 but 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%.
  • Llama-3.2-1B was measured at bs=64 only (252.2 s, PPL 20.0717); the bs=128 run did not finish before the shared host was saturated.
  • ROCm/gfx1201 numbers are not re-measured (the issue's baseline was measured there).

#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
Qubitium marked this pull request as ready for review November 18, 2026 16:18
@Qubitium
Qubitium merged commit 899b509 into main Nov 18, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/5246-paro-quant-speed branch November 18, 2026 23:41
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.
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.

[PERF] TODO: recover ParoQuant quantize speed (1.7x slower since #5175) while keeping its accuracy gain

1 participant