Download examples/flux2/model_training/validate_lora/FLUX.2-dev.py from ymyy307/diffsynth: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/ymyy307/diffsynth/resolve/main/examples/flux2/model_training/validate_lora/FLUX.2-dev.py
- Command line
-
hf download hf://ymyy307/diffsynth/examples/flux2/model_training/validate_lora/FLUX.2-dev.py
-
curl -L -o FLUX.2-dev.py https://huggingface.co/ymyy307/diffsynth/resolve/main/examples/flux2/model_training/validate_lora/FLUX.2-dev.py
1.18 kB
| from diffsynth.pipelines.flux2_image import Flux2ImagePipeline, ModelConfig | |
| import torch | |
| vram_config = { | |
| "offload_dtype": torch.bfloat16, | |
| "offload_device": "cpu", | |
| "onload_dtype": torch.bfloat16, | |
| "onload_device": "cuda", | |
| "preparing_dtype": torch.bfloat16, | |
| "preparing_device": "cuda", | |
| "computation_dtype": torch.bfloat16, | |
| "computation_device": "cuda", | |
| } | |
| pipe = Flux2ImagePipeline.from_pretrained( | |
| torch_dtype=torch.bfloat16, | |
| device="cuda", | |
| model_configs=[ | |
| ModelConfig(model_id="black-forest-labs/FLUX.2-dev", origin_file_pattern="text_encoder/*.safetensors", **vram_config), | |
| ModelConfig(model_id="black-forest-labs/FLUX.2-dev", origin_file_pattern="transformer/*.safetensors", **vram_config), | |
| ModelConfig(model_id="black-forest-labs/FLUX.2-dev", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config), | |
| ], | |
| tokenizer_config=ModelConfig(model_id="black-forest-labs/FLUX.2-dev", origin_file_pattern="tokenizer/"), | |
| ) | |
| pipe.load_lora(pipe.dit, "./models/train/FLUX.2-dev-LoRA-splited/epoch-4.safetensors") | |
| prompt = "a dog" | |
| image = pipe(prompt, seed=0) | |
| image.save("image_FLUX.2-dev_lora.jpg") | |