Align CPO/ORPO with DPO: Add evaluate() override
Follow-up to #6116 (core trainers), #6148 (KTO) and #6195 (TPO): CPOTrainer and ORPOTrainer preprocess eval_dataset in __init__ but don't override evaluate(), so passing a raw (unprocessed) dataset directly to evaluate(eval_dataset=...) — e.g. a held-out test set — fails because the columns don't match the tokenized signature:
ValueError: No columns in the dataset match the model's forward method signature...
This adds an evaluate() override to both trainers that preprocesses a directly-passed dataset the same way __init__ does (extract prompt → apply chat template → tokenize), mirroring DPO/KTO/TPO. A str (which selects an eval dataset already prepared at init time) is left untouched, and dicts are handled per key.
BCOTrainer has the same gap, but its tokenization path is different (module-level _tokenize with reference/embedding precomputation), so I've left it for a separate PR.
Verification
- Added
test_evaluate_with_raw_datasetto both trainers — each fails onmainwith theValueErrorabove and passes with this change. - Full
tests/experimental/test_cpo_trainer.pyandtests/experimental/test_orpo_trainer.pypass locally;ruff check/ruff format --checkclean.
[!NOTE] Low Risk Behavioral fix aligned with DPO/KTO/TPO; only affects eval when passing a non-string dataset to evaluate(), with no training or auth changes.
Overview CPOTrainer and ORPOTrainer now override
evaluate()so a raw preference dataset passed at call time (e.g. a held-out test split) is preprocessed like__init__: extract prompt → chat template →tokenize_row, thensuper().evaluate()runs.streval keys (datasets already tokenized at init) are unchanged;dicteval sets are prepared per key underPartialState().main_process_first().Regression tests
test_evaluate_with_raw_datasetwere added for both trainers to asserteval_lossis returned when evaluating an unprocessed zen preference dataset.Reviewed by Cursor Bugbot for commit c0d2a6f8a305741c899e89cda284e17b4eb472c7. Bugbot is set up for automated code reviews on this repo. Configure here.