Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sdxl lightning quant use #992

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions onediff_diffusers_extensions/examples/lightning/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Run:


```
python3 onediff_diffusers_extensions/tools/quantization/quantize-sd-fast.py \
--quantized_model ./sdxl_lightning_quant \
--conv_ssim_threshold 0.1 \
--linear_ssim_threshold 0.1 \
--conv_compute_density_threshold 900 \
--linear_compute_density_threshold 300 \
--save_as_float true \
--use_lightning 1
lixiang007666 marked this conversation as resolved.
Show resolved Hide resolved
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
StableDiffusionXLImg2ImgPipeline,
StableDiffusionPipeline,
StableDiffusionImg2ImgPipeline,
UNet2DConditionModel
)
from safetensors.torch import load_file
from huggingface_hub import hf_hub_download

from onediff.quantization import QuantPipeline

Expand Down Expand Up @@ -62,6 +65,9 @@
)
parser.add_argument("--seed", type=int, default=111)
parser.add_argument("--cache_dir", type=str, default=None)
parser.add_argument("--use_lightning", type=(lambda x: str(x).lower() in ["true", "1", "yes"]), default=False, help="Use the SDXL Lightning model if true")
parser.add_argument("--lightning_ckpt", type=str, default="sdxl_lightning_4step_unet.safetensors",
help="Checkpoint file name for the ByteDance SDXL-Lightning model")
args = parser.parse_args()

pipeline_cls = AutoPipelineForText2Image if args.input_image is None else AutoPipelineForImage2Image
Expand All @@ -87,6 +93,19 @@
use_safetensors=True,
)

if args.use_lightning:
repo = "ByteDance/SDXL-Lightning"
ckpt = args.lightning_ckpt
unet = UNet2DConditionModel.from_config(args.model, subfolder="unet").to("cuda", torch.float16)
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
pipe = QuantPipeline.from_pretrained(
pipeline_cls,
args.model,
unet=unet,
torch_dtype=torch.float16,
variant=args.variant,
use_safetensors=True,
)
else:
pipe = QuantPipeline.from_pretrained(
pipeline_cls,
Expand Down