Align KTO with DPO: quantization_config trainer argument#6276
Align KTO with DPO: quantization_config trainer argument#6276qgallouedec wants to merge 2 commits into
quantization_config trainer argument#6276Conversation
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.
Reviewed by Cursor Bugbot for commit 6a7e848. Configure here.
| logger.warning( | ||
| "You passed `quantization_config` to the trainer, but your model is already instantiated. The " | ||
| "`quantization_config` will be ignored." | ||
| ) |
There was a problem hiding this comment.
Ref load ignores quantization warning
Medium Severity
When model is already instantiated, the trainer logs that quantization_config will be ignored, but auto-created reference models still inject that config into ref_model_init_kwargs. Full fine-tuning without PEFT can then pair an unquantized policy with a separately loaded quantized reference, producing inconsistent reference log-probs.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6a7e848. Configure here.
|
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a7e848653
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ref_model_init_kwargs = args.model_init_kwargs or {} | ||
| ref_model_init_kwargs = dict(args.model_init_kwargs or {}) # copy to avoid mutating model_init_kwargs | ||
| if quantization_config is not None: | ||
| ref_model_init_kwargs["quantization_config"] = quantization_config |
There was a problem hiding this comment.
Avoid quantizing only the implicit reference model
When callers pass an already-instantiated non-PEFT model together with quantization_config, the trainer warns above that the config is ignored because the model is already instantiated, but this branch still injects it while auto-creating the reference model. In that scenario KTO compares an unquantized policy against a 4/8-bit reference instead of the initial policy, changing the loss despite the argument being reported as ignored; only propagate this config here when it was also used to load the policy model, or require an explicit matching ref_model.
Useful? React with 👍 / 👎.


Ports the
quantization_configtrainer argument added toDPOTrainerin #6157 toKTOTrainer, to streamline QLoRA (pass aBitsAndBytesConfigdirectly instead of stuffing it intomodel_init_kwargs).Mirrors DPO exactly. No behavior change unless
quantization_configis passed.Note
Low Risk
Additive API and script refactor aligned with existing DPO behavior; default training paths are unchanged unless
quantization_configis passed.Overview
KTOTrainernow accepts an optionalquantization_config(BitsAndBytesConfig) when loading from a model id, matchingDPOTrainer: it is merged intomodel_init_kwargsfor the policy and auto-created reference model, with aValueErrorif both the argument andargs.model_init_kwargsset quantization, and a warning if the model is already instantiated.The
trl/scripts/kto.pyentry point no longer loads model, ref model, and tokenizer up front; it passes the model path to the trainer, setstraining_args.model_init_kwargsfromModelConfig, and wiresget_quantization_config(model_args)andget_peft_config(model_args)for QLoRA-style runs.Reviewed by Cursor Bugbot for commit 6fd39d8. Bugbot is set up for automated code reviews on this repo. Configure here.