trl icon indicating copy to clipboard operation
trl copied to clipboard

Align BCO with DPO: Support sync_ref_model

Open DaoyuanLi2816 opened this issue 5 months ago • 0 comments

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=True together 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=True together with precompute_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 with sync_ref_model=True and ref_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.py passes locally; ruff check / ruff format --check clean.

[!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.

BCOConfig gains sync_ref_model, ref_model_mixup_alpha, and ref_model_sync_steps. When sync_ref_model=True, the trainer registers SyncRefModelCallback after the reference model is prepared. sync_ref_model=True is rejected with NotImplementedError for PEFT (no separate ref_model) and with ValueError when combined with precompute_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.

DaoyuanLi2816 avatar Jun 30 '26 07:06 DaoyuanLi2816