Explain collator in SFTTrainer #330
Merged
+4,221
−4,211
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_sample
function 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 aDataCollatorForVisionLanguageModeling
which convers the inputs to the appropriate format.Who can review?
@merveenoyan @stevhliu