Downloads · 30 days
19
18% of all-time downloads
Xiejiehang/ERNIE-Image-NF4
ERNIE-Image-NF4 is a text-to-image model from Xiejiehang. Use it when you need an image from a text prompt. It is set up for diffusers. The card lists the license as apache-2.0.
ERNIE-Image-NF4 is a BitsAndBytes 4-bit NF4 quantized version of ERNIE-Image. The goal is to preserve the original inference workflow as much as possible while significantly reducing model size and deployment cost.
Downloads · 30 days
19
18% of all-time downloads
All-time downloads
108
Public
Parameters
4.1B
9.3 GB on disk
Likes
3
Public
Click a slice to open those files.
.safetensors9.3 GB · 100%
How the weights are stored.
U84.1B · 100%
From the Hugging Face model README
ERNIE-Image-NF4 is a BitsAndBytes 4-bit NF4 quantized version of ERNIE-Image. The goal is to preserve the original inference workflow as much as possible while significantly reducing model size and deployment cost.
⚠️ Quality Disclaimer: This quantized model has NOT been evaluated for generation quality degradation. No systematic side-by-side comparison (e.g., FID, CLIP Score, human evaluation) has been conducted between the original
ERNIE-ImageandERNIE-Image-NF4. NF4 quantization may introduce noticeable artifacts, loss of fine detail, reduced prompt adherence, or other quality regressions — especially in challenging scenarios such as complex compositions, small text rendering, or subtle color gradients. Users are strongly advised to run their own quality evaluations before relying on this model for production or quality-sensitive use cases.
This project uses the BitsAndBytes quantization path supported by Hugging Face Diffusers and Transformers:
4-bit NF4bnb_4bit_use_double_quant=Truebfloat16transformer, text_encoder, pevae, scheduler, tokenizer, pe_tokenizerQuantization metadata is stored in:
quantization_metadata.jsonExperiment setup:
NVIDIA GeForce RTX 5090A realistic orange kitten sits on a wooden desk with a white sheet of paper that says Hello ERNIE-Image NF4, soft natural lighting, centered composition.512x51250guidance_scale=4.0seed=1234enable_model_cpu_offload()transformer, text_encoder, and pe on GPU, with vae kept in bfloat16Results:
| Metric | Original ERNIE-Image | ERNIE-Image-NF4 | Observation |
|---|---|---|---|
| Load time | 3.60 s | 7.70 s | Quantized model still loads slower |
| Inference time | 50.52 s | 23.23 s | Quantized model is about 2.17x faster |
| Total time | 54.12 s | 30.93 s | Quantized model is about 1.75x faster overall |
| Peak reserved VRAM | 15.62 GiB | 9.95 GiB | Peak memory drops by about 36.29% |
To better reflect sustained generation throughput, an additional benchmark was run on the current machine with one-time model loading followed by 10 consecutive generations under identical settings.
Experiment setup:
NVIDIA GeForce RTX 5090A realistic orange kitten sits on a wooden desk with a white sheet of paper that says Hello ERNIE-Image NF4, soft natural lighting, centered composition.512x51250guidance_scale=4.01234, incremented by 1 for each imageenable_model_cpu_offload()transformer, text_encoder, and pe on GPU, with vae kept in bfloat16Results:
| Metric | Original ERNIE-Image | ERNIE-Image-NF4 | Observation |
|---|---|---|---|
| Load time | 3.72 s | 7.77 s | Quantized model still loads slower |
| Total time for 10 images | 470.70 s | 241.54 s | Quantized model is about 1.95x faster |
| Average inference time per image | 47.07 s | 24.15 s | Quantized model is about 1.95x faster |
| Peak reserved VRAM | 15.66 GiB | 10.01 GiB | Reserved memory drops by about 36.07% |
| Peak allocated VRAM | 15.48 GiB | 9.25 GiB | Allocated memory drops by about 40.23% |
Interpretation:
Below is a minimal runnable example:
from pathlib import Path
import torch
from diffusers import AutoModel, ErnieImagePipeline
from transformers import AutoModel as TransformersAutoModel
from transformers import AutoModelForCausalLM
model_dir = Path("ERNIE-Image-NF4")
transformer = AutoModel.from_pretrained(
str(model_dir / "transformer"),
torch_dtype=torch.bfloat16,
device_map={"": 0},
local_files_only=True,
)
text_encoder = TransformersAutoModel.from_pretrained(
str(model_dir / "text_encoder"),
torch_dtype=torch.bfloat16,
device_map={"": 0},
local_files_only=True,
)
pe = AutoModelForCausalLM.from_pretrained(
str(model_dir / "pe"),
torch_dtype=torch.bfloat16,
device_map={"": 0},
local_files_only=True,
)
pipe = ErnieImagePipeline.from_pretrained(
str(model_dir),
transformer=transformer,
text_encoder=text_encoder,
pe=pe,
torch_dtype=torch.bfloat16,
local_files_only=True,
)
pipe.vae.to("cuda", dtype=torch.bfloat16)
image = pipe(
prompt="一只橙色的小猫坐在木桌上,前面放着一张写有 Hello Ernie-Image NF4 的白纸,纸张和文字在画面中布局居中,柔和自然光,写实风格。",
height=512,
width=512,
num_inference_steps=50,
guidance_scale=4.0,
use_pe=True,
generator=torch.Generator(device="cuda").manual_seed(1234),
).images[0]
image.save(model_dir / "demo_output.png")