ymyy307 commited on
Commit
3c11df8
·
verified ·
1 Parent(s): 171f557

Upload folder using huggingface_hub (part 4)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. examples/ideogram4/model_training/lora/Ideogram-4-fp8.sh +18 -0
  2. examples/ideogram4/model_training/lora/Ideogram-4-nf4.sh +18 -0
  3. examples/ideogram4/model_training/special/split_training/Ideogram-4-bf16-repackage.sh +40 -0
  4. examples/ideogram4/model_training/special/split_training/validate.py +21 -0
  5. examples/ideogram4/model_training/train.py +132 -0
  6. examples/ideogram4/model_training/validate_lora/Ideogram-4-bf16-repackage.py +21 -0
  7. examples/ideogram4/model_training/validate_lora/Ideogram-4-fp8.py +32 -0
  8. examples/ideogram4/model_training/validate_lora/Ideogram-4-nf4.py +32 -0
  9. examples/image_quality_metric/aesthetic.py +16 -0
  10. examples/image_quality_metric/bioclip.py +17 -0
  11. examples/image_quality_metric/clipscore.py +17 -0
  12. examples/image_quality_metric/fid.py +17 -0
  13. examples/image_quality_metric/hpsv2.py +17 -0
  14. examples/image_quality_metric/hpsv3.py +17 -0
  15. examples/image_quality_metric/image_reward.py +17 -0
  16. examples/image_quality_metric/lpips.py +33 -0
  17. examples/image_quality_metric/pickscore.py +17 -0
  18. examples/image_quality_metric/qwen_image_bench.py +21 -0
  19. examples/image_quality_metric/unified_reward_2.py +19 -0
  20. examples/image_quality_metric/unified_reward_edit.py +25 -0
  21. examples/joyai_image/model_inference/JoyAI-Image-Edit.py +39 -0
  22. examples/joyai_image/model_inference_low_vram/JoyAI-Image-Edit.py +51 -0
  23. examples/joyai_image/model_training/full/JoyAI-Image-Edit.sh +35 -0
  24. examples/joyai_image/model_training/full/accelerate_config_zero3.yaml +23 -0
  25. examples/joyai_image/model_training/lora/JoyAI-Image-Edit.sh +39 -0
  26. examples/joyai_image/model_training/special/split_training/JoyAI-Image-Edit.sh +42 -0
  27. examples/joyai_image/model_training/special/split_training/validate.py +30 -0
  28. examples/joyai_image/model_training/train.py +150 -0
  29. examples/joyai_image/model_training/validate_full/JoyAI-Image-Edit.py +32 -0
  30. examples/joyai_image/model_training/validate_lora/JoyAI-Image-Edit.py +30 -0
  31. examples/krea2/model_inference/Krea-2-Raw.py +17 -0
  32. examples/krea2/model_inference/Krea-2-Turbo.py +22 -0
  33. examples/krea2/model_inference_low_vram/Krea-2-Raw.py +27 -0
  34. examples/krea2/model_inference_low_vram/Krea-2-Turbo.py +32 -0
  35. examples/krea2/model_training/full/Krea-2-Raw.sh +17 -0
  36. examples/krea2/model_training/full/Krea-2-Turbo.sh +17 -0
  37. examples/krea2/model_training/lora/Krea-2-Raw.sh +19 -0
  38. examples/krea2/model_training/lora/Krea-2-Turbo.sh +21 -0
  39. examples/krea2/model_training/special/split_training/Krea-2-Raw.sh +42 -0
  40. examples/krea2/model_training/special/split_training/validate.py +19 -0
  41. examples/krea2/model_training/train.py +151 -0
  42. examples/krea2/model_training/validate_full/Krea-2-Raw.py +19 -0
  43. examples/krea2/model_training/validate_full/Krea-2-Turbo.py +19 -0
  44. examples/krea2/model_training/validate_lora/Krea-2-Raw.py +19 -0
  45. examples/krea2/model_training/validate_lora/Krea-2-Turbo.py +18 -0
  46. examples/lingbot_video/README.md +3 -0
  47. examples/lingbot_video/model_inference/lingbot-video-dense-1.3b_t2i.py +32 -0
  48. examples/lingbot_video/model_inference/lingbot-video-dense-1.3b_t2v.py +68 -0
  49. examples/lingbot_video/model_inference/lingbot-video-dense-1.3b_ti2v.py +39 -0
  50. examples/lingbot_video/model_inference/lingbot-video-moe-30b-a3b_t2i.py +32 -0
