Avoid eager transformers>=5.0.0 requirement for ErnieImage prompt enhancer#14007
Open
dxqb wants to merge 1 commit into
Open
Avoid eager transformers>=5.0.0 requirement for ErnieImage prompt enhancer#14007dxqb wants to merge 1 commit into
dxqb wants to merge 1 commit into
Conversation
…ancer `Ministral3ForCausalLM` is only used to type/load the optional `pe` prompt-enhancer component, but importing it unconditionally at module level forced transformers>=5.0.0 on anyone importing `ErnieImagePipeline` or `ErnieImagePromptEnhancerStep`, even without using the prompt enhancer. Use `AutoModelForCausalLM` as the type hint instead. It resolves the concrete architecture lazily via transformers' own Auto* machinery only when the `pe` component is actually loaded, so the version requirement now only applies when the prompt enhancer is actually used. Fixes huggingface#13935
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.
What does this PR do?
Fixes #13935.
The obvious solution would be to make the import and the version check local to the function that uses the prompt enhancer. But Claude thinks it has found a solution that is more in line with your architecture, because
AutoModelForCausalLMis already used elsewhere.The error is then printed by transformers, with an already quite clear message that you need a newer transformers.
Let me know what you think:
Replaces
Ministral3ForCausalLMwithAutoModelForCausalLMas the type hint/ComponentSpectype for the optionalpeprompt-enhancer component inErnieImagePipeline/ErnieImagePromptEnhancerStep.AutoModelForCausalLMis available on any transformers version, and resolves the concrete architecture lazily through transformers' own Auto* machinery only whenpeis actually loaded viafrom_pretrained. Sotransformers>=5.0.0is now only required when the prompt enhancer is actually used, with a clear error from transformers itself at that point:ValueError: The checkpoint you are trying to load has model type
ministral3but Transformers does not recognize this architecture. This could be because of an issue with the checkpoint, or because your version of Transformers is out of date.You can update Transformers with the command
pip install --upgrade transformers.No behavior change for users already on transformers>=5.0.0.
🤖 Drafted by Claude
Who can review?