IWOPDTrainer can skip the mandatory vLLM weight sync when resuming from a checkpoint
Reproduction
VLLMGeneration loads weights from model.name_or_path only once, at construction time (trl/generation/vllm_generation.py), not from the trainer's live in-memory weights. The only thing that updates the vLLM engine's weights afterward is sync_weights(). So after resuming from a checkpoint, the engine keeps generating rollouts against the pre-resume weights until the next sync_weights() call.
IWOPDTrainer initializes _last_vllm_sync_step = -1 and gates the sync on self.state.global_step % self.vllm_sync_frequency == 0 (trl/experimental/iw_opd/iw_opd_trainer.py:666 and :872-873). After a resume, this only fires if the resumed step happens to be a multiple of vllm_sync_frequency — otherwise the sync is skipped entirely until the next multiple comes around.
GOLDTrainer implements the identical mechanism, under the same attribute names (trl/experimental/gold/gold_trainer.py:1107, :1597-1601), but initializes _last_vllm_sync_step = -self.vllm_sync_frequency and checks self.state.global_step >= self._last_vllm_sync_step + self.vllm_sync_frequency, which always fires once right after construction or resume:
def gold_should_sync(step, last_sync, freq):
return step != last_sync and step >= last_sync + freq # GOLDTrainer (correct)
def iwopd_should_sync(step, last_sync, freq):
return step != last_sync and step % freq == 0 # IWOPDTrainer (buggy)
resumed_step, freq = 37, 5
print(gold_should_sync(resumed_step, -freq, freq)) # True -- syncs immediately on resume
print(iwopd_should_sync(resumed_step, -1, freq)) # False -- keeps the stale, pre-resume weights
This is unreachable when distillation_objective="iw_opd", since IWOPDConfig forces vllm_sync_frequency=1 in that case (every step is a multiple of 1, so the two formulas always agree). It is reachable for distillation_objective="jsd" with use_vllm=True and vllm_sync_frequency>1, which IWOPDConfig permits.
How did you hit this?
Found by comparing IWOPDTrainer's vLLM weight-sync bookkeeping against the identical, correct mechanism in GOLDTrainer while auditing the experimental trainers for duplication drift (per the repo's "duplicated logic must stay consistent" guidance) — not from a production run. Confirmed by tracing both code paths and VLLMGeneration's weight-loading source, and with the arithmetic reproduction above.
System Info
- Platform: macOS-26.5.2-arm64
- Python version: 3.12
- PyTorch version: 2.14.1
- Transformers version: 5.18.0
- accelerator(s): cpu
- TRL version: main @ 5b365bf0
Checklist
- [x] I have checked that my issue isn't already filed (see open issues)
- [x] I have included my system information
- [x] Any code provided is minimal, complete, and reproducible
- [x] Any code provided is properly formatted in code blocks
- [x] Any traceback provided is complete
I have a fix ready (align _last_vllm_sync_step's init and the sync check with GOLDTrainer's existing, correct pattern) plus a regression test. Could this be assigned to me so I can open the PR?
Hi @qgallouedec, gentle ping on this one. The bug is still present on current main (c886cf2): IWOPDTrainer still initializes _last_vllm_sync_step = -1 and gates on global_step % vllm_sync_frequency == 0, so after a resume at a non-multiple step the vLLM engine keeps generating with pre-resume weights (jsd objective + use_vllm=True + vllm_sync_frequency > 1). My fix is a 2-line change that matches GOLDTrainer's existing pattern, plus a CPU regression test; the IW-OPD test file passes locally. Could you assign this to me so I can open the PR?
Thanks for the report, @sahil-mangla. Confirmed on current main.
One correction to the impact: the stale weights aren't the pre-resume weights. In colocate mode, VLLMGeneration builds the engine from model.name_or_path at construction time, before the checkpoint is loaded. In server mode, the server holds whatever model it was launched with. Either way, after resuming at a step that isn't a multiple of vllm_sync_frequency, rollouts come from the initial model weights until the next multiple. For example, resuming at step 37 with vllm_sync_frequency=5 means steps 37–39 are generated by the initial policy.
The cause is drift between the two copies of this logic. GOLDTrainer moved to the >= form when it switched to VLLMGeneration. IWOPDTrainer kept the older % == 0 form it inherited from DistillationTrainer.
I've assigned the issue to you, so feel free to open the PR.