Simplify tokenization [1/N]: Remove redundant is_vlm parameter#6298
Merged
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. |
1 task
qgallouedec
approved these changes
Jul 6, 2026
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.
Simplify tokenization [1/N]: Remove redundant
is_vlmparameter.This PR refactors the tokenization logic in the DPO, KTO, and SFT trainers to simplify the handling of VLM (Vision-Language Model) processors. The main change is to remove the explicit
is_vlmparameter from the tokenization functions and instead infer whether the processor is a VLM by checking its type. This reduces redundancy and streamlines the code.Changes
Tokenization logic simplification:
is_vlmparameter from the_tokenizeand relatedtokenize_fnfunctions indpo_trainer.py,kto_trainer.py, andsft_trainer.py. The code now determines if the processor is a VLM by checking if it is an instance ofProcessorMixin._tokenizeandtokenize_fnto remove theis_vlmargument, passing only the necessary parameters.Documentation updates:
is_vlmparameter from function docstrings to reflect the new logic and avoid confusion.Behavioral consistency:
These changes make the codebase easier to maintain and less error-prone by reducing unnecessary parameters and centralizing the logic for determining processor type.
Note
Low Risk
Mechanical refactor with the same VLM branch logic; risk is only if a non-processor were misclassified, which matches existing trainer
processing_classtyping.Overview
DPO, KTO, and SFT dataset preprocessing no longer threads an explicit
is_vlmflag through_tokenizeand thedataset.maptokenize_fnhelpers.Inside
_tokenize, vision-language handling (multimodal message prep and unwrapping the processor batch dimension) is keyed offisinstance(processing_class, ProcessorMixin)instead of a caller-supplied boolean.fn_kwargsfor mapping dropis_vlm/self._is_vlm, and docstrings no longer document that parameter.Intended behavior for tokenizer vs processor paths is unchanged; this is API cleanup ahead of further tokenization refactors.
Reviewed by Cursor Bugbot for commit 604866f. Bugbot is set up for automated code reviews on this repo. Configure here.