Instructions to use ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
Download generate.py from ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained/resolve/main/generate.py
- Command line
-
hf download hf://ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained/generate.py
-
curl -L -o generate.py https://huggingface.co/ApacheOne/Creaprompt_SDXL_no_vae_DWD_trained/resolve/main/generate.py
2.02 kB
| 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}") | |