Run this model with HF Jobs

Run ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
File size: 2,022 Bytes
5004633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import argparse
from pathlib import Path

import torch
from diffusers import UNet2DConditionModel
from PIL import Image
from transformers import CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer
import creaprompt_sdxl_dwd as dwd

parser = argparse.ArgumentParser()
parser.add_argument("--prompt", required=True)
parser.add_argument("--seed", type=int, default=42)
parser.add_argument("--width", type=int, default=1024)
parser.add_argument("--height", type=int, default=1024)
parser.add_argument("--output", default="image.png")
args = parser.parse_args()
dwd.check_size(args.width, args.height)

root = Path(__file__).resolve().parent
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
dtype = (torch.bfloat16 if device.type == "cuda" and torch.cuda.is_bf16_supported()
         else torch.float32)
unet = UNet2DConditionModel.from_pretrained(
    root / "unet", torch_dtype=dtype, use_safetensors=True, local_files_only=True,
).to(device)
model = dwd.SDXLDWD(unet).eval()
state = torch.load(root / "dwd_inference.pt", map_location="cpu", weights_only=True)
model.tuned.load_state_dict(state["ema"], strict=True)
tokenizers = tuple(
    CLIPTokenizer.from_pretrained(root / name, local_files_only=True)
    for name in ("tokenizer", "tokenizer_2")
)
encoders = tuple(
    cls.from_pretrained(root / name, torch_dtype=dtype,
                        use_safetensors=True, local_files_only=True).to(device).eval()
    for cls, name in (
        (CLIPTextModel, "text_encoder"),
        (CLIPTextModelWithProjection, "text_encoder_2"),
    )
)
ids = torch.tensor([[args.height, args.width, 0, 0, args.height, args.width]])
cond = dwd.text_embeddings(tokenizers, encoders, [args.prompt], ids)
schedule = dwd.NormalSDESchedule(state["sampling_steps"], device)
rgb = dwd.render(model, schedule, cond, args.width, args.height, args.seed)
pixels = rgb[0].permute(1, 2, 0).clamp(-1, 1).add(1).mul(127.5).round().byte().cpu().numpy()
Image.fromarray(pixels).save(args.output)
print(f"Saved {args.output}")