DreamShaper-XL-Lightning — OpenVINO INT4

將 Lykon/dreamshaper-xl-lightning(SDXL 4-step Lightning 蒸餾模型) 轉換為 OpenVINO INT4 權重,並以 純 CPU 實測 1024×1024 出圖。

optimum-intel 匯出 → NNCF weight-only INT4 量化 → FP16 6.5 GB → INT4 2.06 GB(↓ ~68%)。

完整的 192 vCPU 實測數據見下方「效能實測摘要」。


目錄


快速資訊

項目 內容
基座模型 Lykon/dreamshaper-xl-lightning
Pipeline StableDiffusionXLPipeline(diffusers 格式)
Scheduler EulerDiscreteScheduler(timestep_spacing=leading)
量化格式 UNet / text_encoder / text_encoder_2 → INT4;VAE → INT8
模型大小 FP16 6.5 GB → INT4 2.06 GB(↓ ~68%)
推論裝置 CPU(OpenVINO CPU plugin,無需 GPU)
推薦參數 num_inference_steps=4、guidance_scale=2.0、1024×1024
轉換工具 optimum 2.3.0 / optimum-intel 2.2.0 / OpenVINO 2026.4.0 / NNCF 3.4.0

特色

  • **體積 ↓ 68%**:FP16 6.5 GB → INT4 2.06 GB,CPU 記憶體需求大幅下降。
  • 4 step 出圖:Turbo/Lightning 蒸餾模型,guidance_scale=2.0 即可出圖。
  • 純 CPU 可用:不依賴 GPU / CUDA,OpenVINO 自動使用全部核心。
  • diffusers 目錄結構:可直接 from_pretrained(),與原模型使用方式一致。
  • 附 15 張實測圖:5 組 prompt × (1024px + 512px 對照組),另加 10 張風格展示。
  • 附完整 benchmark:逐 step 耗時、記憶體、系統資訊記錄於 REPORT.md 與 examples/benchmark.json。

安裝

pip install diffusers==0.37.1 transformers==4.57.6 tokenizers==0.22.0 huggingface-hub==0.35.1 optimum==2.3.0 optimum-intel==2.2.0 openvino==2026.4.0 nncf==3.4.0 torch pillow psutil

僅推論時不需要 nncf;nncf 為重新量化所需。

快速開始

import torch
from optimum.intel import OVDiffusionPipeline

pipe = OVDiffusionPipeline.from_pretrained("HelloSun/dreamshaper-xl-lightning-OpenVINO-INT4", compile=True)

image = pipe(
    prompt="Astronaut in a jungle, cold color palette, muted colors, "
             "detailed, 8k, photorealistic, cinematic lighting",
    height=1024, width=1024,
    num_inference_steps=4, guidance_scale=2.0,
    generator=torch.Generator().manual_seed(43),
).images[0]

image.save("out.png")

完整可執行範例:inference_int4.py 批次生成 5 組 + benchmark:generate5.py

推論參數建議

參數 建議值 說明
num_inference_steps 4 Turbo/Lightning 蒸餾步數。請勿增加,更多步數不會更好。
guidance_scale 2.0 Turbo/Lightning 的標準 CFG 值,調高容易劣化。
height / width 1024 SDXL 原生解析度。
compile=True 開啟 編譯模型以取得較佳效能(代價為編譯時間)。

範例結果

全部為 4 steps / guidance 2.0 / CPU,seed 42–46 固定,可完全重現。

