Downloads · 30 days
0
ZJMuYun97/ERNIE-Image-Nunchaku
ERNIE-Image-Nunchaku is a machine learning model from ZJMuYun97. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Downloads · 30 days
0
Access
Public
Updated May 17, 2026
Repo size
4.9 GB
Likes
1
Public
Click a slice to open those files.
.safetensors4.9 GB · 100%
From the Hugging Face model README
This adds W4A4 quantized inference support for ERNIE Image Turbo to Nunchaku, delivering significant speedup and memory reduction with minimal quality loss.
Built on Nunchaku. We gratefully acknowledge their excellent work on efficient diffusion model inference.
# This fork adds ERNIE Image support to Nunchaku
git clone https://github.com/Hzj199/nunchaku.git
cd nunchaku
git submodule update --init --recursive
pip install build
NUNCHAKU_BUILD_WHEELS=1 python -m build --wheel --no-isolation
pip install dist/nunchaku-*.whl
import torch
from diffusers.pipelines.ernie_image.pipeline_ernie_image import ErnieImagePipeline
from nunchaku import NunchakuErnieImageTransformer2DModel
from nunchaku.utils import get_precision
precision = get_precision() # auto-detect: "int4" or "fp4"
rank = 64
transformer = NunchakuErnieImageTransformer2DModel.from_pretrained(
f"ZJMuYun97/ERNIE-Image-Nunchaku/svdq-{precision}_r{rank}-ernie-image.safetensors",
torch_dtype=torch.bfloat16,
device="cuda",
)
pipe = ErnieImagePipeline.from_pretrained(
"baidu/ERNIE-Image-Turbo",
transformer=transformer,
torch_dtype=torch.bfloat16,
pe=None, pe_tokenizer=None,
)
image = pipe(
prompt="a cute orange cat sitting on a sunlit windowsill",
height=1024, width=1024,
num_inference_steps=8,
guidance_scale=1.0,
generator=torch.Generator().manual_seed(42),
).images[0]
image.save("ernie-image.png")
Tested on a single A800 GPU, 1024×1024 resolution, 8 inference steps:
| Model | Avg Latency | Speedup |
|---|---|---|
| Original BF16 | 4.89s | 1.0x |
| Nunchaku W4A4 | 2.81s | 1.74x |
batch_size=1 is supported (same as typical inference use case).为 Nunchaku 添加了对 ERNIE Image Turbo 的 W4A4 量化推理支持,在保持图像质量的前提下显著提升推理速度、降低显存占用。
本实现基于 Nunchaku,感谢其在高效扩散模型推理方面的出色工作。
# 本 fork 基于 Nunchaku 添加了对 ERNIE Image 的支持
git clone https://github.com/Hzj199/nunchaku.git
cd nunchaku
git submodule update --init --recursive
pip install build
NUNCHAKU_BUILD_WHEELS=1 python -m build --wheel --no-isolation
pip install dist/nunchaku-*.whl
import torch
from diffusers.pipelines.ernie_image.pipeline_ernie_image import ErnieImagePipeline
from nunchaku import NunchakuErnieImageTransformer2DModel
from nunchaku.utils import get_precision
precision = get_precision() # 自动检测:int4 或 fp4
rank = 64
transformer = NunchakuErnieImageTransformer2DModel.from_pretrained(
f"ZJMuYun97/ERNIE-Image-Nunchaku/svdq-{precision}_r{rank}-ernie-image.safetensors",
torch_dtype=torch.bfloat16,
device="cuda",
)
pipe = ErnieImagePipeline.from_pretrained(
"baidu/ERNIE-Image-Turbo",
transformer=transformer,
torch_dtype=torch.bfloat16,
pe=None, pe_tokenizer=None,
)
image = pipe(
prompt="一只可爱的橘色猫咪坐在阳光照射的窗台上,旁边放着一盆绿色植物",
height=1024, width=1024,
num_inference_steps=8,
guidance_scale=1.0,
generator=torch.Generator().manual_seed(42),
).images[0]
image.save("ernie-image.png")
A800 单卡测试,1024×1024 分辨率,8 步推理:
| 模型 | 平均延迟 | 加速比 |
|---|---|---|
| 原始 BF16 | 4.89s | 1.0x |
| Nunchaku W4A4 | 2.81s | 1.74x |
batch_size=1(符合常见推理场景)。