Align BCO with DPO: Support sync_ref_model
Follow-up to #6152 ("Align KTO with DPO: Support sync_ref_model"): add TR-DPO reference-model synchronization to BCOTrainer. BCO is the last preference trainer with a real reference model that still lacks this — DPO and KTO both support it, and CPO/ORPO/TPO are reference-free so it doesn't apply to them.
This adds the three TR-DPO config fields (sync_ref_model, ref_model_mixup_alpha, ref_model_sync_steps) and wires up SyncRefModelCallback after the reference model is prepared, with the same two guards as KTO:
sync_ref_model=Truetogether with a PEFT model →NotImplementedError: with PEFT there is no standalone reference model to synchronize (BCO recovers reference behavior by disabling the adapter).sync_ref_model=Truetogether withprecompute_ref_log_probs=True→ValueError: precomputed reference log-probs would go stale as the reference model is periodically updated.
Verification
- Added
test_train_with_sync_ref_model(clone of the KTO test): trains withsync_ref_model=Trueandref_model_sync_steps=2, and asserts that both the policy and the reference model parameters change. Passes on a single GPU (RTX 4080). - Full
tests/experimental/test_bco_trainer.pypasses locally;ruff check/ruff format --checkclean.
[!NOTE] Medium Risk Changes BCO training dynamics when opt-in sync is enabled and touches reference-model lifecycle; default behavior stays off and mirrors an existing KTO/DPO pattern.
Overview BCOTrainer now supports periodic reference-model synchronization from TR-DPO, matching DPO and KTO.
BCOConfiggainssync_ref_model,ref_model_mixup_alpha, andref_model_sync_steps. Whensync_ref_model=True, the trainer registersSyncRefModelCallbackafter the reference model is prepared.sync_ref_model=Trueis rejected withNotImplementedErrorfor PEFT (no separateref_model) and withValueErrorwhen combined withprecompute_ref_log_probs=True(stale precomputed log-probs).A new integration test trains with sync enabled and asserts both policy and reference weights update.
Reviewed by Cursor Bugbot for commit 7bd713b4b2d8e25990b4330d98cc2dd831441aed. Bugbot is set up for automated code reviews on this repo. Configure here.