Views
No views yet
Prompt: A cat is sitting on a stone.
| dark | normal | light |
|---|---|---|
![]() | ![]() | ![]() |
Prompt: A graceful ballerina posing on a stage.
| dark | normal | light |
|---|---|---|
![]() | ![]() | ![]() |
Prompt: A quiet courtyard with a small fountain in the center.
| dark | normal | light |
|---|---|---|
![]() | ![]() | ![]() |
git clone https://github.com/modelscope/DiffSynth-Studio.git
cd DiffSynth-Studio
pip install -e .1from diffsynth.diffusion.template import TemplatePipeline
2from diffsynth.pipelines.flux2_image import Flux2ImagePipeline, ModelConfig
3import torch
4
5pipe = Flux2ImagePipeline.from_pretrained(
6 torch_dtype=torch.bfloat16,
7 device="cuda",
8 model_configs=[
9 ModelConfig(model_id="black-forest-labs/FLUX.2-klein-base-4B", origin_file_pattern="transformer/*.safetensors"),
10 ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="text_encoder/*.safetensors"),
11 ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
12 ],
13 tokenizer_config=ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="tokenizer/"),
14)
15template = TemplatePipeline.from_pretrained(
16 torch_dtype=torch.bfloat16,
17 device="cuda",
18 model_configs=[ModelConfig(model_id="DiffSynth-Studio/Template-KleinBase4B-Brightness")],
19)
20image = template(
21 pipe,
22 prompt="A cat is sitting on a stone.",
23 seed=0, cfg_scale=4, num_inference_steps=50,
24 template_inputs = [{"scale": 0.7}],
25 negative_template_inputs = [{"scale": 0.5}]
26)
27image.save("image_Brightness_light.jpg")
28image = template(
29 pipe,
30 prompt="A cat is sitting on a stone.",
31 seed=0, cfg_scale=4, num_inference_steps=50,
32 template_inputs = [{"scale": 0.5}],
33 negative_template_inputs = [{"scale": 0.5}]
34)
35image.save("image_Brightness_normal.jpg")
36image = template(
37 pipe,
38 prompt="A cat is sitting on a stone.",
39 seed=0, cfg_scale=4, num_inference_steps=50,
40 template_inputs = [{"scale": 0.3}],
41 negative_template_inputs = [{"scale": 0.5}]
42)
43image.save("image_Brightness_dark.jpg")1from diffsynth.diffusion.template import TemplatePipeline
2from diffsynth.pipelines.flux2_image import Flux2ImagePipeline, ModelConfig
3import torch
4
5```python
6vram_config = {
7 "offload_dtype": "disk",
8 "offload_device": "disk",
9 "onload_dtype": torch.float8_e4m3fn,
10 "onload_device": "cpu",
11 "preparing_dtype": torch.float8_e4m3fn,
12 "preparing_device": "cuda",
13 "computation_dtype": torch.bfloat16,
14 "computation_device": "cuda",
15}
16pipe = Flux2ImagePipeline.from_pretrained(
17 torch_dtype=torch.bfloat16,
18 device="cuda",
19 model_configs=[
20 ModelConfig(model_id="black-forest-labs/FLUX.2-klein-base-4B", origin_file_pattern="transformer/*.safetensors", **vram_config),
21 ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="text_encoder/*.safetensors", **vram_config),
22 ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
23 ],
24 tokenizer_config=ModelConfig(model_id="black-forest-labs/FLUX.2-klein-4B", origin_file_pattern="tokenizer/"),
25 vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
26)
27template = TemplatePipeline.from_pretrained(
28 torch_dtype=torch.bfloat16,
29 device="cuda",
30 model_configs=[ModelConfig(model_id="DiffSynth-Studio/Template-KleinBase4B-Brightness")],
31 lazy_loading=True,
32)
33image = template(
34 pipe,
35 prompt="A cat is sitting on a stone.",
36 seed=0, cfg_scale=4, num_inference_steps=50,
37 template_inputs = [{"scale": 0.7}],
38 negative_template_inputs = [{"scale": 0.5}]
39)
40image.save("image_Brightness_light.jpg")
41image = template(
42 pipe,
43 prompt="A cat is sitting on a stone.",
44 seed=0, cfg_scale=4, num_inference_steps=50,
45 template_inputs = [{"scale": 0.5}],
46 negative_template_inputs = [{"scale": 0.5}]
47)
48image.save("image_Brightness_normal.jpg")
49image = template(
50 pipe,
51 prompt="A cat is sitting on a stone.",
52 seed=0, cfg_scale=4, num_inference_steps=50,
53 template_inputs = [{"scale": 0.3}],
54 negative_template_inputs = [{"scale": 0.5}]
55)
56image.save("image_Brightness_dark.jpg")1modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "flux2/Template-KleinBase4B-Brightness/*" --local_dir ./data/diffsynth_example_dataset
2
3accelerate launch examples/flux2/model_training/train.py \
4 --dataset_base_path data/diffsynth_example_dataset/flux2/Template-KleinBase4B-Brightness \
5 --dataset_metadata_path data/diffsynth_example_dataset/flux2/Template-KleinBase4B-Brightness/metadata.jsonl \
6 --extra_inputs "template_inputs" \
7 --max_pixels 1048576 \
8 --dataset_repeat 50 \
9 --model_id_with_origin_paths "black-forest-labs/FLUX.2-klein-4B:text_encoder/*.safetensors,black-forest-labs/FLUX.2-klein-base-4B:transformer/*.safetensors,black-forest-labs/FLUX.2-klein-4B:vae/diffusion_pytorch_model.safetensors" \
10 --template_model_id_or_path "DiffSynth-Studio/Template-KleinBase4B-Brightness:" \
11 --tokenizer_path "black-forest-labs/FLUX.2-klein-4B:tokenizer/" \
12 --learning_rate 1e-4 \
13 --num_epochs 2 \
14 --remove_prefix_in_ckpt "pipe.template_model." \
15 --output_path "./models/train/Template-KleinBase4B-Brightness_full" \
16 --trainable_models "template_model" \
17 --use_gradient_checkpointing \
18 --find_unused_parameters