Fix Auto classes to support dynamically registered processors #41865
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.
What does this PR do?
This PR fixes Auto classes (
AutoImageProcessorandAutoVideoProcessor) to properly support dynamically registered processors via the.register()method.Problem
When users call
AutoImageProcessor.register()orAutoVideoProcessor.register(), the registration only updates the*_MAPPINGobjects (specifically their_extra_content), not the*_MAPPING_NAMESdictionaries. However, some code paths were checking*_MAPPING_NAMESinstead of*_MAPPING, which meant registered processors would not be recognized in certain code paths.Changes
image_processing_auto.pyfor-elseloop that checked ifimage_processor_typeexists inIMAGE_PROCESSOR_MAPPING_NAMES.values()with a direct call toget_image_processor_class_from_name(), which properly checks both the static mapping and registered items viaIMAGE_PROCESSOR_MAPPING._extra_contentvideo_processing_auto.pyif video_processor_class_inferred in VIDEO_PROCESSOR_MAPPING_NAMES.values()to usingvideo_processor_class_from_name(video_processor_class_inferred) is not None, which properly checks both the static mapping and registered itemsWhy This Matters
The helper functions like
get_image_processor_class_from_name()andvideo_processor_class_from_name()are designed to check both:*_MAPPING_NAMESdictionaries (for built-in processors)*_MAPPING._extra_contentdictionaries (for dynamically registered processors)By using these helper functions instead of directly checking
*_MAPPING_NAMES.values(), we ensure that dynamically registered processors are properly recognized throughout the codebase.Testing
The changes maintain backward compatibility with existing code while adding support for registered processors. The helper functions already have the logic to handle both static and dynamic mappings.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@ArthurZucker @Cyrilvallez (model loading)