Run this model with HF Jobs
Run PrunaAI/P-Flux-2-Klein-4B-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-Flux-2-Klein-4B-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-Flux-2-Klein-4B-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.
Instructions to use PrunaAI/P-Flux-2-Klein-4B-DWD with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Pruna AI
How to use PrunaAI/P-Flux-2-Klein-4B-DWD with Pruna AI:
from pruna import PrunaModel model = PrunaModel.from_pretrained("PrunaAI/P-Flux-2-Klein-4B-DWD") - Notebooks
- Google Colab
- Kaggle
File size: 3,077 Bytes
24baf68 | 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 | #!/usr/bin/env python
"""Generate an image with FLUX.2 [klein] 4B and the DWD head (no VAE).
python scripts/generate.py --prompt "a red fox in fresh snow" --out fox.png
--tail takes an exported tail file, a directory holding dwd_tail.safetensors, or a Hugging Face repo id (default: the
released tail, PrunaAI/P-Flux-2-Klein-4B-DWD). Width and height must be multiples of 16; the tail was trained at
1024x1024, 1152x896, 896x1152, 1344x768 and 768x1344.
"""
import argparse
import os
import sys
import time
try:
from dwd_klein.pipeline import DEFAULT_REPO, DWDKleinPipeline
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 dwd_klein.pipeline import DEFAULT_REPO, DWDKleinPipeline
def main(argv=None) -> int:
ap = argparse.ArgumentParser(description="FLUX.2 [klein] 4B + DWD head text-to-image (no VAE)")
ap.add_argument("--tail", default=DEFAULT_REPO,
help=f"exported tail (.safetensors), a directory holding it, or a repo id (default {DEFAULT_REPO})")
ap.add_argument("--prompt", required=True, action="append",
help="text prompt; repeat for several images (seeds seed, seed + 1, ...)")
ap.add_argument("--width", type=int, default=1024)
ap.add_argument("--height", type=int, default=1024)
ap.add_argument("--seed", type=int, default=0)
ap.add_argument("--steps", type=int, default=4, help="sampler steps (the tail was trained for 4)")
ap.add_argument("--out", default="dwd.png", help="output PNG; with several prompts, _<i> is added to the name")
ap.add_argument("--base", default="black-forest-labs/FLUX.2-klein-4B", help="base model repo id or local dir")
ap.add_argument("--device", default=None, help="default: cuda if available, else cpu")
ap.add_argument("--compile", nargs="?", const="default", default=None, choices=["default", "reduce-overhead"],
help="torch.compile the transformer and head (first image per size is slow)")
a = ap.parse_args(argv)
if a.width % 16 or a.height % 16:
ap.error("--width and --height must be multiples of 16")
t0 = time.perf_counter()
compile_arg = False if a.compile is None else (True if a.compile == "default" else a.compile)
pipe = DWDKleinPipeline.from_pretrained(a.tail, base=a.base, device=a.device, compile=compile_arg)
print(f"loaded in {time.perf_counter() - t0:.1f} s", flush=True)
t1 = time.perf_counter()
images = pipe(a.prompt, width=a.width, height=a.height, seed=a.seed, steps=a.steps)
print(f"generated {len(images)} image(s) in {time.perf_counter() - t1:.2f} s", flush=True)
root, ext = os.path.splitext(a.out)
os.makedirs(os.path.dirname(os.path.abspath(a.out)), exist_ok=True)
for i, img in enumerate(images):
path = a.out if len(images) == 1 else f"{root}_{i}{ext or '.png'}"
img.save(path)
print(f"wrote {path}")
return 0
if __name__ == "__main__":
sys.exit(main())
|