Align KTO collator keys with the DPO convention#6182
Open
qgallouedec wants to merge 3 commits into
Open
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
KTO's collator named the assembled prompt+completion model input
completion_input_ids/completion_attention_maskmisleading (it's not completion-only), and the trainer renamed it straight back toinput_idsbefore every forward. This aligns the keys with DPO: the policy branch is unprefixed, and a prefix marks only the KL branch.completion_input_ids→input_ids,completion_attention_mask→attention_maskKL_completion_input_ids→KL_input_ids,KL_completion_attention_mask→KL_attention_maskKL_completion_token_type_ids→KL_token_type_ids,KL_completion_mm_token_type_ids→KL_mm_token_type_idscompletion_mask/KL_completion_maskunchanged (they correctly mark completion positions); dataset columns (prompt_ids,completion_ids,KL_completion_ids) unchanged.Removes the now-dead
model_kwargs.pop("completion_input_ids")renames in the forward and the redundantoutput.pop("input_ids")in the vision collator (now identical to the DPO/SFT vision collators).Note
Medium Risk
Renames every batch key on the KTO training path (text, VLM, Liger, ref log-prob precompute); behavior should be equivalent but any external code or forks expecting
completion_input_idswill break.Overview
Renames KTO collator and trainer batch tensor keys so the policy forward path matches DPO/SFT: full prompt+completion sequences are exposed as
input_ids/attention_maskinstead ofcompletion_input_ids/completion_attention_mask, with KL branches underKL_input_ids,KL_attention_mask, and (for VLMs)KL_token_type_ids/KL_mm_token_type_ids.completion_maskandKL_completion_maskstay as-is; dataset columns (prompt_ids,completion_ids,KL_completion_ids) are unchanged.The trainer no longer renames collator keys before
model(**kwargs)(removedpop("completion_input_ids")style shims). The vision collator writes assembled tensors directly into the output dict instead of dropping processorinput_idsand aliasing them under the old names. Tests are updated to assert the new keys.Reviewed by Cursor Bugbot for commit 1e16213. Bugbot is set up for automated code reviews on this repo. Configure here.