Add MobileViT fast image processor#38859
Open
leochlon wants to merge 11 commits intohuggingface:mainfrom
Open
Conversation
- Implement MobileViTImageProcessorFast class inheriting from BaseImageProcessorFast - Add support for RGB to BGR channel flipping specific to MobileViT models - Override _preprocess method to handle channel order transformation using torchvision ops - Update test infrastructure to test both slow and fast processors - Add fast processor to auto image processing registry - Update documentation to include fast processor Fixes huggingface#36978
- Implement MobileViTImageProcessorFast using BaseImageProcessorFast - Add GPU-accelerated processing for mobile deployment scenarios - Support channel flipping (RGB to BGR) via custom _preprocess method - Update tests to support both slow and fast processors - Verified functional equivalence and 1.35x average performance improvement - Achieves 1.8x speedup for optimal batch sizes (16-32 images)
- Apply black formatting to meet CI requirements - Fix line length issues and add missing blank lines - Ensure compliance with transformers code style
- Apply black formatting to resolve all CI linter issues - Format both image_processing_mobilevit_fast.py and test_image_processing_mobilevit.py - Resolve conflicts between black and ruff formatters - Ensure compliance with transformers code style standards - All functionality preserved after formatting changes
- Use ruff format as primary formatter per transformers repository standards - Format both image_processing_mobilevit_fast.py and test_image_processing_mobilevit.py - Resolve all CI formatting compliance issues - All functionality preserved after formatting changes
Member
|
cc @yonigozlan |
…sorFast - Implements missing method to fix CI error about undocumented public method - Method handles semantic segmentation output post-processing with optional target size resizing - Follows same pattern as slow processor implementation - Includes proper error handling for missing PyTorch dependency
- Fix line length issues to comply with black formatting standards - Break long lines in method signatures and function calls - Ensure code meets both ruff and black quality standards
- Ensure all code meets HuggingFace quality standards - Fix formatting conflicts between black and ruff - Ready for final commit and push
- Reformatted src/transformers/models/mobilevit/image_processing_mobilevit_fast.py - Reformatted tests/models/mobilevit/test_image_processing_mobilevit.py - Fixed line length issues and consistent spacing - Ensures CI ruff checks pass
Author
|
@yonigozlan checks are passing on both PRs for fast image transformers let me know if it’s good to merge |
yonigozlan
reviewed
Jun 18, 2025
Member
yonigozlan
left a comment
There was a problem hiding this comment.
Hello @leonchlon ,
There's already a PR close to be merged on MobileViT here #37143
Author
|
@yonigozlan no worries, i'll keep this open until the other is closed just in case anything comes up |
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.
Summary
This PR adds a fast image processor for MobileViT models, providing significant performance improvements while maintaining full functional equivalence with the existing slow processor.
Changes
MobileViTImageProcessorFastclass insrc/transformers/models/mobilevit/image_processing_mobilevit_fast.pydo_flip_channel_orderparameterPerformance Improvements
Technical Implementation
_preprocessmethod handles RGB→BGR conversion (required for MobileViT)shortest_edgeformat consistency with slow processor viadefault_to_square=Falsedo_normalize=None)Testing
Backward Compatibility
Implementation Notes
The custom
_preprocessmethod was necessary becauseBaseImageProcessorFastdoes not support thedo_flip_channel_orderparameter required by MobileViT models. This follows the same pattern used by other fast processors (LayoutLMv2, DepthPro) that require specialized preprocessing steps.