Align KTO with DPO: Support tool calling#6259
Open
qgallouedec wants to merge 2 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.
KTOTrainerignored thetoolscolumn during tokenization, so tool schemas were never rendered into the prompt. Tool-calling datasets trained as if no tools were defined.The existing
test_train_toolcall_data(mirrors DPO's, usestrl-internal-testing/toolcall) now genuinely exercises tool rendering; it passes.Matches DPO's behavior: tool calling is supported on the text path; the vision collator does not wire tools through in either trainer.
#4786
Note
Low Risk
Small change to KTO preprocessing only; it corrects tokenization for datasets that already carry a
toolscolumn and does not touch loss, reference model, or auth paths.Overview
KTO text-path training now renders tool schemas in prompts, matching DPO behavior for tool-calling datasets.
During dataset tokenization,
KTOTrainerreads each example’s optionaltoolsfield (JSON-parsing when stored as a string) and forwards it intoapply_chat_templatefor both the generation prompt and the full prompt+completion sequence. Previously those columns were ignored, so KTO trained on tool data as if no tools existed.For vision datasets,
"tools"is added to the trainer’s signature columns so it is retained when unused columns are removed (the vision collator still does not wire tools through, same as DPO).Reviewed by Cursor Bugbot for commit c198c65. Bugbot is set up for automated code reviews on this repo. Configure here.