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.
P-Flux-2-Klein-4B-DWD / scripts /export_checkpoint.py
johnrachwanpruna's picture
P-Flux-2-Klein-4B-DWD
24baf68
Raw History Blame Contribute Delete
1.92 kB
#!/usr/bin/env python
"""Export a training checkpoint to the inference tail file (student tail + DWD head, safetensors).
python scripts/export_checkpoint.py --ckpt checkpoints/<run>/ckpt_026000.pt --out dwd_tail.safetensors
By default the EMA weights are exported in bf16. --raw exports the raw (non-EMA) weights, --fp32 keeps fp32.
Optimizer, discriminator, RNG and config entries of the checkpoint are not exported.
"""
import argparse
import json
import os
import sys
try:
from dwd_klein.export import export_checkpoint
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.export import export_checkpoint
def main(argv=None) -> int:
import torch
ap = argparse.ArgumentParser(description="training checkpoint -> dwd_tail.safetensors")
ap.add_argument("--ckpt", required=True, help="training checkpoint (.pt), a run directory (uses its 'latest'), or a 'latest' file")
ap.add_argument("--out", default="dwd_tail.safetensors")
ap.add_argument("--raw", action="store_true", help="export the raw weights instead of the EMA weights")
ap.add_argument("--fp32", action="store_true", help="store fp32 tensors instead of bf16")
a = ap.parse_args(argv)
ckpt = a.ckpt
if os.path.isdir(ckpt):
with open(os.path.join(ckpt, "latest")) as fh:
ckpt = os.path.join(ckpt, fh.read().strip())
elif os.path.basename(ckpt) == "latest":
with open(ckpt) as fh:
ckpt = os.path.join(os.path.dirname(ckpt), fh.read().strip())
meta = export_checkpoint(ckpt, a.out, use_ema=not a.raw, dtype=torch.float32 if a.fp32 else torch.bfloat16)
print(f"wrote {a.out} ({os.path.getsize(a.out) / 1e6:.1f} MB)")
print(json.dumps(meta, indent=1))
return 0
if __name__ == "__main__":
sys.exit(main())