Run this model with HF Jobs

Run PrunaAI/P-Q-Image-2.1-DWD 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/PrunaAI/P-Q-Image-2.1-DWD. 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/PrunaAI/P-Q-Image-2.1-DWD 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: 3,961 Bytes
baa0a0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
"""Generate or edit an image with Qwen-Image-2.1-Turbo and the DWD head (no VAE decode).

    python scripts/generate.py --prompt "a red fox in fresh snow at sunrise" --width 2048 --height 2048 --out fox.png
    python scripts/generate.py --prompt "Add gently falling snow to the whole scene." --image in.jpg --out snow.png

--tail takes a tail .safetensors file, a directory holding dwd_tail.safetensors, or a Hugging Face repo id. Width and
height must be multiples of 32; for an edit they default to about --output-resolution^2 pixels at the input's aspect.
--compare also writes the stock pipeline's image for the same seed (VAE decode) next to the output.
"""

import argparse
import os
import sys
import time

try:
    from pq_image_dwd.pipeline import DEFAULT_TAIL, DWDPipeline
except ImportError:  # running from a source checkout without installing the package
    sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src"))
    from pq_image_dwd.pipeline import DEFAULT_TAIL, DWDPipeline


def main(argv=None) -> int:
    ap = argparse.ArgumentParser(description="Qwen-Image-2.1-Turbo + DWD head: text-to-image and editing without the "
                                             "VAE decode")
    ap.add_argument("--prompt", required=True, action="append",
                    help="text prompt or edit instruction; repeat for several images (seeds seed, seed + 1, ...)")
    ap.add_argument("--image", action="append", default=None,
                    help="condition image for editing; repeat for several condition images")
    ap.add_argument("--tail", default=DEFAULT_TAIL, help="tail .safetensors, a directory holding it, or a repo id")
    ap.add_argument("--base", default="Qwen/Qwen-Image-2.1-Turbo", help="base model repo id or local diffusers dir")
    ap.add_argument("--width", type=int, default=None)
    ap.add_argument("--height", type=int, default=None)
    ap.add_argument("--output-resolution", type=int, default=1024,
                    help="condition images are resized to about this^2 pixels (and the default output size)")
    ap.add_argument("--seed", type=int, default=0)
    ap.add_argument("--out", default="dwd.png", help="output PNG; with several prompts, _<i> is added to the name")
    ap.add_argument("--compare", action="store_true",
                    help="also write the stock pipeline's image (VAE decode) as <out>_vae.png")
    ap.add_argument("--device", default=None, help="default: cuda if available, else cpu")
    ap.add_argument("--compile", action="store_true", help="torch.compile the transformer blocks (slow first image)")
    a = ap.parse_args(argv)
    for name in ("width", "height"):
        v = getattr(a, name)
        if v is not None and (v <= 0 or v % 32):
            ap.error(f"--{name} must be a positive multiple of 32")

    images = None
    if a.image:
        from PIL import Image

        images = [Image.open(p) for p in a.image]
    t0 = time.perf_counter()
    pipe = DWDPipeline.from_pretrained(a.tail, base=a.base, device=a.device, compile=a.compile)
    print(f"loaded in {time.perf_counter() - t0:.1f} s", flush=True)
    t1 = time.perf_counter()
    res = pipe(a.prompt, image=images, width=a.width, height=a.height, seed=a.seed,
               output_resolution=a.output_resolution, return_vae=a.compare)
    dwd, vae = res if a.compare else (res, None)
    print(f"generated {len(dwd)} image(s) in {time.perf_counter() - t1:.2f} s", flush=True)
    root, ext = os.path.splitext(a.out)
    ext = ext or ".png"
    os.makedirs(os.path.dirname(os.path.abspath(a.out)), exist_ok=True)
    for i, img in enumerate(dwd):
        stem = root if len(dwd) == 1 else f"{root}_{i}"
        img.save(stem + ext)
        print(f"wrote {stem + ext}")
        if vae is not None:
            vae[i].save(f"{stem}_vae{ext}")
            print(f"wrote {stem}_vae{ext}")
    return 0


if __name__ == "__main__":
    sys.exit(main())