Skip to content

Simplify tokenization [1/N]: Remove redundant is_vlm parameter#6298

Merged
albertvillanova merged 3 commits into
mainfrom
simplify-tokenize-1
Jul 6, 2026
Merged

Simplify tokenization [1/N]: Remove redundant is_vlm parameter#6298
albertvillanova merged 3 commits into
mainfrom
simplify-tokenize-1

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Jul 6, 2026

Copy link
Copy Markdown
Member

Simplify tokenization [1/N]: Remove redundant is_vlm parameter.

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_vlm parameter 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:

  • Removed the is_vlm parameter from the _tokenize and related tokenize_fn functions in dpo_trainer.py, kto_trainer.py, and sft_trainer.py. The code now determines if the processor is a VLM by checking if it is an instance of ProcessorMixin.
  • Updated all calls to _tokenize and tokenize_fn to remove the is_vlm argument, passing only the necessary parameters.

Documentation updates:

  • Removed references to the is_vlm parameter from function docstrings to reflect the new logic and avoid confusion.

Behavioral consistency:

  • The logic for preparing multimodal messages is now consistently applied based on processor type, ensuring that the correct processing is performed for both VLM and non-VLM cases.

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_class typing.

Overview
DPO, KTO, and SFT dataset preprocessing no longer threads an explicit is_vlm flag through _tokenize and the dataset.map tokenize_fn helpers.

Inside _tokenize, vision-language handling (multimodal message prep and unwrapping the processor batch dimension) is keyed off isinstance(processing_class, ProcessorMixin) instead of a caller-supplied boolean. fn_kwargs for mapping drop is_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.

@bot-ci-comment

bot-ci-comment Bot commented Jul 6, 2026

Copy link
Copy Markdown

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.

@albertvillanova albertvillanova merged commit 31b5f42 into main Jul 6, 2026
14 checks passed
@albertvillanova albertvillanova deleted the simplify-tokenize-1 branch July 6, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants