|
| 1 | +<!--Copyright 2025 The HuggingFace Team. All rights reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 4 | +the License. You may obtain a copy of the License at |
| 5 | +
|
| 6 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +
|
| 8 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 9 | +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +specific language governing permissions and limitations under the License. |
| 11 | +--> |
| 12 | + |
| 13 | +# Ernie-Image |
| 14 | + |
| 15 | +<div class="flex flex-wrap space-x-1"> |
| 16 | + <img alt="LoRA" src="https://img.shields.io/badge/LoRA-d8b4fe?style=flat"/> |
| 17 | +</div> |
| 18 | + |
| 19 | +[ERNIE-Image] is a powerful and highly efficient image generation model with 8B parameters. Currently there's only two models to be released: |
| 20 | + |
| 21 | +|Model|Hugging Face| |
| 22 | +|---|---| |
| 23 | +|ERNIE-Image|https://huggingface.co/baidu/ERNIE-Image| |
| 24 | +|ERNIE-Image-Turbo|https://huggingface.co/baidu/ERNIE-Image-Turbo| |
| 25 | + |
| 26 | +## ERNIE-Image |
| 27 | + |
| 28 | +ERNIE-Image is designed with a relatively compact architecture and solid instruction-following capability, emphasizing parameter efficiency. Based on an 8B DiT backbone, it provides performance that is comparable in some scenarios to larger (20B+) models, while maintaining reasonable parameter efficiency. It offers a relatively stable level of performance in instruction understanding and execution, text generation (e.g., English / Chinese / Japanese), and overall stability. |
| 29 | + |
| 30 | +## ERNIE-Image-Turbo |
| 31 | + |
| 32 | +ERNIE-Image-Turbo is a distilled variant of ERNIE-Image, requiring only 8 NFEs (Number of Function Evaluations) and offering a more efficient alternative with relatively comparable performance to the full model in certain cases. |
| 33 | + |
| 34 | +## ErnieImagePipeline |
| 35 | + |
| 36 | +Use [ErnieImagePipeline] to generate images from text prompts. The pipeline supports Prompt Enhancer (PE) by default, which enhances the user’s raw prompt to improve output quality, though it may reduce instruction-following accuracy. |
| 37 | + |
| 38 | +We provide a pretrained 3B-parameter PE model; however, using larger language models (e.g., Gemini or ChatGPT) for prompt enhancement may yield better results. The system prompt template is available at: https://huggingface.co/baidu/ERNIE-Image/blob/main/pe/chat_template.jinja. |
| 39 | + |
| 40 | +If you prefer not to use PE, set use_pe=False. |
| 41 | + |
| 42 | +```python |
| 43 | +import torch |
| 44 | +from diffusers import ErnieImagePipeline |
| 45 | +from diffusers.utils import load_image |
| 46 | + |
| 47 | +pipe = ErnieImagePipeline.from_pretrained("baidu/ERNIE-Image", torch_dtype=torch.bfloat16) |
| 48 | +pipe.to("cuda") |
| 49 | +# If you are running low on GPU VRAM, you can enable offloading |
| 50 | +pipe.enable_model_cpu_offload() |
| 51 | + |
| 52 | +prompt = "一只黑白相间的中华田园犬" |
| 53 | +images = pipe( |
| 54 | + prompt=prompt, |
| 55 | + height=1024, |
| 56 | + width=1024, |
| 57 | + num_inference_steps=50, |
| 58 | + guidance_scale=4.0, |
| 59 | + generator=torch.Generator("cuda").manual_seed(42), |
| 60 | + use_pe=True, |
| 61 | +).images |
| 62 | +images[0].save("ernie-image-output.png") |
| 63 | +``` |
| 64 | + |
| 65 | +```python |
| 66 | +import torch |
| 67 | +from diffusers import ErnieImagePipeline |
| 68 | +from diffusers.utils import load_image |
| 69 | + |
| 70 | +pipe = ErnieImagePipeline.from_pretrained("baidu/ERNIE-Image-Turbo", torch_dtype=torch.bfloat16) |
| 71 | +pipe.to("cuda") |
| 72 | +# If you are running low on GPU VRAM, you can enable offloading |
| 73 | +pipe.enable_model_cpu_offload() |
| 74 | + |
| 75 | +prompt = "一只黑白相间的中华田园犬" |
| 76 | +images = pipe( |
| 77 | + prompt=prompt, |
| 78 | + height=1024, |
| 79 | + width=1024, |
| 80 | + num_inference_steps=8, |
| 81 | + guidance_scale=1.0, |
| 82 | + generator=torch.Generator("cuda").manual_seed(42), |
| 83 | + use_pe=True, |
| 84 | +).images |
| 85 | +images[0].save("ernie-image-turbo-output.png") |
| 86 | +``` |
0 commit comments