[GITHUB] 

  • Maintain realistic details sdxl model adapt.

NOTE_rev1. : It works well with diffusers but doesn't perform as well with ComfyUI, so don't expect too much from it.

ex

import torch
from diffusers import StableDiffusionXLPipeline, EulerDiscreteScheduler

CONFIG = {
    "model_id":        "SG161222/RealVisXL_V5.0",
    "adapter_path":    "s_adapter_step10000.pt",
    "adapter_scale":   1.0,

    "prompt":          "a portrait of a young woman in a nightclub. She is standing in front of a bar counter with colorful lights in the background. The woman is wearing a black halter top with a deep V-neckline and her hair is styled in loose waves. She has a serious expression on her face and is looking directly at the camera. The lighting is dim and the overall mood of the image is dark and mysterious",
    "negative_prompt": "bad hands, bad anatomy, ugly, deformed, face asymmetry, eyes asymmetry, deformed eyes, deformed mouth, open mouth",

    "width":           1024,
    "height":          1024,
    "steps":           30,
    "cfg":             5.0,
    "seed":            42,

    "output":          "output.png",
}
def load_adapter(unet, adapter_path, device="cuda", scale=1.0):
    delta = torch.load(adapter_path, map_location="cpu")
    with torch.no_grad():
        for name, param in unet.named_parameters():
            if name in delta:
                param.data += delta[name].to(device, param.dtype) * scale

def infer(cfg):
    pipe = StableDiffusionXLPipeline.from_pretrained(
        cfg["model_id"],
        torch_dtype=torch.float16,
    ).to("cuda")
    pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)

    load_adapter(pipe.unet, cfg["adapter_path"], device="cuda", scale=cfg["adapter_scale"])

    generator = torch.Generator("cuda").manual_seed(cfg["seed"])

    image = pipe(
        cfg["prompt"],
        negative_prompt=cfg["negative_prompt"],
        num_inference_steps=cfg["steps"],
        guidance_scale=cfg["cfg"],
        width=cfg["width"],
        height=cfg["height"],
        generator=generator,
    ).images[0]

    image.save(cfg["output"])
    print(f"Saved → {cfg['output']}")

if __name__ == "__main__":
    infer(CONFIG)
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for kpsss34/SDXL_sapt

Finetuned
(4)
this model