Skip to content

Avoid eager transformers>=5.0.0 requirement for ErnieImage prompt enhancer#14007

Open
dxqb wants to merge 1 commit into
huggingface:mainfrom
dxqb:fix-ernie-image-transformers-version-guard
Open

Avoid eager transformers>=5.0.0 requirement for ErnieImage prompt enhancer#14007
dxqb wants to merge 1 commit into
huggingface:mainfrom
dxqb:fix-ernie-image-transformers-version-guard

Conversation

@dxqb

@dxqb dxqb commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

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 AutoModelForCausalLM is 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 Ministral3ForCausalLM with AutoModelForCausalLM as the type hint/ComponentSpec type for the optional pe prompt-enhancer component in ErnieImagePipeline / ErnieImagePromptEnhancerStep. AutoModelForCausalLM is available on any transformers version, and resolves the concrete architecture lazily through transformers' own Auto* machinery only when pe is actually loaded via from_pretrained. So transformers>=5.0.0 is 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 ministral3 but 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?

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please reconsider transformers>=5.0.0

1 participant