Skip to content

Comments

Allow fallback to loading from Auto"SubProcessor".from_pretrained when model_type can't be inferred from config#42402

Merged
yonigozlan merged 3 commits intohuggingface:mainfrom
yonigozlan:fix-auto-processor-raise-error-early
Dec 2, 2025
Merged

Allow fallback to loading from Auto"SubProcessor".from_pretrained when model_type can't be inferred from config#42402
yonigozlan merged 3 commits intohuggingface:mainfrom
yonigozlan:fix-auto-processor-raise-error-early

Conversation

@yonigozlan
Copy link
Member

What does this PR do?

Fixes #41846

Also remove some dead code in processing_auto.py

Cc @tomaarsen ;)

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@tomaarsen tomaarsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR, when combined with #42387 to fix PEFT loading, fixes my bug reproduction script from #41846. Thanks for opening this @yonigozlan. We should likely aim for a review from a core transformers maintainer, though.

cc @BenjaminBossan this is also looking good for your PR #42387 🤗

@BenjaminBossan
Copy link
Member

Thanks, Yoni. Yeah, let's try to get this and my PR merged for v5.

Copy link
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgt, only one comment about deleting feature extractors as fallback

Comment on lines 324 to 331
if preprocessor_config_file is not None and processor_class is None:
config_dict, _ = FeatureExtractionMixin.get_feature_extractor_dict(
pretrained_model_name_or_path, **kwargs
)
processor_class = config_dict.get("processor_class", None)
if "AutoProcessor" in config_dict.get("auto_map", {}):
processor_auto_map = config_dict["auto_map"]["AutoProcessor"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ig this was deleted because feature extractor and image processor have the same name when saved? There is still one difference though if the config was saved in the new nested format. I think we need to keep it

if "feature_extractor" in processor_dict or "audio_processor" in processor_dict:
feature_extractor_dict = processor_dict.get("feature_extractor", processor_dict.get("audio_processor"))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because it is actually never used unless I missed something. It's already called here:

preprocessor_config_file = cached_file(
pretrained_model_name_or_path, FEATURE_EXTRACTOR_NAME, **cached_file_kwargs
)
if preprocessor_config_file is not None:
config_dict, _ = ImageProcessingMixin.get_image_processor_dict(pretrained_model_name_or_path, **kwargs)
processor_class = config_dict.get("processor_class", None)
if "AutoProcessor" in config_dict.get("auto_map", {}):
processor_auto_map = config_dict["auto_map"]["AutoProcessor"]

and if we preprocessor_config_file is None above, it will be None here as well. If it's not None, then we'll never enter the code path I removed. So it seems like dead code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh you're right! It has a weird dependency because of this identical naming issue 🙃

I think we have to enter this codepath if processor_class is None because we would need to try to load the processor from feature extractor config if we can't still find it at this point. I think we have no tests for this specific case and it's quite rare which is why no issues until today. I still would like to keep it for full functionality

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I still think this code path is never entered 😅. But this can be addressed in another PR anyway, so I added this back.

@yonigozlan
Copy link
Member Author

Thanks for the reviews! @zucchini-nlp could you approve pls ;)

Copy link
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

[For maintainers] Suggested jobs to run (before merge)

run-slow: auto

@yonigozlan yonigozlan enabled auto-merge (squash) December 2, 2025 17:18
@yonigozlan yonigozlan merged commit 675e876 into huggingface:main Dec 2, 2025
23 checks passed
sarathc-cerebras pushed a commit to sarathc-cerebras/transformers that referenced this pull request Dec 7, 2025
…n model_type can't be inferred from config (huggingface#42402)

* fix raise error early

* add back feature extractor saving logic
SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Jan 23, 2026
…n model_type can't be inferred from config (huggingface#42402)

* fix raise error early

* add back feature extractor saving logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incompatibility single-modality AutoProcessor and PEFT Adapter

6 participants