每組另附 512px 對照組(examples/*_512.png),點擊圖片可看原始尺寸。

01_hanfu — seed 42 — 17.6 s

Young Chinese woman in red Hanfu, intricate embroidery, impeccable makeup, red floral forehead pattern, elaborate high bun, golden phoenix headdress, soft-lit outdoor night background, silhouetted tiered pagoda, blurred colorful distant lights, photorealistic, ultra detailed, 8k

01_hanfu

02_astronaut — seed 43 — 14.1 s

Astronaut in a jungle, cold color palette, muted colors, detailed, 8k, photorealistic, cinematic lighting

02_astronaut

03_taipei — seed 44 — 14.8 s

Cyberpunk street in Taipei at night, heavy rain, neon signs with text 'TAIPEI' and Chinese characters '台北', reflections on wet asphalt, crowded night market, cinematic, ultra detailed

03_taipei

04_shiba — seed 45 — 15.3 s

Cute Shiba Inu wearing a tiny astronaut helmet, sitting in a field of sunflowers under a starry sky, dreamy illustration, vibrant colors, high quality

04_shiba

05_ink — seed 46 — 14.4 s

Traditional Chinese ink wash landscape, misty mountains, a small pagoda on a cliff, cranes flying, minimalist, elegant, high aesthetic quality

05_ink

風格展示

以下 10 張為 10 類風格 × 同一組 5 組基礎 prompt(seed 42–51), 使用與上方基準測試完全相同的推論設定。

注意:這批圖片沒有對應的 examples/benchmark.json 紀錄,也沒有腳本可重現, 完整 prompt 亦未收錄於 repo(早期說明檔中的版本已被截斷,無法還原)。

traditional_painting · 傳統繪畫

油畫、版畫、水彩等傳統媒材

01_traditional_painting

anime_manga · 動漫繪師

吉卜力 × 新海誠動畫風

02_anime_manga

digital_3d · 數位 3D

UE5 寫實渲染、CG 質感

03_digital_3d

photography_cinema · 攝影電影

電影感人像攝影

04_photography_cinema

cultural_regional · 文化地域

敦煌壁畫、水墨等東方美學

05_cultural_regional

material_craft · 材質工藝

絲線刺繡、陶瓷、木雕等

06_material_craft

design_commercial · 平面商業

商業插畫、扁平幾何設計

07_design_commercial

abstract_generative · 抽象生成

分形、生成藝術

08_abstract_generative

era_subculture · 復古次文化

80s 霓虹、賽博龐克

09_era_subculture

render_technique · 厚塗渲染

油畫厚塗、概念設定

10_render_technique

效能實測摘要

完整逐 step 數據見 REPORT.md 與 examples/benchmark.json。

測試環境

項目 內容
CPU Intel(R) Xeon(R) Platinum 8559C
拓撲 2 sockets × 48 cores × 2 threads/core = 192 vCPU(96 實體核心)
RAM 2.0 TiB
虛擬化 KVM(完整虛擬化)
OpenVINO CPU only,2026.4.0(build 2026.4.0-22959-99c81491cc3-releases/2026/4)
設定 num_inference_steps=4、guidance_scale=2.0、1024×1024 + 512×512 對照

總結

指標 主測組 對照組
解析度 1024×1024 512×512
平均總耗時 15.25 s / 張 4.76 s / 張
平均單步耗時 3.37 s 1.08 s
最快 / 最慢 14.14 s / 17.63 s 4.51 s / 5.02 s
對照組倍數 — 3.2×
  • 對照組為同一 prompt/seed 的 512×512 重新推理(非縮圖)。
  • 文字編碼與 VAE decode 的時間已包含在總耗時內。

逐張結果(1024×1024 / 4 steps)

# Prompt Seed 總耗時 (s) 平均單步 (s) 512px 總耗時 (s) 512px 單步 (s) 推論後 RSS (GB)
01 hanfu 42 17.63 3.90 4.76 1.07 10.68
02 astronaut 43 14.14 3.09 5.02 1.15 10.58
03 taipei 44 14.85 3.28 4.85 1.11 10.56
04 shiba 45 15.27 3.42 4.66 1.06 10.46
05 ink 46 14.36 3.17 4.51 1.02 10.47
平均 15.25 3.37 4.76 1.08 10.55

模型大小

以下為 repo 內 openvino_model.bin 的實際位元組數(Git LFS 記錄值)。

元件 位元組 大小 精度
unet 1,496,655,568 1.50 GB INT4
text_encoder_2 393,063,207 0.39 GB INT4
text_encoder 83,658,537 0.08 GB INT4
vae_decoder 49,557,592 0.05 GB INT8
vae_encoder 34,215,068 0.03 GB INT8
合計 2,057,149,972 2.06 GB

FP16 匯出模型約 6.5 GB(unet 4.8 GB + text_encoder_2 1.3 GB + text_encoder 236 MB + vae_decoder 95 MB + vae_encoder 66 MB)——此組數值取自原始轉換紀錄,非本 repo 的量測檔。

實際下載量請以本表為準:2.06 GB(另有 XML 與 tokenizer,實際略高於此值)。

檔案結構

.
├── README.md                  # 本文件
├── REPORT.md                  # 完整轉換 + 實測報告
├── model_index.json           # diffusers pipeline 索引
├── openvino_config.json       # OpenVINO 量化設定
├── inference_int4.py          # 單張推論範例
├── generate5.py               # 5 組 prompt 批次生成 + benchmark
├── quantize_int4.py           # FP16 OV → INT4 OV 量化腳本
├── unet/                      # INT4 UNet
├── vae_encoder/               # INT8 VAE encoder
├── vae_decoder/               # INT8 VAE decoder
├── text_encoder/              # INT4 CLIP text encoder
├── text_encoder_2/            # INT4 CLIP text encoder (projection)
├── tokenizer/                 # CLIP tokenizer
├── tokenizer_2/               # CLIP tokenizer 2
├── scheduler/                 # EulerDiscreteScheduler 設定
└── examples/                  # 15 張實測圖 + benchmark.json + prompts.txt
    ├── *_1024.png             # 主測組(5 張)
    ├── *_512.png              # 對照組(5 張)
    ├── *_seed*_1024.png       # 風格展示(10 張)
    ├── benchmark.json         # 逐 step 耗時 + 記憶體 + 系統資訊
    └── prompts.txt            # 5 組 prompt 與 seed

從零復現

# 1. 匯出 FP16 OpenVINO 模型
optimum-cli export openvino \
  -m Lykon/dreamshaper-xl-lightning \
  --task text-to-image \
  --library diffusers \
  --weight-format fp16 \
  ./dreamshaper-xl-lightning-ov-fp16

# 2. NNCF weight-only INT4 量化
python quantize_int4.py --fp16-dir ./dreamshaper-xl-lightning-ov-fp16 \
                          --int4-dir  ./dreamshaper-xl-lightning-ov-int4

# 3. 單張推論
python inference_int4.py

# 4. 批次生成 5 組 + 512px 對照 + benchmark
python generate5.py --outdir examples

量化設定:

from optimum.intel.openvino.configuration import (
    OVConfig, OVWeightQuantizationConfig, OVPipelineQuantizationConfig,
)

int4_config = OVWeightQuantizationConfig(
    bits=4, sym=False, group_size=128,
    group_size_fallback="adjust", ratio=1.0,
)

pipeline_config = OVPipelineQuantizationConfig(
    quantization_configs={
        "unet":           int4_config,
        "text_encoder":   int4_config,
        "text_encoder_2": int4_config,
    },
    default_config=OVWeightQuantizationConfig(bits=8, sym=True),
)

已知限制

  • 僅為 weight-only 量化:啟動時仍需即時量化權重,首次載入 + 編譯約 12 s。
  • CPU 專用:本 repo 為 OpenVINO IR 格式,若要使用 GPU 請改用原模型或自行轉換。
  • 4-step 蒸餾模型:設定 num_inference_steps > 4 不會變好,反而可能劣化。
  • INT4 為非對稱量化(sym=False),與 FP16 原圖仍有細微差異。
  • 風格展示圖無實測紀錄:10 張風格圖未納入 benchmark,完整 prompt 亦未收錄於 repo。
  • 實測僅涵蓋 192 vCPU 伺服器:一般桌上型 CPU 的絕對數字會較慢,比例關係大致相同。

授權與出處

  • 來源模型:Lykon/dreamshaper-xl-lightning

  • 授權:openrail++(沿用來源模型授權)

  • 轉換:僅做格式轉換與權重量化,模型權重來自來源模型

使用本模型時請一併遵守來源模型的授權條款與 OpenRAIL++ 使用政策。


Made with OpenVINO + optimum-intel + NNCF

Downloads last month
161
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for HelloSun/dreamshaper-xl-lightning-OpenVINO-INT4

Finetuned
(4)
this model