Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/wan2.2/predict_s2v.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@

if lora_path is not None:
pipeline = unmerge_lora(pipeline, lora_path, lora_weight, device=device, dtype=weight_dtype)
pipeline = unmerge_lora(pipeline, lora_high_path, lora_high_weight, device=device, dtype=weight_dtype, sub_transformer_name="transformer_2")
if transformer_2 is not None:
pipeline = unmerge_lora(pipeline, lora_high_path, lora_high_weight, device=device, dtype=weight_dtype, sub_transformer_name="transformer_2")

def save_results():
if not os.path.exists(save_path):
Expand Down
4 changes: 2 additions & 2 deletions scripts/cogvideox_fun/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,9 +1229,9 @@ def collate_fn(examples):
ema_transformer3d.to(accelerator.device)

# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device, dtype=weight_dtype)
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device)
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
4 changes: 2 additions & 2 deletions scripts/cogvideox_fun/train_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,9 +1164,9 @@ def collate_fn(examples):
ema_transformer3d.to(accelerator.device)

# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device, dtype=weight_dtype)
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device)
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
4 changes: 2 additions & 2 deletions scripts/cogvideox_fun/train_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,10 +1164,10 @@ def collate_fn(examples):
)

# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device, dtype=weight_dtype)
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
transformer3d.to(accelerator.device, dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device)
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
2 changes: 1 addition & 1 deletion scripts/fantasytalking/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ def _create_special_list(length):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
clip_image_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
audio_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=torch.float32)

Expand Down
4 changes: 2 additions & 2 deletions scripts/flux/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,8 +1348,8 @@ def _create_special_list(length):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder_2.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
text_encoder_2.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
6 changes: 3 additions & 3 deletions scripts/flux/train_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,11 +1280,11 @@ def _create_special_list(length):
# text_encoder_2 = shard_fn(text_encoder_2)

# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device, dtype=weight_dtype)
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
transformer3d.to(accelerator.device, dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device)
text_encoder_2.to(accelerator.device)
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
text_encoder_2.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
2 changes: 1 addition & 1 deletion scripts/qwenimage/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ def _create_special_list(length):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
2 changes: 1 addition & 1 deletion scripts/qwenimage/train_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ def _create_special_list(length):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
4 changes: 2 additions & 2 deletions scripts/qwenimage/train_edit_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,10 +1209,10 @@ def _create_special_list(length):
text_encoder = shard_fn(text_encoder)

# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device, dtype=weight_dtype)
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
transformer3d.to(accelerator.device, dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device)
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
4 changes: 2 additions & 2 deletions scripts/qwenimage/train_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,10 +1157,10 @@ def _create_special_list(length):
text_encoder = shard_fn(text_encoder)

# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device, dtype=weight_dtype)
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
transformer3d.to(accelerator.device, dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device)
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
2 changes: 1 addition & 1 deletion scripts/wan2.1/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ def collate_fn(examples):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if args.train_mode != "normal":
clip_image_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

Expand Down
6 changes: 3 additions & 3 deletions scripts/wan2.1/train_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,12 +1337,12 @@ def collate_fn(examples):
text_encoder = shard_fn(text_encoder)

# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device, dtype=weight_dtype)
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
transformer3d.to(accelerator.device, dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device)
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if args.train_mode != "normal":
clip_image_encoder.to(accelerator.device, dtype=weight_dtype)
clip_image_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
2 changes: 1 addition & 1 deletion scripts/wan2.1_fun/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ def _create_special_list(length):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if args.train_mode != "normal":
clip_image_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

Expand Down
2 changes: 1 addition & 1 deletion scripts/wan2.1_fun/train_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ def _create_special_list(length):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
clip_image_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
Expand Down
6 changes: 3 additions & 3 deletions scripts/wan2.1_fun/train_control_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,11 +1350,11 @@ def _create_special_list(length):
text_encoder = shard_fn(text_encoder)

# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device, dtype=weight_dtype)
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
transformer3d.to(accelerator.device, dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device)
clip_image_encoder.to(accelerator.device, dtype=weight_dtype)
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
clip_image_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
6 changes: 3 additions & 3 deletions scripts/wan2.1_fun/train_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,12 +1338,12 @@ def _create_special_list(length):
text_encoder = shard_fn(text_encoder)

# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device, dtype=weight_dtype)
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
transformer3d.to(accelerator.device, dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device)
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if args.train_mode != "normal":
clip_image_encoder.to(accelerator.device, dtype=weight_dtype)
clip_image_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
2 changes: 1 addition & 1 deletion scripts/wan2.1_fun/train_reward_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ def save_model_hook(models, weights, output_dir):
vae.to(accelerator.device, dtype=weight_dtype)
transformer3d.to(accelerator.device, dtype=weight_dtype)
text_encoder.to(accelerator.device)
clip_image_encoder.to(accelerator.device, dtype=weight_dtype)
clip_image_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(prompt_list) / args.gradient_accumulation_steps)
Expand Down
2 changes: 1 addition & 1 deletion scripts/wan2.1_vace/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ def _create_special_list(length):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
2 changes: 1 addition & 1 deletion scripts/wan2.2/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ def collate_fn(examples):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
Expand Down
34 changes: 1 addition & 33 deletions scripts/wan2.2/train_animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,38 +679,6 @@ def parse_args():
'The initial gradient is relative to the multiple of the max_grad_norm. '
),
)
parser.add_argument(
"--train_mode",
type=str,
default="control",
help=(
'The format of training data. Support `"control"`'
' (default), `"control_ref"`, `"control_camera_ref"`.'
),
)
parser.add_argument(
"--control_ref_image",
type=str,
default="first_frame",
help=(
'The format of training data. Support `"first_frame"`'
' (default), `"random"`.'
),
)
parser.add_argument(
"--add_full_ref_image_in_self_attention",
action="store_true",
help=(
'Whether enable add full ref image in self attention.'
),
)
parser.add_argument(
"--add_inpaint_info",
action="store_true",
help=(
'Whether enable add inpaint info in self attention.'
),
)
parser.add_argument(
"--weighting_scheme",
type=str,
Expand Down Expand Up @@ -1464,7 +1432,7 @@ def _create_special_list(length):
# Move text_encode and vae to gpu and cast to weight_dtype
vae.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
if not args.enable_text_encoder_in_dataloader:
text_encoder.to(accelerator.device if not args.low_vram else "cpu")
text_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)
clip_image_encoder.to(accelerator.device if not args.low_vram else "cpu", dtype=weight_dtype)

# We need to recalculate our total training steps as the size of the training dataloader may have changed.
Expand Down
5 changes: 2 additions & 3 deletions scripts/wan2.2/train_animate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ accelerate launch --mixed_precision="bf16" scripts/wan2.2/train_animate.py \
--pretrained_model_name_or_path=$MODEL_NAME \
--train_data_dir=$DATASET_NAME \
--train_data_meta=$DATASET_META_NAME \
--image_sample_size=1024 \
--video_sample_size=256 \
--token_sample_size=512 \
--video_sample_size=640 \
--token_sample_size=640 \
--video_sample_stride=2 \
--video_sample_n_frames=81 \
--train_batch_size=1 \
Expand Down
Loading