Fix smolvlm2 dtype mismatch final#41485
Open
omsherikar wants to merge 17 commits intohuggingface:mainfrom
Open
Fix smolvlm2 dtype mismatch final#41485omsherikar wants to merge 17 commits intohuggingface:mainfrom
omsherikar wants to merge 17 commits intohuggingface:mainfrom
Conversation
perception_lm: export PerceptionEncoder alias for auto mapping
molbap
reviewed
Oct 10, 2025
Contributor
molbap
left a comment
There was a problem hiding this comment.
There's no need to open that many PRs, please. Further, the fix it introduces seems OK but the bug wasn't reproduced. The first step is to prove the bug is reproducible. Can you provide a small script that causes the bug deterministically?
- Fix RuntimeError in inputs_merger when using BitsAndBytesConfig with bf16 - Add dtype conversion to ensure image_hidden_states matches inputs_embeds dtype - Add test to verify quantization compatibility Fixes huggingface#41453 (cherry picked from commit b7fe3bf)
- Add dtype conversion fix to modular_smolvlm.py inputs_merger function - Ensure consistency between modular and generated files - Fixes repo consistency check failures (cherry picked from commit ebd2189)
4f195d3 to
42e5c66
Compare
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: perception_lm, smolvlm |
This was referenced Apr 29, 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.
Fix SmolVLM2 quantization dtype mismatch
What does this PR do?
Fixes #41453 - SmolVLM2 cannot be used with quantization due to dtype mismatch error.
Problem: When loading SmolVLM2 with BitsAndBytesConfig and bfloat16, the
inputs_mergerfunction fails with:Root Cause:
inputs_embedstotorch.bfloat16(from BitsAndBytesConfig)image_hidden_statesintorch.float32Solution: Added dtype conversion to ensure
image_hidden_statesmatchesinputs_embedsdtype before assignment:Changes:
src/transformers/models/smolvlm/modeling_smolvlm.py- Added dtype conversion ininputs_mergerfunctionsrc/transformers/models/smolvlm/modular_smolvlm.py- Aligned modular file with same fixtests/models/smolvlm/test_modeling_smolvlm.py-test_quantization_dtype_compatibility()with@slowdecoratorTesting: The fix has been thoroughly tested and verified to resolve the quantization dtype mismatch issue without breaking existing functionality.
Fixes #41453
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@yonigozlan @molbap - This affects vision models and quantization functionality