Skip to content

Add ernie image - #13432

Merged
yiyixuxu merged 18 commits into
huggingface:mainfrom
HsiaWinter:add-ernie-image
Apr 11, 2026
Merged

Add ernie image#13432
yiyixuxu merged 18 commits into
huggingface:mainfrom
HsiaWinter:add-ernie-image

Conversation

@HsiaWinter

Copy link
Copy Markdown
Contributor

What does this PR do?

We have introduced a new text-to-image model called ERNIE-Image, which will soon be open-sourced to the community. This PR includes the model architecture definition, the pipeline, as well as the related documentation and test files.

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@github-actionsgithub-actionsBot added documentation Improvements or additions to documentation models tests utils pipelines size/L PR with diff > 200 LOC labels Apr 8, 2026

@yiyixuxuyiyixuxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks for the PR!
i left some feedbacks

Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/pipelines/ernie_image/pipeline_ernie_image.py Outdated
Comment threadsrc/diffusers/pipelines/ernie_image/pipeline_ernie_image.py Outdated
Comment threadsrc/diffusers/pipelines/ernie_image/pipeline_ernie_image.py Outdated
Comment threadsrc/diffusers/pipelines/ernie_image/pipeline_ernie_image.py Outdated
@yiyixuxu
yiyixuxu requested a review from dg845April 8, 2026 09:02
@github-actionsgithub-actionsBot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 8, 2026

@yiyixuxuyiyixuxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks!
i left a few more comments

Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py Outdated
Comment threadsrc/diffusers/pipelines/ernie_image/pipeline_ernie_image.py Outdated
Comment threadsrc/diffusers/pipelines/ernie_image/pipeline_ernie_image.py Outdated
Comment threadsrc/diffusers/pipelines/ernie_image/pipeline_ernie_image.py Outdated
@github-actionsgithub-actionsBot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 9, 2026

@yiyixuxuyiyixuxu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks! left two small comments
let's merge this soon

Comment threadsrc/diffusers/models/transformers/transformer_ernie_image.py
Comment threadtests/models/transformers/test_models_transformer_ernie_image.py Outdated
@yiyixuxu

Copy link
Copy Markdown
Collaborator

@claude can you do a review here also? please keep these 3 note in mind as well during your review

  1. compare the Ernie model/pipeline to others like Qwen/Flux —let us know if there is any significant inconsistencies you found.
  2. if you see any unused code paths, let us know
  3. Look over the PR comments I made and check if the same patterns we caught/fixed still exist elsewhere in the code.

@github-actions

Copy link
Copy Markdown
Contributor

Claude Code is working…

I'll analyze this and get back to you.

View job run

@github-actionsgithub-actionsBot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 10, 2026
@github-actionsgithub-actionsBot added the size/L PR with diff > 200 LOC label Apr 10, 2026
@github-actionsgithub-actionsBot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 10, 2026
@yiyixuxu

Copy link
Copy Markdown
Collaborator

@bot /style

@github-actions

github-actionsBot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Style bot fixed some files and pushed the changes.

@github-actionsgithub-actionsBot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 10, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@yiyixuxu

Copy link
Copy Markdown
Collaborator

can you run make fix-copies? will merge once CI is green:)


# Initialize latents
if latents is None:
latents = torch.randn(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this should probably use the diffusers randn_tensor. Currently it will fail with a cpu generator which is needed for a consistent seed on different systems. ref

latents=randn_tensor(shape, generator=generator, device=device, dtype=dtype)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

fix

return text_bth, lens

@torch.no_grad()
def __call__(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would it be possible to add support for prompt_embeds and negative_prompt_embeds which would bypass needing to encode the prompt? Ref

prompt_embeds: list[torch.FloatTensor] |None=None,
negative_prompt_embeds: list[torch.FloatTensor] |None=None,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

fix

@github-actionsgithub-actionsBot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 11, 2026
@github-actionsgithub-actionsBot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 11, 2026
@yiyixuxu

Copy link
Copy Markdown
Collaborator

@bot /style

@github-actions

github-actionsBot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Style bot fixed some files and pushed the changes.

@github-actionsgithub-actionsBot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 11, 2026
@yiyixuxu
yiyixuxu merged commit dc8d903 into huggingface:mainApr 11, 2026
10 of 14 checks passed

def rope(pos: torch.Tensor, dim: int, theta: int) -> torch.Tensor:
assert dim % 2 == 0
scale = torch.arange(0, dim, 2, dtype=torch.float64, device=pos.device) / dim

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Quick question: is float64 mandatory here?
I experimented with float32 and image generation succeeded. On some GPU backends, float64 is not well supported; that can cause silent numerical issues or cryptic runtime errors.
Could the developers consider changing this to float32 so as to support more GPU backends?

@VargolVargolApr 14, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I can't believe they've done this again, the number of times issues have been raised about float64 being in a rope implementation you think there would be an automatic check by now. It not strictly necessary and to breaks MPS and NPU compatibility.

At least someone else raised age issue this time
https://github.com/huggingface/diffusers/pull/13464/changes

terarachang pushed a commit to terarachang/diffusers that referenced this pull request Apr 30, 2026
* Add ERNIE-Image
* Update doc
* Update doc
* Change from Custom-Attention to Diffusers Style Attention
* Change from Custom-Attention to Diffusers Style Attention
* 兼容SGLang
* 优化PE模块的加载与offload策略
* 更新Doc文件与config配置相关内容
* Fix官方反馈的内容
* 根据官方建议优化代码
* Update code
* update
* update
* Apply style fixes
* update
* update
* Apply style fixes
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentationImprovements or additions to documentationmodelspipelinessize/LPR with diff > 200 LOCtestsutils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@HsiaWinter@yiyixuxu@HuggingFaceDocBuilderDev@Vargol@jaretburkett@zjr1477713910@dg845