Explain collator in SFTTrainer#330
Merged
sergiopaniego merged 1 commit intohuggingface:mainfrom Sep 23, 2025
Merged
Conversation
Added a few lines in section 4.3 to explain the role of the SFTTrainer in inferring that the model is a vision-language model and applying the appropriate collator.
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
stevhliu
approved these changes
Sep 22, 2025
Member
stevhliu
left a comment
There was a problem hiding this comment.
Thanks for the clarification! Also pinging @sergiopaniego for a look who authored this notebook :)
sergiopaniego
approved these changes
Sep 23, 2025
Member
sergiopaniego
left a comment
There was a problem hiding this comment.
Thanks for the addition! This is indeed a super recent feature huggingface/trl#3862 added to TRL.
|
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.
Explain the role of the SFTTrainer in inferring that the model is a vision-language model and applying the appropriate collator.
What does this PR do?
I was looking for resources for finetuning VLMs, specifically Qwen models. I followed the Qwen2-VL-7B model card and then the fine_tuning_vlm_trl.ipynb notebook. In both cases it is clear how to do inference and the preprocessing is done explicitly. However, when doing training the preprocessing is done implicitly through a collator that is infered by the trainer. This is not explained in the current notebook and took me some time to figure out especially since the notebook is resource heavy. I added a short passage in section 4.3 to explain this point and save time for others.
New text:
When doing inference we defined our own
generate_text_from_samplefunction which applied the necessary preprocessing before passing the inputs to the model. Here, the SFTTrainer infers automatically that the model is a vision-language model and applies aDataCollatorForVisionLanguageModelingwhich convers the inputs to the appropriate format.Who can review?
@merveenoyan @stevhliu