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
Download scripts/export_checkpoint.py from PrunaAI/P-Flux-2-Klein-4B-DWD: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/PrunaAI/P-Flux-2-Klein-4B-DWD/resolve/main/scripts/export_checkpoint.py
- Command line
-
hf download hf://PrunaAI/P-Flux-2-Klein-4B-DWD/scripts/export_checkpoint.py
-
curl -L -o export_checkpoint.py https://huggingface.co/PrunaAI/P-Flux-2-Klein-4B-DWD/resolve/main/scripts/export_checkpoint.py
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()) | |