generated from fastai/nbdev_template
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
👩🦯 Fix usage of VLM using text only #4080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
qgallouedec
merged 16 commits into
huggingface:main
from
SamuelBarryCS:fix-vlm-for-text-only-data
Sep 23, 2025
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5ac5bbe
Fix issue
SamuelBarryCS a2a43c3
push test
SamuelBarryCS 9bef39d
Push test
SamuelBarryCS 20f74d1
Merge branch 'main' into fix-vlm-for-text-only-data
SamuelBarryCS ff6a276
Merge branch 'main' into fix-vlm-for-text-only-data
sergiopaniego 6465594
Add test in test_sft_trainer.py
SamuelBarryCS caa8046
Fix tests ?
SamuelBarryCS c54f1a2
doc
SamuelBarryCS 98d998f
Merge branch 'main' into fix-vlm-for-text-only-data
SamuelBarryCS 9487ead
revert to main
SamuelBarryCS ca6770b
remote min
SamuelBarryCS df7edee
Merge branch 'main' into fix-vlm-for-text-only-data
SamuelBarryCS 7e041f6
Merge branch 'main' into fix-vlm-for-text-only-data
sergiopaniego 5e78dd2
revert
qgallouedec 8d52bae
different approach
qgallouedec 28a0560
Merge branch 'main' into fix-vlm-for-text-only-data
qgallouedec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """Test for issue #3957 - VLM KeyError fix""" | ||
|
|
||
| from unittest.mock import MagicMock | ||
| import torch | ||
| from trl.trainer.sft_trainer import DataCollatorForVisionLanguageModeling | ||
|
|
||
|
|
||
| def test_collator(): | ||
| processor = MagicMock() | ||
| processor.apply_chat_template = MagicMock(return_value=["test"]) | ||
| processor.return_value = {"input_ids": torch.tensor([[1, 2, 3]]), "attention_mask": torch.tensor([[1, 1, 1]])} | ||
|
|
||
| collator = DataCollatorForVisionLanguageModeling(processor=processor) | ||
|
|
||
| # Test with images | ||
| examples = [{"images": ["img"], "messages": [{"role": "user", "content": "test"}]}] | ||
| collator(examples) | ||
| assert "images" in processor.call_args.kwargs | ||
|
|
||
| # Test without images (failed before the fix) | ||
| processor.reset_mock() | ||
| processor.return_value = {"input_ids": torch.tensor([[1, 2, 3]]), "attention_mask": torch.tensor([[1, 1, 1]])} | ||
| examples = [{"messages": [{"role": "user", "content": "test"}]}] | ||
| collator(examples) | ||
| assert "images" not in processor.call_args.kwargs | ||
|
|
||
| print("Tests passed") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| test_collator() | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be deleted before merging