examples/ideogram4/model_training/lora/Ideogram-4-fp8.sh ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "ideogram4/Ideogram-4-fp8/*" --local_dir ./data/diffsynth_example_dataset
2
+
3
+ accelerate launch examples/ideogram4/model_training/train.py \
4
+ --learning_rate 1e-4 \
5
+ --num_epochs 5 \
6
+ --lora_rank 32 \
7
+ --use_gradient_checkpointing \
8
+ --find_unused_parameters \
9
+ --dataset_base_path "./data/diffsynth_example_dataset/ideogram4/Ideogram-4-fp8" \
10
+ --dataset_metadata_path "./data/diffsynth_example_dataset/ideogram4/Ideogram-4-fp8/metadata.json" \
11
+ --model_id_with_origin_paths "ideogram-ai/ideogram-4-fp8:transformer/diffusion_pytorch_model.safetensors,ideogram-ai/ideogram-4-fp8:text_encoder/model.safetensors,ideogram-ai/ideogram-4-fp8:vae/diffusion_pytorch_model.safetensors" \
12
+ --lora_base_model "dit" \
13
+ --remove_prefix_in_ckpt "pipe.dit." \
14
+ --max_pixels 1048576 \
15
+ --dataset_repeat 100 \
16
+ --output_path "./models/train/Ideogram-4-fp8_lora" \
17
+ --lora_target_modules "attention.qkv,attention.o,feed_forward.w1,feed_forward.w2,feed_forward.w3,adaln_modulation" \
18
+ --data_file_keys "image"
examples/ideogram4/model_training/lora/Ideogram-4-nf4.sh ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "ideogram4/Ideogram-4-nf4/*" --local_dir ./data/diffsynth_example_dataset
2
+
3
+ accelerate launch examples/ideogram4/model_training/train.py \
4
+ --learning_rate 1e-4 \
5
+ --num_epochs 5 \
6
+ --lora_rank 32 \
7
+ --use_gradient_checkpointing \
8
+ --find_unused_parameters \
9
+ --dataset_base_path "./data/diffsynth_example_dataset/ideogram4/Ideogram-4-nf4" \
10
+ --dataset_metadata_path "./data/diffsynth_example_dataset/ideogram4/Ideogram-4-nf4/metadata.json" \
11
+ --model_id_with_origin_paths "ideogram-ai/ideogram-4-nf4:transformer/diffusion_pytorch_model.safetensors,ideogram-ai/ideogram-4-nf4:text_encoder/model.safetensors,ideogram-ai/ideogram-4-nf4:vae/diffusion_pytorch_model.safetensors" \
12
+ --lora_base_model "dit" \
13
+ --remove_prefix_in_ckpt "pipe.dit." \
14
+ --max_pixels 1048576 \
15
+ --dataset_repeat 100 \
16
+ --output_path "./models/train/Ideogram-4-nf4_lora" \
17
+ --lora_target_modules "attention.qkv,attention.o,feed_forward.w1,feed_forward.w2,feed_forward.w3,adaln_modulation" \
18
+ --data_file_keys "image"
examples/ideogram4/model_training/special/split_training/Ideogram-4-bf16-repackage.sh ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "ideogram4/Ideogram-4-bf16-repackage/*" --local_dir ./data/diffsynth_example_dataset
2
+
3
+ # Stage 1: cache deterministic preprocessing outputs.
4
+ accelerate launch examples/ideogram4/model_training/train.py \
5
+ --learning_rate 1e-4 \
6
+ --num_epochs 5 \
7
+ --lora_rank 32 \
8
+ --use_gradient_checkpointing \
9
+ --find_unused_parameters \
10
+ --dataset_base_path ./data/diffsynth_example_dataset/ideogram4/Ideogram-4-bf16-repackage \
11
+ --dataset_metadata_path ./data/diffsynth_example_dataset/ideogram4/Ideogram-4-bf16-repackage/metadata.json \
12
+ --model_id_with_origin_paths DiffSynth-Studio/ideogram-4-bf16-repackage:transformer/diffusion_pytorch_model.safetensors,DiffSynth-Studio/ideogram-4-bf16-repackage:text_encoder/model.safetensors,DiffSynth-Studio/ideogram-4-bf16-repackage:vae/diffusion_pytorch_model.safetensors \
13
+ --lora_base_model dit \
14
+ --remove_prefix_in_ckpt pipe.dit. \
15
+ --max_pixels 1048576 \
16
+ --dataset_repeat 1 \
17
+ --output_path ./models/train/Ideogram-4-bf16-repackage_split_cache \
18
+ --lora_target_modules attention.qkv,attention.o,feed_forward.w1,feed_forward.w2,feed_forward.w3,adaln_modulation \
19
+ --data_file_keys image \
20
+ --offload_models DiffSynth-Studio/ideogram-4-bf16-repackage:transformer/diffusion_pytorch_model.safetensors \
21
+ --task sft:data_process
22
+
23
+ # Stage 2: train LoRA from the cached dataset.
24
+ accelerate launch examples/ideogram4/model_training/train.py \
25
+ --learning_rate 1e-4 \
26
+ --num_epochs 5 \
27
+ --lora_rank 32 \
28
+ --use_gradient_checkpointing \
29
+ --find_unused_parameters \
30
+ --dataset_base_path ./models/train/Ideogram-4-bf16-repackage_split_cache \
31
+ --model_id_with_origin_paths DiffSynth-Studio/ideogram-4-bf16-repackage:transformer/diffusion_pytorch_model.safetensors,DiffSynth-Studio/ideogram-4-bf16-repackage:text_encoder/model.safetensors,DiffSynth-Studio/ideogram-4-bf16-repackage:vae/diffusion_pytorch_model.safetensors \
32
+ --lora_base_model dit \
33
+ --remove_prefix_in_ckpt pipe.dit. \
34
+ --max_pixels 1048576 \
35
+ --dataset_repeat 100 \
36
+ --output_path ./models/train/Ideogram-4-bf16-repackage_split \
37
+ --lora_target_modules attention.qkv,attention.o,feed_forward.w1,feed_forward.w2,feed_forward.w3,adaln_modulation \
38
+ --data_file_keys image \
39
+ --offload_models DiffSynth-Studio/ideogram-4-bf16-repackage:text_encoder/model.safetensors,DiffSynth-Studio/ideogram-4-bf16-repackage:vae/diffusion_pytorch_model.safetensors \
40
+ --task sft:train
examples/ideogram4/model_training/special/split_training/validate.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.ideogram4 import Ideogram4Pipeline
2
+ from diffsynth.core import ModelConfig
3
+ import torch
4
+
5
+ pipe = Ideogram4Pipeline.from_pretrained(
6
+ torch_dtype=torch.bfloat16,
7
+ device="cuda",
8
+ model_configs=[
9
+ ModelConfig(model_id="DiffSynth-Studio/ideogram-4-bf16-repackage", origin_file_pattern="transformer/diffusion_pytorch_model.safetensors"),
10
+ ModelConfig(model_id="DiffSynth-Studio/ideogram-4-bf16-repackage", origin_file_pattern="unconditional_transformer/diffusion_pytorch_model.safetensors"),
11
+ ModelConfig(model_id="DiffSynth-Studio/ideogram-4-bf16-repackage", origin_file_pattern="text_encoder/model.safetensors"),
12
+ ModelConfig(model_id="DiffSynth-Studio/ideogram-4-bf16-repackage", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
13
+ ],
14
+ tokenizer_config=ModelConfig(model_id="ideogram-ai/ideogram-4-fp8", origin_file_pattern="tokenizer/"),
15
+ )
16
+ pipe.load_lora(pipe.dit, './models/train/Ideogram-4-bf16-repackage_split/epoch-4.safetensors', alpha=1)
17
+ # pipe.load_lora(pipe.dit_uncond, './models/train/Ideogram-4-bf16-repackage_split/epoch-4.safetensors', alpha=1)
18
+
19
+ prompt = "{\"high_level_description\":\"A close-up photograph of a happy Pembroke Welsh Corgi sitting on a concrete wall, panting with its tongue out, set against a backdrop of blurred pink cherry blossoms and blue sky.\",\"style_description\":{\"aesthetics\":\"joyful, vibrant, spring-like, cute, energetic\",\"lighting\":\"bright natural daylight, soft diffuse sunlight, shallow depth of field\",\"photo\":\"85mm lens, f/2.0, bokeh background, sharp focus on dog face\",\"medium\":\"photograph\",\"color_palette\":[\"#E2725B\",\"#FFFFFF\",\"#FFB7C5\",\"#87CEEB\",\"#A9A9A9\"]},\"compositional_deconstruction\":{\"background\":\"Softly blurred background of pink cherry blossom branches against a pale blue sky. The bokeh effect creates a dreamy spring atmosphere. The background is out of focus to highlight the sharp details of the dog in the foreground.\",\"elements\":[{\"type\":\"obj\",\"bbox\":[150,200,900,850],\"desc\":\"A Pembroke Welsh Corgi with fluffy orange and white fur. Its mouth is open, panting with a pink tongue hanging out, expression is happy and excited. Ears are perked up. Sharp focus on the face and eyes.\"},{\"type\":\"obj\",\"bbox\":[850,0,1000,1000],\"desc\":\"A grey concrete wall or ledge at the bottom of the frame. The dog's front paws are resting near the edge. Rough texture.\"}]}}"
20
+ image = pipe(prompt=prompt, height=1024, width=1024, num_inference_steps=48, cfg_scale=7.0, seed=0)
21
+ image.save('split_training_Ideogram-4.jpg')
examples/ideogram4/model_training/train.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch, os, argparse, accelerate
2
+ from diffsynth.core import UnifiedDataset
3
+ from diffsynth.pipelines.ideogram4 import Ideogram4Pipeline, ModelConfig
4
+ from diffsynth.diffusion import *
5
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
6
+
7
+
8
+ class Ideogram4TrainingModule(DiffusionTrainingModule):
9
+ def __init__(
10
+ self,
11
+ model_paths=None, model_id_with_origin_paths=None,
12
+ tokenizer_path=None,
13
+ trainable_models=None,
14
+ lora_base_model=None, lora_target_modules="", lora_rank=32, lora_checkpoint=None,
15
+ preset_lora_path=None, preset_lora_model=None,
16
+ use_gradient_checkpointing=True,
17
+ use_gradient_checkpointing_offload=False,
18
+ extra_inputs=None,
19
+ fp8_models=None,
20
+ offload_models=None,
21
+ quant_options=None,
22
+ device="cpu",
23
+ task="sft",
24
+ ):
25
+ super().__init__()
26
+ model_configs = self.parse_model_configs(model_paths, model_id_with_origin_paths, fp8_models=fp8_models, offload_models=offload_models, quant_options=quant_options, device=device)
27
+ tokenizer_config = self.parse_path_or_model_id(tokenizer_path, default_value=ModelConfig(model_id="ideogram-ai/ideogram-4-fp8", origin_file_pattern="tokenizer/"))
28
+ self.pipe = Ideogram4Pipeline.from_pretrained(torch_dtype=torch.bfloat16, device=device, model_configs=model_configs, tokenizer_config=tokenizer_config)
29
+ self.pipe = self.split_pipeline_units(task, self.pipe, trainable_models, lora_base_model)
30
+
31
+ self.switch_pipe_to_training_mode(
32
+ self.pipe, trainable_models,
33
+ lora_base_model, lora_target_modules, lora_rank, lora_checkpoint,
34
+ preset_lora_path, preset_lora_model,
35
+ task=task,
36
+ )
37
+
38
+ self.use_gradient_checkpointing = use_gradient_checkpointing
39
+ self.use_gradient_checkpointing_offload = use_gradient_checkpointing_offload
40
+ self.extra_inputs = extra_inputs.split(",") if extra_inputs is not None else []
41
+ self.fp8_models = fp8_models
42
+ self.task = task
43
+ self.task_to_loss = {
44
+ "sft:data_process": lambda pipe, *args: args,
45
+ "sft": lambda pipe, inputs_shared, inputs_posi, inputs_nega: FlowMatchSFTLoss(pipe, **inputs_shared, **inputs_posi),
46
+ "sft:train": lambda pipe, inputs_shared, inputs_posi, inputs_nega: FlowMatchSFTLoss(pipe, **inputs_shared, **inputs_posi),
47
+ }
48
+
49
+ def get_pipeline_inputs(self, data):
50
+ inputs_posi = {"prompt": data["prompt"]}
51
+ inputs_nega = {"negative_prompt": ""}
52
+ inputs_shared = {
53
+ "input_image": data["image"],
54
+ "height": data["image"].size[1],
55
+ "width": data["image"].size[0],
56
+ "cfg_scale": 1,
57
+ "rand_device": self.pipe.device,
58
+ "use_gradient_checkpointing": self.use_gradient_checkpointing,
59
+ "use_gradient_checkpointing_offload": self.use_gradient_checkpointing_offload,
60
+ }
61
+ inputs_shared = self.parse_extra_inputs(data, self.extra_inputs, inputs_shared)
62
+ return inputs_shared, inputs_posi, inputs_nega
63
+
64
+ def forward(self, data, inputs=None):
65
+ if inputs is None: inputs = self.get_pipeline_inputs(data)
66
+ inputs = self.transfer_data_to_device(inputs, self.pipe.device, self.pipe.torch_dtype)
67
+ for unit in self.pipe.units:
68
+ inputs = self.pipe.unit_runner(unit, self.pipe, *inputs)
69
+ loss = self.task_to_loss[self.task](self.pipe, *inputs)
70
+ return loss
71
+
72
+
73
+ def ideogram4_parser():
74
+ parser = argparse.ArgumentParser(description="Ideogram4 training.")
75
+ parser = add_general_config(parser)
76
+ parser = add_image_size_config(parser)
77
+ parser.add_argument("--tokenizer_path", type=str, default=None, help="Path to tokenizer.")
78
+ return parser
79
+
80
+
81
+ if __name__ == "__main__":
82
+ parser = ideogram4_parser()
83
+ args = parser.parse_args()
84
+ accelerator = accelerate.Accelerator(
85
+ gradient_accumulation_steps=args.gradient_accumulation_steps,
86
+ kwargs_handlers=[accelerate.DistributedDataParallelKwargs(find_unused_parameters=args.find_unused_parameters)],
87
+ )
88
+ dataset = UnifiedDataset(
89
+ base_path=args.dataset_base_path,
90
+ metadata_path=args.dataset_metadata_path,
91
+ repeat=args.dataset_repeat,
92
+ data_file_keys=args.data_file_keys.split(","),
93
+ main_data_operator=UnifiedDataset.default_image_operator(
94
+ base_path=args.dataset_base_path,
95
+ max_pixels=args.max_pixels,
96
+ height=args.height,
97
+ width=args.width,
98
+ height_division_factor=16,
99
+ width_division_factor=16,
100
+ ),
101
+ )
102
+ model = Ideogram4TrainingModule(
103
+ model_paths=args.model_paths,
104
+ model_id_with_origin_paths=args.model_id_with_origin_paths,
105
+ tokenizer_path=args.tokenizer_path,
106
+ trainable_models=args.trainable_models,
107
+ lora_base_model=args.lora_base_model,
108
+ lora_target_modules=args.lora_target_modules,
109
+ lora_rank=args.lora_rank,
110
+ lora_checkpoint=args.lora_checkpoint,
111
+ preset_lora_path=args.preset_lora_path,
112
+ preset_lora_model=args.preset_lora_model,
113
+ use_gradient_checkpointing=args.use_gradient_checkpointing,
114
+ use_gradient_checkpointing_offload=args.use_gradient_checkpointing_offload,
115
+ extra_inputs=args.extra_inputs,
116
+ fp8_models=args.fp8_models,
117
+ offload_models=args.offload_models,
118
+ quant_options=args.quant_options,
119
+ task=args.task,
120
+ device=accelerator.device,
121
+ )
122
+ model_logger = ModelLogger(
123
+ args.output_path,
124
+ remove_prefix_in_ckpt=args.remove_prefix_in_ckpt,
125
+ enable_csv_log=args.enable_csv_log,
126
+ )
127
+ launcher_map = {
128
+ "sft:data_process": launch_data_process_task,
129
+ "sft": launch_training_task,
130
+ "sft:train": launch_training_task,
131
+ }
132
+ launcher_map[args.task](accelerator, dataset, model, model_logger, args=args)
examples/ideogram4/model_training/validate_lora/Ideogram-4-bf16-repackage.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.ideogram4 import Ideogram4Pipeline
2
+ from diffsynth.core import ModelConfig
3
+ import torch
4
+
5
+ pipe = Ideogram4Pipeline.from_pretrained(
6
+ torch_dtype=torch.bfloat16,
7
+ device="cuda",
8
+ model_configs=[
9
+ ModelConfig(model_id="DiffSynth-Studio/ideogram-4-bf16-repackage", origin_file_pattern="transformer/diffusion_pytorch_model.safetensors"),
10
+ ModelConfig(model_id="DiffSynth-Studio/ideogram-4-bf16-repackage", origin_file_pattern="unconditional_transformer/diffusion_pytorch_model.safetensors"),
11
+ ModelConfig(model_id="DiffSynth-Studio/ideogram-4-bf16-repackage", origin_file_pattern="text_encoder/model.safetensors"),
12
+ ModelConfig(model_id="DiffSynth-Studio/ideogram-4-bf16-repackage", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
13
+ ],
14
+ tokenizer_config=ModelConfig(model_id="ideogram-ai/ideogram-4-fp8", origin_file_pattern="tokenizer/"),
15
+ )
16
+ pipe.load_lora(pipe.dit, "models/train/Ideogram-4-bf16-repackage_lora/epoch-4.safetensors", alpha=1)
17
+ pipe.load_lora(pipe.dit_uncond, "models/train/Ideogram-4-bf16-repackage_lora/epoch-4.safetensors", alpha=1)
18
+
19
+ prompt = "{\"high_level_description\":\"A close-up photograph of a happy Pembroke Welsh Corgi sitting on a concrete wall, panting with its tongue out, set against a backdrop of blurred pink cherry blossoms and blue sky.\",\"style_description\":{\"aesthetics\":\"joyful, vibrant, spring-like, cute, energetic\",\"lighting\":\"bright natural daylight, soft diffuse sunlight, shallow depth of field\",\"photo\":\"85mm lens, f/2.0, bokeh background, sharp focus on dog face\",\"medium\":\"photograph\",\"color_palette\":[\"#E2725B\",\"#FFFFFF\",\"#FFB7C5\",\"#87CEEB\",\"#A9A9A9\"]},\"compositional_deconstruction\":{\"background\":\"Softly blurred background of pink cherry blossom branches against a pale blue sky. The bokeh effect creates a dreamy spring atmosphere. The background is out of focus to highlight the sharp details of the dog in the foreground.\",\"elements\":[{\"type\":\"obj\",\"bbox\":[150,200,900,850],\"desc\":\"A Pembroke Welsh Corgi with fluffy orange and white fur. Its mouth is open, panting with a pink tongue hanging out, expression is happy and excited. Ears are perked up. Sharp focus on the face and eyes.\"},{\"type\":\"obj\",\"bbox\":[850,0,1000,1000],\"desc\":\"A grey concrete wall or ledge at the bottom of the frame. The dog's front paws are resting near the edge. Rough texture.\"}]}}"
20
+ image = pipe(prompt=prompt, height=1024, width=1024, num_inference_steps=48, cfg_scale=7.0, seed=0)
21
+ image.save("image_lora.jpg")
examples/ideogram4/model_training/validate_lora/Ideogram-4-fp8.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.ideogram4 import Ideogram4Pipeline
2
+ from diffsynth.core import ModelConfig
3
+ import torch
4
+
5
+ vram_config = {
6
+ "offload_dtype": torch.bfloat16,
7
+ "offload_device": "cpu",
8
+ "onload_dtype": torch.bfloat16,
9
+ "onload_device": "cpu",
10
+ "preparing_dtype": torch.bfloat16,
11
+ "preparing_device": "cuda",
12
+ "computation_dtype": torch.bfloat16,
13
+ "computation_device": "cuda",
14
+ }
15
+ pipe = Ideogram4Pipeline.from_pretrained(
16
+ torch_dtype=torch.bfloat16,
17
+ device="cuda",
18
+ model_configs=[
19
+ ModelConfig(model_id="ideogram-ai/ideogram-4-fp8", origin_file_pattern="transformer/diffusion_pytorch_model.safetensors", **vram_config),
20
+ ModelConfig(model_id="ideogram-ai/ideogram-4-fp8", origin_file_pattern="unconditional_transformer/diffusion_pytorch_model.safetensors", **vram_config),
21
+ ModelConfig(model_id="ideogram-ai/ideogram-4-fp8", origin_file_pattern="text_encoder/model.safetensors", **vram_config),
22
+ ModelConfig(model_id="ideogram-ai/ideogram-4-fp8", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
23
+ ],
24
+ tokenizer_config=ModelConfig(model_id="ideogram-ai/ideogram-4-fp8", origin_file_pattern="tokenizer/"),
25
+ vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
26
+ )
27
+ pipe.load_lora(pipe.dit, "models/train/Ideogram-4-fp8_lora/epoch-4.safetensors", alpha=1)
28
+ pipe.load_lora(pipe.dit_uncond, "models/train/Ideogram-4-fp8_lora/epoch-4.safetensors", alpha=1)
29
+
30
+ prompt = "{\"high_level_description\":\"A close-up photograph of a happy Pembroke Welsh Corgi sitting on a concrete wall, panting with its tongue out, set against a backdrop of blurred pink cherry blossoms and blue sky.\",\"style_description\":{\"aesthetics\":\"joyful, vibrant, spring-like, cute, energetic\",\"lighting\":\"bright natural daylight, soft diffuse sunlight, shallow depth of field\",\"photo\":\"85mm lens, f/2.0, bokeh background, sharp focus on dog face\",\"medium\":\"photograph\",\"color_palette\":[\"#E2725B\",\"#FFFFFF\",\"#FFB7C5\",\"#87CEEB\",\"#A9A9A9\"]},\"compositional_deconstruction\":{\"background\":\"Softly blurred background of pink cherry blossom branches against a pale blue sky. The bokeh effect creates a dreamy spring atmosphere. The background is out of focus to highlight the sharp details of the dog in the foreground.\",\"elements\":[{\"type\":\"obj\",\"bbox\":[150,200,900,850],\"desc\":\"A Pembroke Welsh Corgi with fluffy orange and white fur. Its mouth is open, panting with a pink tongue hanging out, expression is happy and excited. Ears are perked up. Sharp focus on the face and eyes.\"},{\"type\":\"obj\",\"bbox\":[850,0,1000,1000],\"desc\":\"A grey concrete wall or ledge at the bottom of the frame. The dog's front paws are resting near the edge. Rough texture.\"}]}}"
31
+ image = pipe(prompt=prompt, height=1024, width=1024, num_inference_steps=48, cfg_scale=7.0, seed=0)
32
+ image.save("image_lora.jpg")
examples/ideogram4/model_training/validate_lora/Ideogram-4-nf4.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.ideogram4 import Ideogram4Pipeline
2
+ from diffsynth.core import ModelConfig
3
+ import torch
4
+
5
+ vram_config = {
6
+ "offload_dtype": torch.bfloat16,
7
+ "offload_device": "cpu",
8
+ "onload_dtype": torch.bfloat16,
9
+ "onload_device": "cpu",
10
+ "preparing_dtype": torch.bfloat16,
11
+ "preparing_device": "cuda",
12
+ "computation_dtype": torch.bfloat16,
13
+ "computation_device": "cuda",
14
+ }
15
+ pipe = Ideogram4Pipeline.from_pretrained(
16
+ torch_dtype=torch.bfloat16,
17
+ device="cuda",
18
+ model_configs=[
19
+ ModelConfig(model_id="ideogram-ai/ideogram-4-nf4", origin_file_pattern="transformer/diffusion_pytorch_model.safetensors", **vram_config),
20
+ ModelConfig(model_id="ideogram-ai/ideogram-4-nf4", origin_file_pattern="unconditional_transformer/diffusion_pytorch_model.safetensors", **vram_config),
21
+ ModelConfig(model_id="ideogram-ai/ideogram-4-nf4", origin_file_pattern="text_encoder/model.safetensors", **vram_config),
22
+ ModelConfig(model_id="ideogram-ai/ideogram-4-nf4", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
23
+ ],
24
+ tokenizer_config=ModelConfig(model_id="ideogram-ai/ideogram-4-nf4", origin_file_pattern="tokenizer/"),
25
+ vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
26
+ )
27
+ pipe.load_lora(pipe.dit, "models/train/Ideogram-4-nf4_lora/epoch-4.safetensors", alpha=1)
28
+ pipe.load_lora(pipe.dit_uncond, "models/train/Ideogram-4-nf4_lora/epoch-4.safetensors", alpha=1)
29
+
30
+ prompt = "{\"high_level_description\":\"A close-up photograph of a happy Pembroke Welsh Corgi sitting on a concrete wall, panting with its tongue out, set against a backdrop of blurred pink cherry blossoms and blue sky.\",\"style_description\":{\"aesthetics\":\"joyful, vibrant, spring-like, cute, energetic\",\"lighting\":\"bright natural daylight, soft diffuse sunlight, shallow depth of field\",\"photo\":\"85mm lens, f/2.0, bokeh background, sharp focus on dog face\",\"medium\":\"photograph\",\"color_palette\":[\"#E2725B\",\"#FFFFFF\",\"#FFB7C5\",\"#87CEEB\",\"#A9A9A9\"]},\"compositional_deconstruction\":{\"background\":\"Softly blurred background of pink cherry blossom branches against a pale blue sky. The bokeh effect creates a dreamy spring atmosphere. The background is out of focus to highlight the sharp details of the dog in the foreground.\",\"elements\":[{\"type\":\"obj\",\"bbox\":[150,200,900,850],\"desc\":\"A Pembroke Welsh Corgi with fluffy orange and white fur. Its mouth is open, panting with a pink tongue hanging out, expression is happy and excited. Ears are perked up. Sharp focus on the face and eyes.\"},{\"type\":\"obj\",\"bbox\":[850,0,1000,1000],\"desc\":\"A grey concrete wall or ledge at the bottom of the frame. The dog's front paws are resting near the edge. Rough texture.\"}]}}"
31
+ image = pipe(prompt=prompt, height=1024, width=1024, num_inference_steps=48, cfg_scale=7.0, seed=0)
32
+ image.save("image_lora.jpg")
examples/image_quality_metric/aesthetic.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import AestheticMetric, ModelConfig
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+
5
+ dataset_snapshot_download(
6
+ "DiffSynth-Studio/diffsynth_example_dataset",
7
+ allow_file_pattern="flux/FLUX.1-dev/*",
8
+ local_dir="./data/diffsynth_example_dataset",
9
+ )
10
+ image = Image.open("data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg").convert("RGB")
11
+ metric = AestheticMetric.from_pretrained(
12
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="Aesthetic/model.safetensors"),
13
+ device="cuda"
14
+ )
15
+ score = metric.compute(image)[0]
16
+ print(f"Aesthetic score: {score:.3f}")
examples/image_quality_metric/bioclip.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import BioCLIPMetric, ModelConfig
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+
5
+ dataset_snapshot_download(
6
+ "DiffSynth-Studio/diffsynth_example_dataset",
7
+ allow_file_pattern="flux/FLUX.1-dev/*",
8
+ local_dir="./data/diffsynth_example_dataset",
9
+ )
10
+ image = Image.open("data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg").convert("RGB")
11
+ prompt = "a photo of Animalia Chordata Mammalia Carnivora Canidae Canis Canis lupus familiaris with common name domestic dog."
12
+ metric = BioCLIPMetric.from_pretrained(
13
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="BioCLIPv2/open_clip_model.safetensors"),
14
+ device="cuda",
15
+ )
16
+ score = metric.compute(prompt, image)[0]
17
+ print(f"BioCLIP score: {score:.3f}")
examples/image_quality_metric/clipscore.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import CLIPMetric, ModelConfig
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+
5
+ dataset_snapshot_download(
6
+ "DiffSynth-Studio/diffsynth_example_dataset",
7
+ allow_file_pattern="flux/FLUX.1-dev/*",
8
+ local_dir="./data/diffsynth_example_dataset",
9
+ )
10
+ image = Image.open("data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg").convert("RGB")
11
+ prompt = "a dog"
12
+ metric = CLIPMetric.from_pretrained(
13
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="CLIP-ViT-H-14-laion2B-s32B-b79K/model.safetensors"),
14
+ device="cuda"
15
+ )
16
+ score = metric.compute(prompt, image)[0]
17
+ print(f"CLIP score: {score:.3f}")
examples/image_quality_metric/fid.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import FIDMetric, ModelConfig
2
+ from modelscope import dataset_snapshot_download
3
+
4
+ dataset_snapshot_download(
5
+ "DiffSynth-Studio/diffsynth_example_dataset",
6
+ allow_file_pattern=["flux/FLUX.1-dev/*", "flux2/FLUX.2-dev/*"],
7
+ local_dir="./data/diffsynth_example_dataset",
8
+ )
9
+ metric = FIDMetric.from_pretrained(
10
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="FID/model.safetensors"),
11
+ device="cuda",
12
+ )
13
+ score = metric.compute(
14
+ "./data/diffsynth_example_dataset/flux/FLUX.1-dev",
15
+ "./data/diffsynth_example_dataset/flux2/FLUX.2-dev",
16
+ )
17
+ print(f"FID score: {score:.3f}")
examples/image_quality_metric/hpsv2.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import HPSv2Metric, ModelConfig
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+
5
+ dataset_snapshot_download(
6
+ "DiffSynth-Studio/diffsynth_example_dataset",
7
+ allow_file_pattern="flux/FLUX.1-dev/*",
8
+ local_dir="./data/diffsynth_example_dataset",
9
+ )
10
+ image = Image.open("data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg").convert("RGB")
11
+ prompt = "a dog"
12
+ metric = HPSv2Metric.from_pretrained(
13
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="HPSv2/model.safetensors"),
14
+ device="cuda"
15
+ )
16
+ score = metric.compute(prompt, image)[0]
17
+ print(f"HPSv2 score: {score:.3f}")
examples/image_quality_metric/hpsv3.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import HPSv3Metric, ModelConfig
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+
5
+ dataset_snapshot_download(
6
+ "DiffSynth-Studio/diffsynth_example_dataset",
7
+ allow_file_pattern="flux/FLUX.1-dev/*",
8
+ local_dir="./data/diffsynth_example_dataset",
9
+ )
10
+ image = Image.open("data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg").convert("RGB")
11
+ prompt = "a dog"
12
+ metric = HPSv3Metric.from_pretrained(
13
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="HPSv3/model.safetensors"),
14
+ device="cuda"
15
+ )
16
+ score = metric.compute(prompt, image)[0]
17
+ print(f"HPSv3 score: {score:.3f}")
examples/image_quality_metric/image_reward.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import ImageRewardMetric, ModelConfig
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+
5
+ dataset_snapshot_download(
6
+ "DiffSynth-Studio/diffsynth_example_dataset",
7
+ allow_file_pattern="flux/FLUX.1-dev/*",
8
+ local_dir="./data/diffsynth_example_dataset",
9
+ )
10
+ image = Image.open("data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg").convert("RGB")
11
+ prompt = "a dog"
12
+ metric = ImageRewardMetric.from_pretrained(
13
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="ImageReward/model.safetensors"),
14
+ device="cuda"
15
+ )
16
+ score = metric.compute(prompt, image)[0]
17
+ print(f"ImageReward score: {score:.3f}")
examples/image_quality_metric/lpips.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import LPIPSMetric, ModelConfig
2
+ from modelscope import dataset_snapshot_download
3
+
4
+ dataset_snapshot_download(
5
+ "DiffSynth-Studio/diffsynth_example_dataset",
6
+ allow_file_pattern=["flux/FLUX.1-dev/*", "flux2/FLUX.2-dev/*"],
7
+ local_dir="./data/diffsynth_example_dataset",
8
+ )
9
+
10
+ # net="alex" with LPIPS/alexnet.safetensors (default)
11
+ # For VGG: net="vgg", model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="LPIPS/vgg.safetensors")
12
+ # For SqueezeNet: net="squeeze", model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="LPIPS/squeezenet.safetensors")
13
+ metric = LPIPSMetric.from_pretrained(
14
+ net="alex",
15
+ model_config=ModelConfig(
16
+ model_id="DiffSynth-Studio/ImageMetrics",
17
+ origin_file_pattern="LPIPS/alexnet.safetensors",
18
+ ),
19
+ device="cuda",
20
+ target_size=512,
21
+ )
22
+
23
+ score = metric.compute(
24
+ "./data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg",
25
+ "./data/diffsynth_example_dataset/flux/FLUX.1-dev/2.jpg",
26
+ )
27
+ print(f"LPIPS score (image vs image): {score:.4f}")
28
+
29
+ score = metric.compute(
30
+ "./data/diffsynth_example_dataset/flux/FLUX.1-dev",
31
+ "./data/diffsynth_example_dataset/flux2/FLUX.2-dev",
32
+ )
33
+ print(f"LPIPS score (dir vs dir): {score:.4f}")
examples/image_quality_metric/pickscore.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import PickScoreMetric, ModelConfig
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+
5
+ dataset_snapshot_download(
6
+ "DiffSynth-Studio/diffsynth_example_dataset",
7
+ allow_file_pattern="flux/FLUX.1-dev/*",
8
+ local_dir="./data/diffsynth_example_dataset",
9
+ )
10
+ image = Image.open("data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg").convert("RGB")
11
+ prompt = "a dog"
12
+ metric = PickScoreMetric.from_pretrained(
13
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="PickScore/model.safetensors"),
14
+ device="cuda"
15
+ )
16
+ score = metric.compute(prompt, image)[0]
17
+ print(f"PickScore score:: {score:.3f}")
examples/image_quality_metric/qwen_image_bench.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import ModelConfig, QwenImageBenchMetric
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+ import json
5
+
6
+ dataset_snapshot_download(
7
+ "DiffSynth-Studio/diffsynth_example_dataset",
8
+ allow_file_pattern="flux/FLUX.1-dev/*",
9
+ local_dir="./data/diffsynth_example_dataset",
10
+ )
11
+ image = Image.open("data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg").convert("RGB")
12
+ prompt = "a dog"
13
+ metric = QwenImageBenchMetric.from_pretrained(
14
+ model_config=ModelConfig(model_id="Qwen/Qwen-Image-Bench", origin_file_pattern="model-*.safetensors"),
15
+ processor_config=ModelConfig(model_id="Qwen/Qwen-Image-Bench"),
16
+ device="cuda",
17
+ )
18
+ details = metric.evaluate(prompt, image)[0]
19
+ print(json.dumps(details["level1_scores"], indent=4, ensure_ascii=False))
20
+ print(json.dumps(details["level2_scores"], indent=4, ensure_ascii=False))
21
+ print(json.dumps(details["level3_scores"], indent=4, ensure_ascii=False))
examples/image_quality_metric/unified_reward_2.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import ModelConfig, UnifiedReward2Metric
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+ import json
5
+
6
+ dataset_snapshot_download(
7
+ "DiffSynth-Studio/diffsynth_example_dataset",
8
+ allow_file_pattern="flux/FLUX.1-dev/*",
9
+ local_dir="./data/diffsynth_example_dataset",
10
+ )
11
+ image = Image.open("data/diffsynth_example_dataset/flux/FLUX.1-dev/1.jpg").convert("RGB")
12
+ prompt = "a dog"
13
+ metric = UnifiedReward2Metric.from_pretrained(
14
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="UnifiedReward-2.0-qwen35-9b/model-*.safetensors"),
15
+ processor_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="UnifiedReward-2.0-qwen35-9b/"),
16
+ device="cuda",
17
+ )
18
+ details = metric.evaluate(prompt, image)[0]
19
+ print(json.dumps(details, indent=4, ensure_ascii=False))
examples/image_quality_metric/unified_reward_edit.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.metrics import ModelConfig, UnifiedRewardEditMetric
2
+ from modelscope import dataset_snapshot_download
3
+ from PIL import Image
4
+ import json
5
+
6
+ dataset_snapshot_download(
7
+ "DiffSynth-Studio/diffsynth_example_dataset",
8
+ allow_file_pattern="qwen_image/Qwen-Image-Edit/*",
9
+ local_dir="./data/diffsynth_example_dataset",
10
+ )
11
+ source_image = Image.open("data/diffsynth_example_dataset/qwen_image/Qwen-Image-Edit/edit/image1.jpg").convert("RGB")
12
+ edited_image_1 = Image.open("data/diffsynth_example_dataset/qwen_image/Qwen-Image-Edit/edit/image2.jpg").convert("RGB")
13
+ edited_image_2 = source_image
14
+ instruction = "Change the dress to pink."
15
+ metric = UnifiedRewardEditMetric.from_pretrained(
16
+ model_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="UnifiedReward-Edit-qwen3vl-8b/model-*.safetensors"),
17
+ processor_config=ModelConfig(model_id="DiffSynth-Studio/ImageMetrics", origin_file_pattern="UnifiedReward-Edit-qwen3vl-8b/"),
18
+ device="cuda",
19
+ )
20
+ details = metric.evaluate(instruction, [source_image, edited_image_1], task="edit_pointwise_score")[0]
21
+ print(json.dumps(details, indent=4, ensure_ascii=False))
22
+ details = metric.evaluate(instruction, [source_image, edited_image_1, edited_image_2], task="edit_pairwise_rank")[0]
23
+ print(json.dumps(details, indent=4, ensure_ascii=False))
24
+ details = metric.evaluate(instruction, [source_image, edited_image_1, edited_image_2], task="edit_pairwise_score")[0]
25
+ print(json.dumps(details, indent=4, ensure_ascii=False))
examples/joyai_image/model_inference/JoyAI-Image-Edit.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.joyai_image import JoyAIImagePipeline, ModelConfig
2
+ import torch
3
+ from PIL import Image
4
+ from modelscope import dataset_snapshot_download
5
+
6
+ # Download dataset
7
+ dataset_snapshot_download(
8
+ dataset_id="DiffSynth-Studio/diffsynth_example_dataset",
9
+ local_dir="data/diffsynth_example_dataset",
10
+ allow_file_pattern="joyai_image/JoyAI-Image-Edit/*"
11
+ )
12
+
13
+ pipe = JoyAIImagePipeline.from_pretrained(
14
+ torch_dtype=torch.bfloat16,
15
+ device="cuda",
16
+ model_configs=[
17
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="transformer/transformer.pth"),
18
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/model*.safetensors"),
19
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="vae/Wan2.1_VAE.pth"),
20
+ ],
21
+ processor_config=ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/"),
22
+ )
23
+
24
+ # Use first sample from dataset
25
+ dataset_base_path = "data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit"
26
+ prompt = "将裙子改为粉色"
27
+ edit_image = Image.open(f"{dataset_base_path}/edit/image1.jpg").convert("RGB")
28
+
29
+ output = pipe(
30
+ prompt=prompt,
31
+ edit_image=edit_image,
32
+ height=1024,
33
+ width=1024,
34
+ seed=1,
35
+ num_inference_steps=30,
36
+ cfg_scale=5.0,
37
+ )
38
+
39
+ output.save("output_joyai_edit.png")
examples/joyai_image/model_inference_low_vram/JoyAI-Image-Edit.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.joyai_image import JoyAIImagePipeline, ModelConfig
2
+ import torch
3
+ from PIL import Image
4
+ from modelscope import dataset_snapshot_download
5
+
6
+ # Download dataset
7
+ dataset_snapshot_download(
8
+ dataset_id="DiffSynth-Studio/diffsynth_example_dataset",
9
+ local_dir="data/diffsynth_example_dataset",
10
+ allow_file_pattern="joyai_image/JoyAI-Image-Edit/*"
11
+ )
12
+
13
+ vram_config = {
14
+ "offload_dtype": torch.bfloat16,
15
+ "offload_device": "cpu",
16
+ "onload_dtype": torch.bfloat16,
17
+ "onload_device": "cpu",
18
+ "preparing_dtype": torch.bfloat16,
19
+ "preparing_device": "cuda",
20
+ "computation_dtype": torch.bfloat16,
21
+ "computation_device": "cuda",
22
+ }
23
+
24
+ pipe = JoyAIImagePipeline.from_pretrained(
25
+ torch_dtype=torch.bfloat16,
26
+ device="cuda",
27
+ model_configs=[
28
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="transformer/transformer.pth", **vram_config),
29
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/model*.safetensors", **vram_config),
30
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="vae/Wan2.1_VAE.pth", **vram_config),
31
+ ],
32
+ processor_config=ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/"),
33
+ vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 0.5,
34
+ )
35
+
36
+ # Use first sample from dataset
37
+ dataset_base_path = "data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit"
38
+ prompt = "将裙子改为粉色"
39
+ edit_image = Image.open(f"{dataset_base_path}/edit/image1.jpg").convert("RGB")
40
+
41
+ output = pipe(
42
+ prompt=prompt,
43
+ edit_image=edit_image,
44
+ height=1024,
45
+ width=1024,
46
+ seed=0,
47
+ num_inference_steps=30,
48
+ cfg_scale=5.0,
49
+ )
50
+
51
+ output.save("output_joyai_edit_low_vram.png")
examples/joyai_image/model_training/full/JoyAI-Image-Edit.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dataset: data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit/
2
+ # Download: modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "joyai_image/JoyAI-Image-Edit/*" --local_dir ./data/diffsynth_example_dataset
3
+
4
+ accelerate launch examples/joyai_image/model_training/train.py \
5
+ --dataset_base_path "./data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit" \
6
+ --dataset_metadata_path "./data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit/metadata.csv" \
7
+ --max_pixels 1048576 \
8
+ --dataset_repeat 1 \
9
+ --model_id_with_origin_paths "jd-opensource/JoyAI-Image-Edit:JoyAI-Image-Und/model*.safetensors,jd-opensource/JoyAI-Image-Edit:vae/Wan2.1_VAE.pth" \
10
+ --learning_rate 1e-5 \
11
+ --num_epochs 2 \
12
+ --remove_prefix_in_ckpt "pipe.dit." \
13
+ --output_path "./models/train/JoyAI-Image-Edit-full-cache" \
14
+ --use_gradient_checkpointing \
15
+ --find_unused_parameters \
16
+ --data_file_keys "image,edit_image" \
17
+ --extra_inputs "edit_image" \
18
+ --task "sft:data_process"
19
+
20
+ accelerate launch --config_file examples/joyai_image/model_training/full/accelerate_config_zero3.yaml \
21
+ examples/joyai_image/model_training/train.py \
22
+ --dataset_base_path "./models/train/JoyAI-Image-Edit-full-cache" \
23
+ --max_pixels 1048576 \
24
+ --dataset_repeat 50 \
25
+ --model_id_with_origin_paths "jd-opensource/JoyAI-Image-Edit:transformer/transformer.pth" \
26
+ --learning_rate 1e-5 \
27
+ --num_epochs 2 \
28
+ --remove_prefix_in_ckpt "pipe.dit." \
29
+ --output_path "./models/train/JoyAI-Image-Edit-full" \
30
+ --trainable_models "dit" \
31
+ --use_gradient_checkpointing \
32
+ --find_unused_parameters \
33
+ --data_file_keys "image,edit_image" \
34
+ --extra_inputs "edit_image" \
35
+ --task "sft:train"
examples/joyai_image/model_training/full/accelerate_config_zero3.yaml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ compute_environment: LOCAL_MACHINE
2
+ debug: false
3
+ deepspeed_config:
4
+ gradient_accumulation_steps: 1
5
+ offload_optimizer_device: none
6
+ offload_param_device: none
7
+ zero3_init_flag: true
8
+ zero3_save_16bit_model: true
9
+ zero_stage: 3
10
+ distributed_type: DEEPSPEED
11
+ downcast_bf16: 'no'
12
+ enable_cpu_affinity: false
13
+ machine_rank: 0
14
+ main_training_function: main
15
+ mixed_precision: bf16
16
+ num_machines: 1
17
+ num_processes: 8
18
+ rdzv_backend: static
19
+ same_network: true
20
+ tpu_env: []
21
+ tpu_use_cluster: false
22
+ tpu_use_sudo: false
23
+ use_cpu: false
examples/joyai_image/model_training/lora/JoyAI-Image-Edit.sh ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dataset: data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit/
2
+ # Download: modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "joyai_image/JoyAI-Image-Edit/*" --local_dir ./data/diffsynth_example_dataset
3
+
4
+ accelerate launch examples/joyai_image/model_training/train.py \
5
+ --dataset_base_path "./data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit" \
6
+ --dataset_metadata_path "./data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit/metadata.csv" \
7
+ --max_pixels 1048576 \
8
+ --dataset_repeat 1 \
9
+ --model_id_with_origin_paths "jd-opensource/JoyAI-Image-Edit:JoyAI-Image-Und/model*.safetensors,jd-opensource/JoyAI-Image-Edit:vae/Wan2.1_VAE.pth" \
10
+ --learning_rate 1e-4 \
11
+ --num_epochs 5 \
12
+ --remove_prefix_in_ckpt "pipe.dit." \
13
+ --output_path "./models/train/JoyAI-Image-Edit-split-cache" \
14
+ --lora_base_model "dit" \
15
+ --lora_target_modules "img_attn_qkv,txt_attn_qkv,img_attn_proj,txt_attn_proj" \
16
+ --lora_rank 32 \
17
+ --use_gradient_checkpointing \
18
+ --find_unused_parameters \
19
+ --data_file_keys "image,edit_image" \
20
+ --extra_inputs "edit_image" \
21
+ --task "sft:data_process"
22
+
23
+ accelerate launch examples/joyai_image/model_training/train.py \
24
+ --dataset_base_path "./models/train/JoyAI-Image-Edit-split-cache" \
25
+ --max_pixels 1048576 \
26
+ --dataset_repeat 50 \
27
+ --model_id_with_origin_paths "jd-opensource/JoyAI-Image-Edit:transformer/transformer.pth" \
28
+ --learning_rate 1e-4 \
29
+ --num_epochs 5 \
30
+ --remove_prefix_in_ckpt "pipe.dit." \
31
+ --output_path "./models/train/JoyAI-Image-Edit-lora" \
32
+ --lora_base_model "dit" \
33
+ --lora_target_modules "img_attn_qkv,txt_attn_qkv,img_attn_proj,txt_attn_proj" \
34
+ --lora_rank 32 \
35
+ --use_gradient_checkpointing \
36
+ --find_unused_parameters \
37
+ --data_file_keys "image,edit_image" \
38
+ --extra_inputs "edit_image" \
39
+ --task "sft:train"
examples/joyai_image/model_training/special/split_training/JoyAI-Image-Edit.sh ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "joyai_image/JoyAI-Image-Edit/*" --local_dir ./data/diffsynth_example_dataset
2
+
3
+ # Stage 1: cache deterministic preprocessing outputs.
4
+ accelerate launch examples/joyai_image/model_training/train.py \
5
+ --dataset_base_path ./data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit \
6
+ --dataset_metadata_path ./data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit/metadata.csv \
7
+ --max_pixels 1048576 \
8
+ --dataset_repeat 1 \
9
+ --model_id_with_origin_paths 'jd-opensource/JoyAI-Image-Edit:transformer/transformer.pth,jd-opensource/JoyAI-Image-Edit:JoyAI-Image-Und/model*.safetensors,jd-opensource/JoyAI-Image-Edit:vae/Wan2.1_VAE.pth' \
10
+ --learning_rate 1e-4 \
11
+ --num_epochs 5 \
12
+ --remove_prefix_in_ckpt pipe.dit. \
13
+ --output_path ./models/train/JoyAI-Image-Edit-split-cache \
14
+ --lora_base_model dit \
15
+ --lora_target_modules img_attn_qkv,txt_attn_qkv,img_attn_proj,txt_attn_proj \
16
+ --lora_rank 32 \
17
+ --use_gradient_checkpointing \
18
+ --find_unused_parameters \
19
+ --data_file_keys image,edit_image \
20
+ --extra_inputs edit_image \
21
+ --task sft:data_process \
22
+ --offload_models jd-opensource/JoyAI-Image-Edit:transformer/transformer.pth
23
+
24
+ # Stage 2: train LoRA from the cached dataset.
25
+ accelerate launch examples/joyai_image/model_training/train.py \
26
+ --dataset_base_path ./models/train/JoyAI-Image-Edit-split-cache \
27
+ --max_pixels 1048576 \
28
+ --dataset_repeat 50 \
29
+ --model_id_with_origin_paths 'jd-opensource/JoyAI-Image-Edit:transformer/transformer.pth,jd-opensource/JoyAI-Image-Edit:JoyAI-Image-Und/model*.safetensors,jd-opensource/JoyAI-Image-Edit:vae/Wan2.1_VAE.pth' \
30
+ --learning_rate 1e-4 \
31
+ --num_epochs 5 \
32
+ --remove_prefix_in_ckpt pipe.dit. \
33
+ --output_path ./models/train/JoyAI-Image-Edit-split \
34
+ --lora_base_model dit \
35
+ --lora_target_modules img_attn_qkv,txt_attn_qkv,img_attn_proj,txt_attn_proj \
36
+ --lora_rank 32 \
37
+ --use_gradient_checkpointing \
38
+ --find_unused_parameters \
39
+ --data_file_keys image,edit_image \
40
+ --extra_inputs edit_image \
41
+ --task sft:train \
42
+ --offload_models 'jd-opensource/JoyAI-Image-Edit:JoyAI-Image-Und/model*.safetensors,jd-opensource/JoyAI-Image-Edit:vae/Wan2.1_VAE.pth'
examples/joyai_image/model_training/special/split_training/validate.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from PIL import Image
3
+ from diffsynth.pipelines.joyai_image import JoyAIImagePipeline, ModelConfig
4
+
5
+ pipe = JoyAIImagePipeline.from_pretrained(
6
+ torch_dtype=torch.bfloat16,
7
+ device="cuda",
8
+ model_configs=[
9
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="transformer/transformer.pth"),
10
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/model*.safetensors"),
11
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="vae/Wan2.1_VAE.pth"),
12
+ ],
13
+ processor_config=ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/"),
14
+ )
15
+
16
+ pipe.load_lora(pipe.dit, './models/train/JoyAI-Image-Edit-split/epoch-4.safetensors')
17
+
18
+ prompt = "将裙子改为粉色"
19
+ edit_image = Image.open("data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit/edit/image1.jpg").convert("RGB")
20
+
21
+ image = pipe(
22
+ prompt=prompt,
23
+ edit_image=edit_image,
24
+ height=1024,
25
+ width=1024,
26
+ seed=0,
27
+ num_inference_steps=30,
28
+ cfg_scale=5.0,
29
+ )
30
+ image.save('split_training_JoyAI-Image-Edit.jpg')
examples/joyai_image/model_training/train.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch, os, argparse, accelerate
2
+ from diffsynth.core import UnifiedDataset
3
+ from diffsynth.pipelines.joyai_image import JoyAIImagePipeline, ModelConfig
4
+ from diffsynth.diffusion import *
5
+ from diffsynth.core.data.operators import *
6
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
7
+
8
+
9
+ class JoyAIImageTrainingModule(DiffusionTrainingModule):
10
+ def __init__(
11
+ self,
12
+ model_paths=None, model_id_with_origin_paths=None,
13
+ processor_path=None,
14
+ trainable_models=None,
15
+ lora_base_model=None, lora_target_modules="", lora_rank=32, lora_checkpoint=None,
16
+ preset_lora_path=None, preset_lora_model=None,
17
+ use_gradient_checkpointing=True,
18
+ use_gradient_checkpointing_offload=False,
19
+ extra_inputs=None,
20
+ fp8_models=None,
21
+ offload_models=None,
22
+ quant_options=None,
23
+ resume_from_checkpoint=None, remove_prefix_in_ckpt=None,
24
+ device="cpu",
25
+ task="sft",
26
+ ):
27
+ super().__init__()
28
+ # Load models
29
+ model_configs = self.parse_model_configs(model_paths, model_id_with_origin_paths, fp8_models=fp8_models, offload_models=offload_models, quant_options=quant_options, device=device)
30
+ processor_config = ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/") if processor_path is None else ModelConfig(processor_path)
31
+ self.pipe = JoyAIImagePipeline.from_pretrained(torch_dtype=torch.bfloat16, device=device, model_configs=model_configs, processor_config=processor_config)
32
+ self.pipe = self.split_pipeline_units(task, self.pipe, trainable_models, lora_base_model)
33
+ self.resume_from_checkpoint(resume_from_checkpoint, remove_prefix_in_ckpt)
34
+
35
+ # Training mode
36
+ self.switch_pipe_to_training_mode(
37
+ self.pipe, trainable_models,
38
+ lora_base_model, lora_target_modules, lora_rank, lora_checkpoint,
39
+ preset_lora_path, preset_lora_model,
40
+ task=task,
41
+ )
42
+
43
+ # Other configs
44
+ self.use_gradient_checkpointing = use_gradient_checkpointing
45
+ self.use_gradient_checkpointing_offload = use_gradient_checkpointing_offload
46
+ self.extra_inputs = extra_inputs.split(",") if extra_inputs is not None else []
47
+ self.fp8_models = fp8_models
48
+ self.task = task
49
+ self.task_to_loss = {
50
+ "sft:data_process": lambda pipe, *args: args,
51
+ "sft": lambda pipe, inputs_shared, inputs_posi, inputs_nega: FlowMatchSFTLoss(pipe, **inputs_shared, **inputs_posi),
52
+ "sft:train": lambda pipe, inputs_shared, inputs_posi, inputs_nega: FlowMatchSFTLoss(pipe, **inputs_shared, **inputs_posi),
53
+ }
54
+
55
+ def get_pipeline_inputs(self, data):
56
+ inputs_posi = {"prompt": data["prompt"]}
57
+ inputs_nega = {"negative_prompt": ""}
58
+ inputs_shared = {
59
+ # Assume you are using this pipeline for inference,
60
+ # please fill in the input parameters.
61
+ "input_image": data["image"],
62
+ "height": data["image"].size[1],
63
+ "width": data["image"].size[0],
64
+ # Please do not modify the following parameters
65
+ # unless you clearly know what this will cause.
66
+ "cfg_scale": 1,
67
+ "rand_device": self.pipe.device,
68
+ "use_gradient_checkpointing": self.use_gradient_checkpointing,
69
+ "use_gradient_checkpointing_offload": self.use_gradient_checkpointing_offload,
70
+ }
71
+ inputs_shared = self.parse_extra_inputs(data, self.extra_inputs, inputs_shared)
72
+ return inputs_shared, inputs_posi, inputs_nega
73
+
74
+ def forward(self, data, inputs=None):
75
+ if inputs is None: inputs = self.get_pipeline_inputs(data)
76
+ inputs = self.transfer_data_to_device(inputs, self.pipe.device, self.pipe.torch_dtype)
77
+ for unit in self.pipe.units:
78
+ inputs = self.pipe.unit_runner(unit, self.pipe, *inputs)
79
+ loss = self.task_to_loss[self.task](self.pipe, *inputs)
80
+ return loss
81
+
82
+
83
+ def joyai_image_parser():
84
+ parser = argparse.ArgumentParser(description="JoyAI-Image training.")
85
+ parser = add_general_config(parser)
86
+ parser = add_image_size_config(parser)
87
+ parser.add_argument("--processor_path", type=str, default=None, help="Path to the processor.")
88
+ parser.add_argument("--initialize_model_on_cpu", default=False, action="store_true", help="Whether to initialize models on CPU.")
89
+ return parser
90
+
91
+
92
+ if __name__ == "__main__":
93
+ parser = joyai_image_parser()
94
+ args = parser.parse_args()
95
+ accelerator = accelerate.Accelerator(
96
+ gradient_accumulation_steps=args.gradient_accumulation_steps,
97
+ kwargs_handlers=[accelerate.DistributedDataParallelKwargs(find_unused_parameters=args.find_unused_parameters)],
98
+ )
99
+ dataset = UnifiedDataset(
100
+ base_path=args.dataset_base_path,
101
+ metadata_path=args.dataset_metadata_path,
102
+ repeat=args.dataset_repeat,
103
+ data_file_keys=args.data_file_keys.split(","),
104
+ main_data_operator=UnifiedDataset.default_image_operator(
105
+ base_path=args.dataset_base_path,
106
+ max_pixels=args.max_pixels,
107
+ height=args.height,
108
+ width=args.width,
109
+ height_division_factor=16,
110
+ width_division_factor=16,
111
+ ),
112
+ )
113
+ model = JoyAIImageTrainingModule(
114
+ model_paths=args.model_paths,
115
+ model_id_with_origin_paths=args.model_id_with_origin_paths,
116
+ processor_path=args.processor_path,
117
+ trainable_models=args.trainable_models,
118
+ lora_base_model=args.lora_base_model,
119
+ lora_target_modules=args.lora_target_modules,
120
+ lora_rank=args.lora_rank,
121
+ lora_checkpoint=args.lora_checkpoint,
122
+ preset_lora_path=args.preset_lora_path,
123
+ preset_lora_model=args.preset_lora_model,
124
+ use_gradient_checkpointing=args.use_gradient_checkpointing,
125
+ use_gradient_checkpointing_offload=args.use_gradient_checkpointing_offload,
126
+ extra_inputs=args.extra_inputs,
127
+ fp8_models=args.fp8_models,
128
+ offload_models=args.offload_models,
129
+ quant_options=args.quant_options,
130
+ resume_from_checkpoint=args.resume_from_checkpoint,
131
+ remove_prefix_in_ckpt=args.remove_prefix_in_ckpt,
132
+ task=args.task,
133
+ device="cpu" if (args.initialize_model_on_cpu or args.enable_model_cpu_offload) else accelerator.device,
134
+ )
135
+ model_logger = ModelLogger(
136
+ args.output_path,
137
+ remove_prefix_in_ckpt=args.remove_prefix_in_ckpt,
138
+ enable_tensorboard_log=args.enable_tensorboard_log,
139
+ enable_swanlab_log=args.enable_swanlab_log,
140
+ swanlab_project=args.swanlab_project,
141
+ enable_wandb_log=args.enable_wandb_log,
142
+ wandb_project=args.wandb_project,
143
+ enable_csv_log=args.enable_csv_log,
144
+ )
145
+ launcher_map = {
146
+ "sft:data_process": launch_data_process_task,
147
+ "sft": launch_training_task,
148
+ "sft:train": launch_training_task,
149
+ }
150
+ launcher_map[args.task](accelerator, dataset, model, model_logger, args=args)
examples/joyai_image/model_training/validate_full/JoyAI-Image-Edit.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from PIL import Image
3
+ from diffsynth.pipelines.joyai_image import JoyAIImagePipeline, ModelConfig
4
+ from diffsynth import load_state_dict
5
+
6
+ pipe = JoyAIImagePipeline.from_pretrained(
7
+ torch_dtype=torch.bfloat16,
8
+ device="cuda",
9
+ model_configs=[
10
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="transformer/transformer.pth"),
11
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/model*.safetensors"),
12
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="vae/Wan2.1_VAE.pth"),
13
+ ],
14
+ processor_config=ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/"),
15
+ )
16
+
17
+ state_dict = load_state_dict("models/train/JoyAI-Image-Edit_full/epoch-1.safetensors")
18
+ pipe.dit.load_state_dict(state_dict)
19
+
20
+ prompt = "将裙子改为粉色"
21
+ edit_image = Image.open("data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit/edit/image1.jpg").convert("RGB")
22
+
23
+ image = pipe(
24
+ prompt=prompt,
25
+ edit_image=edit_image,
26
+ height=1024,
27
+ width=1024,
28
+ seed=0,
29
+ num_inference_steps=50,
30
+ cfg_scale=5.0,
31
+ )
32
+ image.save("image_full.jpg")
examples/joyai_image/model_training/validate_lora/JoyAI-Image-Edit.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from PIL import Image
3
+ from diffsynth.pipelines.joyai_image import JoyAIImagePipeline, ModelConfig
4
+
5
+ pipe = JoyAIImagePipeline.from_pretrained(
6
+ torch_dtype=torch.bfloat16,
7
+ device="cuda",
8
+ model_configs=[
9
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="transformer/transformer.pth"),
10
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/model*.safetensors"),
11
+ ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="vae/Wan2.1_VAE.pth"),
12
+ ],
13
+ processor_config=ModelConfig(model_id="jd-opensource/JoyAI-Image-Edit", origin_file_pattern="JoyAI-Image-Und/"),
14
+ )
15
+
16
+ pipe.load_lora(pipe.dit, "models/train/JoyAI-Image-Edit-lora/epoch-4.safetensors")
17
+
18
+ prompt = "将裙子改为粉色"
19
+ edit_image = Image.open("data/diffsynth_example_dataset/joyai_image/JoyAI-Image-Edit/edit/image1.jpg").convert("RGB")
20
+
21
+ image = pipe(
22
+ prompt=prompt,
23
+ edit_image=edit_image,
24
+ height=1024,
25
+ width=1024,
26
+ seed=0,
27
+ num_inference_steps=30,
28
+ cfg_scale=5.0,
29
+ )
30
+ image.save("image_lora.jpg")
examples/krea2/model_inference/Krea-2-Raw.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
2
+ import torch
3
+
4
+
5
+ pipe = Krea2Pipeline.from_pretrained(
6
+ torch_dtype=torch.bfloat16,
7
+ device="cuda",
8
+ model_configs=[
9
+ ModelConfig(model_id="krea/Krea-2-Raw", origin_file_pattern="raw.safetensors"),
10
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
11
+ ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
12
+ ],
13
+ tokenizer_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
14
+ )
15
+ prompt = "A cat standing on a stone."
16
+ image = pipe(prompt, seed=0, num_inference_steps=52, cfg_scale=4.5)
17
+ image.save("image.jpg")
examples/krea2/model_inference/Krea-2-Turbo.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
2
+ import torch
3
+
4
+
5
+ pipe = Krea2Pipeline.from_pretrained(
6
+ torch_dtype=torch.bfloat16,
7
+ device="cuda",
8
+ model_configs=[
9
+ ModelConfig(model_id="krea/Krea-2-Turbo", origin_file_pattern="turbo.safetensors"),
10
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
11
+ ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
12
+ ],
13
+ tokenizer_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
14
+ )
15
+ prompt = "Portrait of a woman in a blue dress, underwater, surrounded by colorful bubbles."
16
+ image = pipe(
17
+ prompt, seed=0,
18
+ height=2048, width=2048,
19
+ # The following parameters are fixed.
20
+ num_inference_steps=8, cfg_scale=1, mu=1.15,
21
+ )
22
+ image.save("image.jpg")
examples/krea2/model_inference_low_vram/Krea-2-Raw.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
2
+ import torch
3
+
4
+ vram_config = {
5
+ "offload_dtype": "disk",
6
+ "offload_device": "disk",
7
+ "onload_dtype": torch.float8_e4m3fn,
8
+ "onload_device": "cpu",
9
+ "preparing_dtype": torch.float8_e4m3fn,
10
+ "preparing_device": "cuda",
11
+ "computation_dtype": torch.bfloat16,
12
+ "computation_device": "cuda",
13
+ }
14
+ pipe = Krea2Pipeline.from_pretrained(
15
+ torch_dtype=torch.bfloat16,
16
+ device="cuda",
17
+ model_configs=[
18
+ ModelConfig(model_id="krea/Krea-2-Raw", origin_file_pattern="raw.safetensors", **vram_config),
19
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors", **vram_config),
20
+ ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
21
+ ],
22
+ tokenizer_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
23
+ vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 1,
24
+ )
25
+ prompt = "A cat standing on a stone."
26
+ image = pipe(prompt, seed=0, num_inference_steps=52, cfg_scale=4.5)
27
+ image.save("image.jpg")
examples/krea2/model_inference_low_vram/Krea-2-Turbo.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
2
+ import torch
3
+
4
+ vram_config = {
5
+ "offload_dtype": "disk",
6
+ "offload_device": "disk",
7
+ "onload_dtype": torch.float8_e4m3fn,
8
+ "onload_device": "cpu",
9
+ "preparing_dtype": torch.float8_e4m3fn,
10
+ "preparing_device": "cuda",
11
+ "computation_dtype": torch.bfloat16,
12
+ "computation_device": "cuda",
13
+ }
14
+ pipe = Krea2Pipeline.from_pretrained(
15
+ torch_dtype=torch.bfloat16,
16
+ device="cuda",
17
+ model_configs=[
18
+ ModelConfig(model_id="krea/Krea-2-Turbo", origin_file_pattern="turbo.safetensors", **vram_config),
19
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors", **vram_config),
20
+ ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors", **vram_config),
21
+ ],
22
+ tokenizer_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
23
+ vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 1,
24
+ )
25
+ prompt = "Portrait of a woman in a blue dress, underwater, surrounded by colorful bubbles."
26
+ image = pipe(
27
+ prompt, seed=0,
28
+ height=2048, width=2048,
29
+ # The following parameters are fixed.
30
+ num_inference_steps=8, cfg_scale=1, mu=1.15,
31
+ )
32
+ image.save("image.jpg")
examples/krea2/model_training/full/Krea-2-Raw.sh ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Please run `accelerate config` to configure GPU, DeepSpeed, etc.
2
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "krea2/Krea-2-Raw/*" --local_dir ./data/diffsynth_example_dataset
3
+
4
+ accelerate launch examples/krea2/model_training/train.py \
5
+ --dataset_base_path data/diffsynth_example_dataset/krea2/Krea-2-Raw \
6
+ --dataset_metadata_path data/diffsynth_example_dataset/krea2/Krea-2-Raw/metadata.csv \
7
+ --max_pixels 1048576 \
8
+ --dataset_repeat 50 \
9
+ --model_id_with_origin_paths "krea/Krea-2-Raw:raw.safetensors,Qwen/Qwen3-VL-4B-Instruct:*.safetensors,Qwen/Qwen-Image:vae/diffusion_pytorch_model.safetensors" \
10
+ --tokenizer_path "Qwen/Qwen3-VL-4B-Instruct:" \
11
+ --learning_rate 1e-5 \
12
+ --num_epochs 2 \
13
+ --remove_prefix_in_ckpt "pipe.dit." \
14
+ --output_path "./models/train/Krea-2-Raw_full" \
15
+ --trainable_models "dit" \
16
+ --use_gradient_checkpointing \
17
+ --find_unused_parameters
examples/krea2/model_training/full/Krea-2-Turbo.sh ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Please run `accelerate config` to configure GPU, DeepSpeed, etc.
2
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "krea2/Krea-2-Turbo/*" --local_dir ./data/diffsynth_example_dataset
3
+
4
+ accelerate launch examples/krea2/model_training/train.py \
5
+ --dataset_base_path data/diffsynth_example_dataset/krea2/Krea-2-Turbo \
6
+ --dataset_metadata_path data/diffsynth_example_dataset/krea2/Krea-2-Turbo/metadata.csv \
7
+ --max_pixels 1048576 \
8
+ --dataset_repeat 50 \
9
+ --model_id_with_origin_paths "krea/Krea-2-Turbo:turbo.safetensors,Qwen/Qwen3-VL-4B-Instruct:*.safetensors,Qwen/Qwen-Image:vae/diffusion_pytorch_model.safetensors" \
10
+ --tokenizer_path "Qwen/Qwen3-VL-4B-Instruct:" \
11
+ --learning_rate 1e-5 \
12
+ --num_epochs 2 \
13
+ --remove_prefix_in_ckpt "pipe.dit." \
14
+ --output_path "./models/train/Krea-2-Turbo_full" \
15
+ --trainable_models "dit" \
16
+ --use_gradient_checkpointing \
17
+ --find_unused_parameters
examples/krea2/model_training/lora/Krea-2-Raw.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "krea2/Krea-2-Raw/*" --local_dir ./data/diffsynth_example_dataset
2
+
3
+ accelerate launch examples/krea2/model_training/train.py \
4
+ --dataset_base_path data/diffsynth_example_dataset/krea2/Krea-2-Raw \
5
+ --dataset_metadata_path data/diffsynth_example_dataset/krea2/Krea-2-Raw/metadata.csv \
6
+ --max_pixels 1048576 \
7
+ --dataset_repeat 50 \
8
+ --model_id_with_origin_paths "krea/Krea-2-Raw:raw.safetensors,Qwen/Qwen3-VL-4B-Instruct:*.safetensors,Qwen/Qwen-Image:vae/diffusion_pytorch_model.safetensors" \
9
+ --tokenizer_path "Qwen/Qwen3-VL-4B-Instruct:" \
10
+ --learning_rate 1e-4 \
11
+ --num_epochs 5 \
12
+ --remove_prefix_in_ckpt "pipe.dit." \
13
+ --output_path "./models/train/Krea-2-Raw_lora" \
14
+ --lora_base_model "dit" \
15
+ --lora_target_modules "wq,wk,wv,gate,wo,gate,up,down,first,tmlp.0,tmlp.2,projector,txtmlp.1,txtmlp.3,last.linear,tproj.1" \
16
+ --lora_rank 32 \
17
+ --use_gradient_checkpointing \
18
+ --find_unused_parameters \
19
+ --align_to_opensource_format
examples/krea2/model_training/lora/Krea-2-Turbo.sh ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # We do not recommend training LoRA on Krea-2-Turbo.
2
+
3
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "krea2/Krea-2-Turbo/*" --local_dir ./data/diffsynth_example_dataset
4
+
5
+ accelerate launch examples/krea2/model_training/train.py \
6
+ --dataset_base_path data/diffsynth_example_dataset/krea2/Krea-2-Turbo \
7
+ --dataset_metadata_path data/diffsynth_example_dataset/krea2/Krea-2-Turbo/metadata.csv \
8
+ --max_pixels 1048576 \
9
+ --dataset_repeat 50 \
10
+ --model_id_with_origin_paths "krea/Krea-2-Turbo:turbo.safetensors,Qwen/Qwen3-VL-4B-Instruct:*.safetensors,Qwen/Qwen-Image:vae/diffusion_pytorch_model.safetensors" \
11
+ --tokenizer_path "Qwen/Qwen3-VL-4B-Instruct:" \
12
+ --learning_rate 1e-4 \
13
+ --num_epochs 5 \
14
+ --remove_prefix_in_ckpt "pipe.dit." \
15
+ --output_path "./models/train/Krea-2-Turbo_lora" \
16
+ --lora_base_model "dit" \
17
+ --lora_target_modules "wq,wk,wv,gate,wo,gate,up,down,first,tmlp.0,tmlp.2,projector,txtmlp.1,txtmlp.3,last.linear,tproj.1" \
18
+ --lora_rank 32 \
19
+ --use_gradient_checkpointing \
20
+ --find_unused_parameters \
21
+ --align_to_opensource_format
examples/krea2/model_training/special/split_training/Krea-2-Raw.sh ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "krea2/Krea-2-Raw/*" --local_dir ./data/diffsynth_example_dataset
2
+
3
+ # Stage 1: cache deterministic preprocessing outputs.
4
+ accelerate launch examples/krea2/model_training/train.py \
5
+ --dataset_base_path data/diffsynth_example_dataset/krea2/Krea-2-Raw \
6
+ --dataset_metadata_path data/diffsynth_example_dataset/krea2/Krea-2-Raw/metadata.csv \
7
+ --max_pixels 1048576 \
8
+ --dataset_repeat 1 \
9
+ --model_id_with_origin_paths 'krea/Krea-2-Raw:raw.safetensors,Qwen/Qwen3-VL-4B-Instruct:*.safetensors,Qwen/Qwen-Image:vae/diffusion_pytorch_model.safetensors' \
10
+ --tokenizer_path Qwen/Qwen3-VL-4B-Instruct: \
11
+ --learning_rate 1e-4 \
12
+ --num_epochs 5 \
13
+ --remove_prefix_in_ckpt pipe.dit. \
14
+ --output_path ./models/train/Krea-2-Raw_split_cache \
15
+ --lora_base_model dit \
16
+ --lora_target_modules wq,wk,wv,gate,wo,gate,up,down,first,tmlp.0,tmlp.2,projector,txtmlp.1,txtmlp.3,last.linear,tproj.1 \
17
+ --lora_rank 32 \
18
+ --use_gradient_checkpointing \
19
+ --find_unused_parameters \
20
+ --align_to_opensource_format \
21
+ --offload_models krea/Krea-2-Raw:raw.safetensors \
22
+ --task sft:data_process
23
+
24
+ # Stage 2: train LoRA from the cached dataset.
25
+ accelerate launch examples/krea2/model_training/train.py \
26
+ --dataset_base_path ./models/train/Krea-2-Raw_split_cache \
27
+ --max_pixels 1048576 \
28
+ --dataset_repeat 50 \
29
+ --model_id_with_origin_paths 'krea/Krea-2-Raw:raw.safetensors,Qwen/Qwen3-VL-4B-Instruct:*.safetensors,Qwen/Qwen-Image:vae/diffusion_pytorch_model.safetensors' \
30
+ --tokenizer_path Qwen/Qwen3-VL-4B-Instruct: \
31
+ --learning_rate 1e-4 \
32
+ --num_epochs 5 \
33
+ --remove_prefix_in_ckpt pipe.dit. \
34
+ --output_path ./models/train/Krea-2-Raw_split \
35
+ --lora_base_model dit \
36
+ --lora_target_modules wq,wk,wv,gate,wo,gate,up,down,first,tmlp.0,tmlp.2,projector,txtmlp.1,txtmlp.3,last.linear,tproj.1 \
37
+ --lora_rank 32 \
38
+ --use_gradient_checkpointing \
39
+ --find_unused_parameters \
40
+ --align_to_opensource_format \
41
+ --offload_models 'Qwen/Qwen3-VL-4B-Instruct:*.safetensors,Qwen/Qwen-Image:vae/diffusion_pytorch_model.safetensors' \
42
+ --task sft:train
examples/krea2/model_training/special/split_training/validate.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
2
+ import torch
3
+
4
+
5
+ pipe = Krea2Pipeline.from_pretrained(
6
+ torch_dtype=torch.bfloat16,
7
+ device="cuda",
8
+ model_configs=[
9
+ # For LoRA models trained on Krea-2-Raw, we recommend using them on Krea-2-Turbo.
10
+ ModelConfig(model_id="krea/Krea-2-Raw", origin_file_pattern="raw.safetensors"),
11
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
12
+ ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
13
+ ],
14
+ tokenizer_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
15
+ )
16
+ pipe.load_lora(pipe.dit, './models/train/Krea-2-Raw_split/epoch-4.safetensors')
17
+ prompt = "A dog"
18
+ image = pipe(prompt, seed=0, num_inference_steps=52, cfg_scale=4.5)
19
+ image.save('split_training_Krea-2-Raw.jpg')
examples/krea2/model_training/train.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch, os, argparse, accelerate
2
+ from diffsynth.core import UnifiedDataset
3
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
4
+ from diffsynth.diffusion import *
5
+ from diffsynth.utils.lora.krea2 import Krea2LoRAConverter
6
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
7
+
8
+
9
+ class Krea2ImageTrainingModule(DiffusionTrainingModule):
10
+ def __init__(
11
+ self,
12
+ model_paths=None, model_id_with_origin_paths=None,
13
+ tokenizer_path=None,
14
+ trainable_models=None,
15
+ lora_base_model=None, lora_target_modules="", lora_rank=32, lora_checkpoint=None,
16
+ preset_lora_path=None, preset_lora_model=None,
17
+ use_gradient_checkpointing=True,
18
+ use_gradient_checkpointing_offload=False,
19
+ extra_inputs=None,
20
+ fp8_models=None,
21
+ offload_models=None,
22
+ quant_options=None,
23
+ template_model_id_or_path=None,
24
+ resume_from_checkpoint=None, remove_prefix_in_ckpt=None,
25
+ enable_lora_hot_loading=False,
26
+ device="cpu",
27
+ task="sft",
28
+ ):
29
+ super().__init__()
30
+ model_configs = self.parse_model_configs(model_paths, model_id_with_origin_paths, fp8_models=fp8_models, offload_models=offload_models, quant_options=quant_options, device=device)
31
+ tokenizer_config = self.parse_path_or_model_id(tokenizer_path, default_value=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""))
32
+ self.pipe = Krea2Pipeline.from_pretrained(torch_dtype=torch.bfloat16, device=device, model_configs=model_configs, tokenizer_config=tokenizer_config)
33
+ self.pipe = self.load_training_template_model(self.pipe, template_model_id_or_path, use_gradient_checkpointing, use_gradient_checkpointing_offload)
34
+ self.pipe = self.split_pipeline_units(task, self.pipe, trainable_models, lora_base_model, remove_unnecessary_params=True)
35
+ self.resume_from_checkpoint(resume_from_checkpoint, remove_prefix_in_ckpt)
36
+ if enable_lora_hot_loading: self.pipe.dit = self.pipe.enable_lora_hot_loading(self.pipe.dit)
37
+
38
+ self.switch_pipe_to_training_mode(
39
+ self.pipe, trainable_models,
40
+ lora_base_model, lora_target_modules, lora_rank, lora_checkpoint,
41
+ preset_lora_path, preset_lora_model,
42
+ task=task,
43
+ )
44
+
45
+ self.use_gradient_checkpointing = use_gradient_checkpointing
46
+ self.use_gradient_checkpointing_offload = use_gradient_checkpointing_offload
47
+ self.extra_inputs = extra_inputs.split(",") if extra_inputs is not None else []
48
+ self.fp8_models = fp8_models
49
+ self.task = task
50
+ self.task_to_loss = {
51
+ "sft:data_process": lambda pipe, *args: args,
52
+ "sft": lambda pipe, inputs_shared, inputs_posi, inputs_nega: FlowMatchSFTLoss(pipe, **inputs_shared, **inputs_posi),
53
+ "sft:train": lambda pipe, inputs_shared, inputs_posi, inputs_nega: FlowMatchSFTLoss(pipe, **inputs_shared, **inputs_posi),
54
+ }
55
+
56
+ def get_pipeline_inputs(self, data):
57
+ inputs_posi = {"prompt": data["prompt"]}
58
+ inputs_nega = {"negative_prompt": ""}
59
+ inputs_shared = {
60
+ "input_image": data["image"],
61
+ "height": data["image"].size[1],
62
+ "width": data["image"].size[0],
63
+ "cfg_scale": 1,
64
+ "rand_device": self.pipe.device,
65
+ "use_gradient_checkpointing": self.use_gradient_checkpointing,
66
+ "use_gradient_checkpointing_offload": self.use_gradient_checkpointing_offload,
67
+ }
68
+ inputs_shared = self.parse_extra_inputs(data, self.extra_inputs, inputs_shared)
69
+ return inputs_shared, inputs_posi, inputs_nega
70
+
71
+ def forward(self, data, inputs=None):
72
+ if inputs is None: inputs = self.get_pipeline_inputs(data)
73
+ inputs = self.transfer_data_to_device(inputs, self.pipe.device, self.pipe.torch_dtype)
74
+ for unit in self.pipe.units:
75
+ inputs = self.pipe.unit_runner(unit, self.pipe, *inputs)
76
+ loss = self.task_to_loss[self.task](self.pipe, *inputs)
77
+ return loss
78
+
79
+
80
+ def krea2_parser():
81
+ parser = argparse.ArgumentParser(description="Simple example of a training script.")
82
+ parser = add_general_config(parser)
83
+ parser = add_image_size_config(parser)
84
+ parser.add_argument("--tokenizer_path", type=str, default=None, help="Path to tokenizer.")
85
+ parser.add_argument("--initialize_model_on_cpu", default=False, action="store_true", help="Whether to initialize models on CPU.")
86
+ parser.add_argument("--align_to_opensource_format", default=False, action="store_true", help="Whether to align the lora format to opensource format. Example: https://modelscope.cn/models/krea/Krea-2-LoRA-softwatercolor")
87
+ return parser
88
+
89
+
90
+ if __name__ == "__main__":
91
+ parser = krea2_parser()
92
+ args = parser.parse_args()
93
+ accelerator = accelerate.Accelerator(
94
+ gradient_accumulation_steps=args.gradient_accumulation_steps,
95
+ kwargs_handlers=[accelerate.DistributedDataParallelKwargs(find_unused_parameters=args.find_unused_parameters)],
96
+ )
97
+ dataset = UnifiedDataset(
98
+ base_path=args.dataset_base_path,
99
+ metadata_path=args.dataset_metadata_path,
100
+ repeat=args.dataset_repeat,
101
+ data_file_keys=args.data_file_keys.split(","),
102
+ main_data_operator=UnifiedDataset.default_image_operator(
103
+ base_path=args.dataset_base_path,
104
+ max_pixels=args.max_pixels,
105
+ height=args.height,
106
+ width=args.width,
107
+ height_division_factor=16,
108
+ width_division_factor=16,
109
+ )
110
+ )
111
+ model = Krea2ImageTrainingModule(
112
+ model_paths=args.model_paths,
113
+ model_id_with_origin_paths=args.model_id_with_origin_paths,
114
+ tokenizer_path=args.tokenizer_path,
115
+ trainable_models=args.trainable_models,
116
+ lora_base_model=args.lora_base_model,
117
+ lora_target_modules=args.lora_target_modules,
118
+ lora_rank=args.lora_rank,
119
+ lora_checkpoint=args.lora_checkpoint,
120
+ preset_lora_path=args.preset_lora_path,
121
+ preset_lora_model=args.preset_lora_model,
122
+ use_gradient_checkpointing=args.use_gradient_checkpointing,
123
+ use_gradient_checkpointing_offload=args.use_gradient_checkpointing_offload,
124
+ extra_inputs=args.extra_inputs,
125
+ fp8_models=args.fp8_models,
126
+ offload_models=args.offload_models,
127
+ quant_options=args.quant_options,
128
+ template_model_id_or_path=args.template_model_id_or_path,
129
+ resume_from_checkpoint=args.resume_from_checkpoint,
130
+ remove_prefix_in_ckpt=args.remove_prefix_in_ckpt,
131
+ enable_lora_hot_loading=args.enable_lora_hot_loading,
132
+ task=args.task,
133
+ device="cpu" if (args.initialize_model_on_cpu or args.enable_model_cpu_offload) else accelerator.device,
134
+ )
135
+ model_logger = ModelLogger(
136
+ args.output_path,
137
+ remove_prefix_in_ckpt=args.remove_prefix_in_ckpt,
138
+ state_dict_converter=Krea2LoRAConverter.align_to_opensource_format if args.align_to_opensource_format else lambda x:x,
139
+ enable_tensorboard_log=args.enable_tensorboard_log,
140
+ enable_swanlab_log=args.enable_swanlab_log,
141
+ swanlab_project=args.swanlab_project,
142
+ enable_wandb_log=args.enable_wandb_log,
143
+ wandb_project=args.wandb_project,
144
+ enable_csv_log=args.enable_csv_log,
145
+ )
146
+ launcher_map = {
147
+ "sft:data_process": launch_data_process_task,
148
+ "sft": launch_training_task,
149
+ "sft:train": launch_training_task,
150
+ }
151
+ launcher_map[args.task](accelerator, dataset, model, model_logger, args=args)
examples/krea2/model_training/validate_full/Krea-2-Raw.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
2
+ import torch
3
+ from diffsynth import load_state_dict
4
+
5
+
6
+ pipe = Krea2Pipeline.from_pretrained(
7
+ torch_dtype=torch.bfloat16,
8
+ device="cuda",
9
+ model_configs=[
10
+ ModelConfig(model_id="krea/Krea-2-Raw", origin_file_pattern="raw.safetensors"),
11
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
12
+ ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
13
+ ],
14
+ tokenizer_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
15
+ )
16
+ pipe.dit.load_state_dict(load_state_dict("models/train/Krea-2-Raw_full/epoch-1.safetensors"))
17
+ prompt = "A dog"
18
+ image = pipe(prompt, seed=0, num_inference_steps=52, cfg_scale=4.5)
19
+ image.save("image.jpg")
examples/krea2/model_training/validate_full/Krea-2-Turbo.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
2
+ import torch
3
+ from diffsynth import load_state_dict
4
+
5
+
6
+ pipe = Krea2Pipeline.from_pretrained(
7
+ torch_dtype=torch.bfloat16,
8
+ device="cuda",
9
+ model_configs=[
10
+ ModelConfig(model_id="krea/Krea-2-Turbo", origin_file_pattern="turbo.safetensors"),
11
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
12
+ ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
13
+ ],
14
+ tokenizer_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
15
+ )
16
+ pipe.dit.load_state_dict(load_state_dict("models/train/Krea-2-Turbo_full/epoch-1.safetensors"))
17
+ prompt = "A dog"
18
+ image = pipe(prompt, seed=0, num_inference_steps=52, cfg_scale=4.5)
19
+ image.save("image.jpg")
examples/krea2/model_training/validate_lora/Krea-2-Raw.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
2
+ import torch
3
+
4
+
5
+ pipe = Krea2Pipeline.from_pretrained(
6
+ torch_dtype=torch.bfloat16,
7
+ device="cuda",
8
+ model_configs=[
9
+ # For LoRA models trained on Krea-2-Raw, we recommend using them on Krea-2-Turbo.
10
+ ModelConfig(model_id="krea/Krea-2-Raw", origin_file_pattern="raw.safetensors"),
11
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
12
+ ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
13
+ ],
14
+ tokenizer_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
15
+ )
16
+ pipe.load_lora(pipe.dit, "models/train/Krea-2-Raw_lora/epoch-4.safetensors")
17
+ prompt = "A dog"
18
+ image = pipe(prompt, seed=0, num_inference_steps=52, cfg_scale=4.5)
19
+ image.save("image.jpg")
examples/krea2/model_training/validate_lora/Krea-2-Turbo.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffsynth.pipelines.krea2 import Krea2Pipeline, ModelConfig
2
+ import torch
3
+
4
+
5
+ pipe = Krea2Pipeline.from_pretrained(
6
+ torch_dtype=torch.bfloat16,
7
+ device="cuda",
8
+ model_configs=[
9
+ ModelConfig(model_id="krea/Krea-2-Turbo", origin_file_pattern="turbo.safetensors"),
10
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
11
+ ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
12
+ ],
13
+ tokenizer_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
14
+ )
15
+ pipe.load_lora(pipe.dit, "models/train/Krea-2-Turbo_lora/epoch-4.safetensors")
16
+ prompt = "A dog"
17
+ image = pipe(prompt, seed=0, num_inference_steps=52, cfg_scale=4.5)
18
+ image.save("image.jpg")
examples/lingbot_video/README.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ English Document: https://diffsynth-studio-doc.readthedocs.io/en/latest/Model_Details/LingBot-Video.html
2
+
3
+ 中文文档:https://diffsynth-studio-doc.readthedocs.io/zh-cn/latest/Model_Details/LingBot-Video.html
examples/lingbot_video/model_inference/lingbot-video-dense-1.3b_t2i.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import torch
3
+ from diffsynth.pipelines.lingbot_video import LingBotVideoPipeline, ModelConfig
4
+ from modelscope import dataset_snapshot_download
5
+
6
+ pipe = LingBotVideoPipeline.from_pretrained(
7
+ torch_dtype=torch.bfloat16,
8
+ device="cuda",
9
+ model_configs=[
10
+ ModelConfig(model_id="Robbyant/lingbot-video-dense-1.3b", origin_file_pattern="transformer/diffusion_pytorch_model.safetensors"),
11
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
12
+ ModelConfig(model_id="Robbyant/lingbot-video-dense-1.3b", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
13
+ ],
14
+ processor_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
15
+ )
16
+
17
+ dataset_snapshot_download(
18
+ dataset_id="DiffSynth-Studio/diffsynth_example_dataset",
19
+ local_dir="data/diffsynth_example_dataset",
20
+ allow_file_pattern="lingbot_video/lingbot-video-dense-1.3b_t2i/*",
21
+ )
22
+ with open("data/diffsynth_example_dataset/lingbot_video/lingbot-video-dense-1.3b_t2i/t2i_example.json", "r", encoding="utf-8") as f:
23
+ caption = json.load(f)
24
+
25
+ frames = pipe(
26
+ prompt=caption,
27
+ negative_prompt=pipe.default_negative_prompt_image,
28
+ height=480, width=832, num_frames=1,
29
+ num_inference_steps=40, cfg_scale=3.0,
30
+ seed=0,
31
+ )
32
+ frames[0].save("image_lingbot-video-dense-1.3b_t2i.png")
examples/lingbot_video/model_inference/lingbot-video-dense-1.3b_t2v.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import json
3
+ from diffsynth.utils.data import save_video, VideoData
4
+ from diffsynth.pipelines.lingbot_video import LingBotVideoPipeline, ModelConfig
5
+ from modelscope import dataset_snapshot_download
6
+
7
+ pipe = LingBotVideoPipeline.from_pretrained(
8
+ torch_dtype=torch.bfloat16,
9
+ device="cuda",
10
+ model_configs=[
11
+ ModelConfig(model_id="Robbyant/lingbot-video-dense-1.3b", origin_file_pattern="transformer/diffusion_pytorch_model.safetensors"),
12
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
13
+ ModelConfig(model_id="Robbyant/lingbot-video-dense-1.3b", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
14
+ ],
15
+ processor_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
16
+ )
17
+
18
+ # --- Text-to-video -------------------------------------------------------------------
19
+ dataset_snapshot_download(
20
+ dataset_id="DiffSynth-Studio/diffsynth_example_dataset",
21
+ local_dir="data/diffsynth_example_dataset",
22
+ allow_file_pattern="lingbot_video/lingbot-video-dense-1.3b_t2v/*",
23
+ )
24
+ # LingBot-Video is trained on structured-JSON captions, not free-form prose. This example
25
+ # runs on a released in-distribution caption; see the bottom for turning a brief idea into
26
+ # such a caption with the two-stage prompt rewriter.
27
+ with open("data/diffsynth_example_dataset/lingbot_video/lingbot-video-dense-1.3b_t2v/t2v_example_1.json", "r", encoding="utf-8") as f:
28
+ caption = json.load(f)
29
+
30
+ video = pipe(
31
+ prompt=caption,
32
+ negative_prompt=pipe.default_negative_prompt,
33
+ height=480, width=832, num_frames=81,
34
+ num_inference_steps=40, cfg_scale=3.0,
35
+ seed=0,
36
+ )
37
+ save_video(video, "video_lingbot-video-dense-1.3b_t2v.mp4", fps=15, quality=10)
38
+
39
+ # --- Video-to-video ------------------------------------------------------------------
40
+ # denoising_strength < 1 keeps part of the input structure.
41
+ input_video = VideoData("video_lingbot-video-dense-1.3b_t2v.mp4", height=480, width=832)
42
+ video = pipe(
43
+ prompt=caption,
44
+ negative_prompt=pipe.default_negative_prompt,
45
+ input_video=input_video, denoising_strength=0.7,
46
+ height=480, width=832, num_frames=81,
47
+ num_inference_steps=40, cfg_scale=3.0,
48
+ seed=1,
49
+ )
50
+ save_video(video, "video_lingbot-video-dense-1.3b_v2v.mp4", fps=15, quality=10)
51
+
52
+ # --- Optional: rewrite a brief idea into a structured caption ------------------------
53
+ # The two-stage rewriter (model_training/scripts/prompt_rewriter.py) is a separate VLM +
54
+ # stage-2 LoRA adapter (NOT the DiT) and is not downloaded automatically. Fetch both
55
+ # weights and point the env vars at them:
56
+ # modelscope download --model Qwen/Qwen3.6-27B --local_dir ./models/Qwen/Qwen3.6-27B
57
+ # modelscope download --model Robbyant/lingbot-video-rewriter-lora --local_dir ./models/Robbyant/lingbot-video-rewriter-lora
58
+ # export REWRITER_BASE_MODEL=./models/Qwen/Qwen3.6-27B
59
+ # export REWRITER_ADAPTER=./models/Robbyant/lingbot-video-rewriter-lora
60
+ #
61
+ # from examples.lingbot_video.model_training.scripts.prompt_rewriter import rewrite_prompt
62
+ # caption = rewrite_prompt(
63
+ # "A playful puppy runs across a lush green meadow, chasing a red ball. "
64
+ # "Dynamic side-tracking camera.",
65
+ # mode="t2v", duration=5,
66
+ # )
67
+ # video = pipe(prompt=caption, height=480, width=832, num_frames=81, cfg_scale=3.0, seed=0)
68
+ # save_video(video, "video_lingbot-video-dense-1.3b_rewrite.mp4", fps=15, quality=10)
examples/lingbot_video/model_inference/lingbot-video-dense-1.3b_ti2v.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import torch
4
+ from PIL import Image
5
+ from diffsynth.utils.data import save_video
6
+ from diffsynth.pipelines.lingbot_video import LingBotVideoPipeline, ModelConfig
7
+ from modelscope import dataset_snapshot_download
8
+
9
+ pipe = LingBotVideoPipeline.from_pretrained(
10
+ torch_dtype=torch.bfloat16,
11
+ device="cuda",
12
+ model_configs=[
13
+ ModelConfig(model_id="Robbyant/lingbot-video-dense-1.3b", origin_file_pattern="transformer/diffusion_pytorch_model.safetensors"),
14
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
15
+ ModelConfig(model_id="Robbyant/lingbot-video-dense-1.3b", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
16
+ ],
17
+ processor_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
18
+ )
19
+
20
+ # The condition first frame and its paired caption ship in the example dataset.
21
+ dataset_snapshot_download(
22
+ dataset_id="DiffSynth-Studio/diffsynth_example_dataset",
23
+ local_dir="data/diffsynth_example_dataset",
24
+ allow_file_pattern="lingbot_video/lingbot-video-dense-1.3b_ti2v/*",
25
+ )
26
+ base = "data/diffsynth_example_dataset/lingbot_video/lingbot-video-dense-1.3b_ti2v"
27
+ with open(os.path.join(base, "ti2v_example.json"), "r", encoding="utf-8") as f:
28
+ caption = json.load(f)
29
+ input_image = Image.open(os.path.join(base, "ti2v_first_frame.png")).convert("RGB")
30
+
31
+ video = pipe(
32
+ prompt=caption,
33
+ negative_prompt=pipe.default_negative_prompt,
34
+ input_image=input_image,
35
+ height=480, width=832, num_frames=81,
36
+ num_inference_steps=40, cfg_scale=3.0,
37
+ seed=0,
38
+ )
39
+ save_video(video, "video_lingbot-video-dense-1.3b_ti2v.mp4", fps=15, quality=10)
examples/lingbot_video/model_inference/lingbot-video-moe-30b-a3b_t2i.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import torch
3
+ from diffsynth.pipelines.lingbot_video import LingBotVideoPipeline, ModelConfig
4
+ from modelscope import dataset_snapshot_download
5
+
6
+ pipe = LingBotVideoPipeline.from_pretrained(
7
+ torch_dtype=torch.bfloat16,
8
+ device="cuda",
9
+ model_configs=[
10
+ ModelConfig(model_id="Robbyant/lingbot-video-moe-30b-a3b", origin_file_pattern="transformer/diffusion_pytorch_model*.safetensors"),
11
+ ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern="*.safetensors"),
12
+ ModelConfig(model_id="Robbyant/lingbot-video-moe-30b-a3b", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
13
+ ],
14
+ processor_config=ModelConfig(model_id="Qwen/Qwen3-VL-4B-Instruct", origin_file_pattern=""),
15
+ )
16
+
17
+ dataset_snapshot_download(
18
+ dataset_id="DiffSynth-Studio/diffsynth_example_dataset",
19
+ local_dir="data/diffsynth_example_dataset",
20
+ allow_file_pattern="lingbot_video/lingbot-video-moe-30b-a3b_t2i/*",
21
+ )
22
+ with open("data/diffsynth_example_dataset/lingbot_video/lingbot-video-moe-30b-a3b_t2i/t2i_example.json", "r", encoding="utf-8") as f:
23
+ caption = json.load(f)
24
+
25
+ frames = pipe(
26
+ prompt=caption,
27
+ negative_prompt=pipe.default_negative_prompt_image,
28
+ height=480, width=832, num_frames=1,
29
+ num_inference_steps=40, cfg_scale=3.0,
30
+ seed=0,
31
+ )
32
+ frames[0].save("image_lingbot-video-moe-30b-a3b_t2i.png")