Align KTO with DPO: Validate Liger kernel configuration before trainer initialization#6227
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
| if self.precompute_ref_logps: | ||
| raise ValueError( | ||
| "You cannot use `precompute_ref_log_probs=True` with liger kernel. Please set " | ||
| "`precompute_ref_log_probs=False`." | ||
| ) |
There was a problem hiding this comment.
in dpo it's
"Liger DPO loss does not support precomputing reference log probabilities. Either disable "
"`precompute_ref_log_probs` or set `use_liger_kernel` to False."There was a problem hiding this comment.
This PR is just a move of the Liger validation checks, to before super().__init__(); no error message modification.
Individual error message alignment is handled in other PR:
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a6c4cb3. Configure here.

This PR moves the validation of the
use_liger_kernelconfiguration in the experimentalKTOTrainerto beforesuper().__init__(), aligning it withDPOTrainer.Motivation
The Liger kernel checks (kernel availability, unsupported loss type, precompute_ref_log_probs, and PEFT) depend only on the config and the input model, so there is no reason to run them after the expensive
super().__init__()(model loading, dataset preparation, reference model creation, accelerator setup).DPOTraineralready validates these beforesuper().__init__(), whileKTOTrainerdid it after, so an invalid configuration was rejected only at the end of a costly initialization.Solution
The validation checks are moved ahead of
super().__init__()so an invalid Liger configuration fails fast. The construction of the fused Liger loss stays aftersuper().__init__()because it depends on self.ref_model, which is only resolved during the reference model setup that runs after the parent initialization.Changes
precompute_ref_log_probs, PEFT) beforesuper().__init__()inKTOTrainerLigerFusedLinearKTOLossconstruction aftersuper().__init__(), whereself.ref_modelis availablesuper().__init__()Note
Low Risk
Init-order refactor only; validation rules are unchanged aside from using the local
modelfor the PEFT check beforeself.modelexists.Overview
KTOTrainer now runs all
use_liger_kernelvalidation (package install, loss type,compute_metrics,precompute_ref_log_probs, PEFT) beforesuper().__init__(), matching DPOTrainer so bad Liger settings fail immediately instead of after model load, dataset prep, and accelerator setup.LigerFusedLinearKTOLossis still constructed only aftersuper().__init__()and reference-model setup, with a short comment that it depends onself.ref_model. The PEFT guard uses the localmodelargument instead ofself.model, which is not assigned until the parent init runs.Reviewed by Cursor Bugbot for commit e4364bb. Bugbot is set up for automated code reviews on this repo. Configure here.