Skip to content

[Ernie-Image] Add lora support#13575

Merged
sayakpaul merged 4 commits intomainfrom
ernie-lora-support
Apr 30, 2026
Merged

[Ernie-Image] Add lora support#13575
sayakpaul merged 4 commits intomainfrom
ernie-lora-support

Conversation

@asomoza
Copy link
Copy Markdown
Member

@asomoza asomoza commented Apr 28, 2026

What does this PR do?

Adds initial lora support for Ernie-Image:

import torch
from diffusers import ErnieImagePipeline

pipe = ErnieImagePipeline.from_pretrained("baidu/ERNIE-Image-Turbo", torch_dtype=torch.bfloat16)
pipe.load_lora_weights("HexWave/Ernie_Lora_pack", weight_name="Yumikon.safetensors")
pipe.enable_model_cpu_offload()

prompt = "yum1kon, a capybara wearing a jacket and riding a skate in the city street."
images = pipe(
    prompt=prompt,
    height=1264,
    width=848,
    num_inference_steps=8,
    guidance_scale=1.0,
    generator=torch.Generator("cuda").manual_seed(42),
    use_pe=False,
).images
images[0].save("ernie-image-turbo-output.png")
w/o lora lora
ernie_fp8_1264x848_42 ernie_fp8_1264x848_42_lora

Fixes #13501

Who can review?

@sayakpaul @SamuelTallet @kayselmecnun

@github-actions github-actions Bot added fixes-issue size/L PR with diff > 200 LOC documentation Improvements or additions to documentation lora models pipelines loaders labels Apr 28, 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.

@asomoza asomoza requested a review from sayakpaul April 28, 2026 15:07
@asomoza
Copy link
Copy Markdown
Member Author

asomoza commented Apr 28, 2026

@claude do a review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Claude finished @asomoza's task in 3m 19s —— View job


Review of PR #13575: [Ernie-Image] Add lora support

  • Read review guidelines (AGENTS.md, models.md, pipelines.md)
  • Read the PR diff
  • Review src/diffusers/loaders/__init__.py
  • Review src/diffusers/loaders/lora_pipeline.py
  • Review src/diffusers/models/transformers/transformer_ernie_image.py
  • Review src/diffusers/pipelines/ernie_image/pipeline_ernie_image.py
  • Check top-level exports
  • Post review feedback

Overall

Clean, well-structured PR. The implementation correctly follows the established LoRA loader mixin pattern (copies from CogVideoXLoraLoaderMixin / SD3LoraLoaderMixin), the model and pipeline inheritance changes are correct, and the # Copied from annotations are properly set. The state dict key transformation logic is appropriately customized for Ernie-Image's architecture. No major issues found.

Detailed Findings

1. src/diffusers/loaders/lora_pipeline.pyErnieImageLoraLoaderMixin

  • lora_state_dict: The PEFT → diffusion_model.*transformer.* key remapping chain is correct and the comment at lines 5896–5898 explaining why only the prefix needs to change (module paths already match diffusers naming) is a nice touch.
  • load_lora_weights (line 5906): Correctly # Copied from CogVideoXLoraLoaderMixin.load_lora_weights.
  • load_lora_into_transformer (line 5949): Correctly # Copied from SD3LoraLoaderMixin.load_lora_into_transformer with SD3Transformer2DModel->ErnieImageTransformer2DModel.
  • save_lora_weights, fuse_lora, unfuse_lora: All correctly # Copied from their CogVideoX counterparts.

2. src/diffusers/models/transformers/transformer_ernie_image.py

  • Adding PeftAdapterMixin to the MRO of ErnieImageTransformer2DModel (line 292) is the correct pattern for enabling LoRA adapter loading on the transformer.
  • MRO order (ModelMixin, ConfigMixin, PeftAdapterMixin) is consistent with other transformer models.

3. src/diffusers/pipelines/ernie_image/pipeline_ernie_image.py

  • Adding ErnieImageLoraLoaderMixin to the pipeline's MRO (line 35) is correct.
  • MRO order (DiffusionPipeline, ErnieImageLoraLoaderMixin) matches the established pattern.

4. src/diffusers/loaders/__init__.py

  • Properly registered in both _import_structure["lora_pipeline"] (line 88) and the TYPE_CHECKING block (line 121), in alphabetical order.

5. docs/source/en/api/loaders/lora.md

  • Correctly placed. The [[autodoc]] section is in the right spot.

Nits (non-blocking)

None for this PR, but I noticed a pre-existing typo on line 38 of docs/source/en/api/loaders/lora.mdLTX2LoraLoaderMixin says "provides similar functions for [Flux2]" instead of "LTX2". Not from this PR but worth a follow-up fix.

Verdict

LGTM — the implementation is clean, follows conventions, and I don't see any correctness issues. 👍


Copy link
Copy Markdown
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

So good!

@github-actions github-actions Bot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 30, 2026
@github-actions github-actions Bot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 30, 2026
@github-actions github-actions Bot added size/L PR with diff > 200 LOC and removed size/L PR with diff > 200 LOC labels Apr 30, 2026
@sayakpaul sayakpaul merged commit 303c1d8 into main Apr 30, 2026
34 of 37 checks passed
@sayakpaul sayakpaul deleted the ernie-lora-support branch April 30, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation fixes-issue loaders lora models pipelines size/L PR with diff > 200 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LoRA support for ERNIE-Image

4 participants