From bbe9aa7f3e16ba320b3eaff2e0b8c7ddeaa58b41 Mon Sep 17 00:00:00 2001 From: Jayce-Ping <315229706@qq.com> Date: Fri, 23 Jan 2026 11:38:18 +0800 Subject: [PATCH 1/2] First commit --- inference/example_full.py | 30 ++++++++++++++++++++++++++++++ inference/example_lora.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 inference/example_full.py create mode 100644 inference/example_lora.py diff --git a/inference/example_full.py b/inference/example_full.py new file mode 100644 index 00000000..adf19d78 --- /dev/null +++ b/inference/example_full.py @@ -0,0 +1,30 @@ +# Modified from https://huggingface.co/black-forest-labs/FLUX.1-dev usage example +import torch +from diffusers import FluxPipeline, FluxTransformer2DModel + +# 1. Load pipeline +pipe = FluxPipeline.from_pretrained( + "black-forest-labs/FLUX.1-dev", + torch_dtype=torch.bfloat16 +) +pipe.enable_model_cpu_offload() + +# 2. Load full fine-tuned transformer weights +checkpoint = 'path/to/full/checkpoint' # replace with your checkpoint directory +pipe.transformer = FluxTransformer2DModel.from_pretrained( + checkpoint, + torch_dtype=torch.bfloat16 +) + +# 3. Generate image +prompt = "A cat holding a sign that says hello world" +image = pipe( + prompt, + height=1024, + width=1024, + guidance_scale=3.5, + num_inference_steps=50, + max_sequence_length=512, + generator=torch.Generator("cpu").manual_seed(0) +).images[0] +image.save("flux-dev-full.png") \ No newline at end of file diff --git a/inference/example_lora.py b/inference/example_lora.py new file mode 100644 index 00000000..36cc054c --- /dev/null +++ b/inference/example_lora.py @@ -0,0 +1,33 @@ +# Modified from https://huggingface.co/black-forest-labs/FLUX.1-dev usage example +import torch +from diffusers import FluxPipeline +from peft import PeftModel + + +# 1. Load pipeline +pipe = FluxPipeline.from_pretrained( + "black-forest-labs/FLUX.1-dev", + torch_dtype=torch.bfloat16 +) +pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power + +# 2. Load LoRA weights +checkpoint = 'path/to/lora/checkpoint' # replace with your checkpoint directory +pipe.transformer = PeftModel.from_pretrained( + pipe.transformer, + checkpoint, + torch_dtype=torch.bfloat16 +) + +# 3. Generate image +prompt = "A cat holding a sign that says hello world" +image = pipe( + prompt, + height=1024, + width=1024, + guidance_scale=3.5, + num_inference_steps=50, + max_sequence_length=512, + generator=torch.Generator("cpu").manual_seed(0) +).images[0] +image.save("flux-dev.png") From a48fb0ec19e32719f3c857180be7a3d46a44e16f Mon Sep 17 00:00:00 2001 From: Jayce-Ping <315229706@qq.com> Date: Fri, 23 Jan 2026 12:37:27 +0800 Subject: [PATCH 2/2] update --- inference/example_full.py | 7 ++++--- inference/example_lora.py | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/inference/example_full.py b/inference/example_full.py index adf19d78..e7c0ce1b 100644 --- a/inference/example_full.py +++ b/inference/example_full.py @@ -7,15 +7,16 @@ "black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16 ) -pipe.enable_model_cpu_offload() # 2. Load full fine-tuned transformer weights -checkpoint = 'path/to/full/checkpoint' # replace with your checkpoint directory +checkpoint = 'path/to/checkpoint' # replace with your checkpoint directory pipe.transformer = FluxTransformer2DModel.from_pretrained( checkpoint, torch_dtype=torch.bfloat16 ) +pipe.enable_model_cpu_offload() + # 3. Generate image prompt = "A cat holding a sign that says hello world" image = pipe( @@ -23,7 +24,7 @@ height=1024, width=1024, guidance_scale=3.5, - num_inference_steps=50, + num_inference_steps=28, max_sequence_length=512, generator=torch.Generator("cpu").manual_seed(0) ).images[0] diff --git a/inference/example_lora.py b/inference/example_lora.py index 36cc054c..7746368f 100644 --- a/inference/example_lora.py +++ b/inference/example_lora.py @@ -3,22 +3,22 @@ from diffusers import FluxPipeline from peft import PeftModel - # 1. Load pipeline pipe = FluxPipeline.from_pretrained( "black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16 ) -pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power # 2. Load LoRA weights -checkpoint = 'path/to/lora/checkpoint' # replace with your checkpoint directory +checkpoint = 'path/to/checkpoint' # replace with your checkpoint directory pipe.transformer = PeftModel.from_pretrained( pipe.transformer, checkpoint, torch_dtype=torch.bfloat16 ) +pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power + # 3. Generate image prompt = "A cat holding a sign that says hello world" image = pipe( @@ -26,7 +26,7 @@ height=1024, width=1024, guidance_scale=3.5, - num_inference_steps=50, + num_inference_steps=28, max_sequence_length=512, generator=torch.Generator("cpu").manual_seed(0) ).images[0]