-
Notifications
You must be signed in to change notification settings - Fork 441
Expand file tree
/
Copy pathtest_self_forcing.py
More file actions
199 lines (181 loc) · 5.53 KB
/
Copy pathtest_self_forcing.py
File metadata and controls
199 lines (181 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import os
os.environ.setdefault("MASTER_ADDR", "localhost")
os.environ.setdefault("MASTER_PORT", "29513")
import sys
import subprocess
from pathlib import Path
import torch
import json
from huggingface_hub import snapshot_download
from fastvideo.utils import logger
# Import the training pipeline
sys.path.append(str(Path(__file__).parent.parent.parent.parent.parent))
from fastvideo.fastvideo_args import FastVideoArgs, TrainingArgs
from fastvideo.utils import FlexibleArgumentParser
from fastvideo.utils import FlexibleArgumentParser
from fastvideo.training.runner import main
from fastvideo.utils import build_parser
wandb_name = "test_self_forcing_distill"
NUM_NODES = "1"
NUM_GPUS_PER_NODE = "2"
def run_worker():
"""Worker function that will be run on each GPU"""
# Create and populate args
parser = build_parser()
# Set the arguments based on the distill_dmd_t2v_1.3B.sh script
args = parser.parse_args([
"--pipeline_class", "WanSelfForcingDistillationPipeline",
"--pipeline_module", "fastvideo.training.wan_self_forcing_distillation_pipeline",
"--model_path",
"wlsaidhi/SFWan2.1-T2V-1.3B-Diffusers",
"--inference_mode",
"False",
"--pretrained_model_name_or_path",
"wlsaidhi/SFWan2.1-T2V-1.3B-Diffusers",
"--real_score_model_path",
"Wan-AI/Wan2.1-T2V-1.3B-Diffusers",
"--fake_score_model_path",
"Wan-AI/Wan2.1-T2V-1.3B-Diffusers",
"--data_path",
"data/crush-smol_processed_t2v/combined_parquet_dataset",
"--validation_dataset_file",
"examples/training/finetune/wan_t2v_1.3B/crush_smol/validation.json",
"--train_batch_size",
"1",
"--num_latent_t",
"21",
"--num_gpus",
"2",
"--sp_size",
"1",
"--tp_size",
"1",
"--hsdp_replicate_dim",
"1",
"--hsdp_shard_dim",
"2",
"--train_sp_batch_size",
"1",
"--dataloader_num_workers",
"1",
"--gradient_accumulation_steps",
"1",
"--max_train_steps",
"2",
"--learning_rate",
"1e-5",
"--mixed_precision",
"bf16",
"--training_state_checkpointing_steps",
"30",
"--weight_only_checkpointing_steps",
"30",
"--validation_steps",
"10",
"--validation_sampling_steps",
"3",
"--log_validation",
"--checkpoints_total_limit",
"3",
"--ema_start_step",
"0",
"--training_cfg_rate",
"0.0",
"--output_dir",
"data/wan_self_forcing_test",
"--tracker_project_name",
"wan_self_forcing_ci",
"--wandb_run_name",
wandb_name,
"--num_height",
"480",
"--num_width",
"832",
"--num_frames",
"21",
"--flow_shift",
"5",
"--weight_decay",
"0.01",
"--dit_precision",
"fp32",
"--max_grad_norm",
"1.0",
# DMD args
"--dmd_denoising_steps",
"1000,750,500", # Reduced steps for testing
"--min_timestep_ratio",
"0.02",
"--max_timestep_ratio",
"0.98",
"--dfake_gen_update_ratio",
"5",
"--real_score_guidance_scale",
"3.0",
"--fake_score_learning_rate",
"8e-6",
"--fake_score_betas",
"0.0,0.999",
"--warp_denoising_step",
"--enable_gradient_checkpointing_type",
"full",
# Self-forcing specific args
"--log_visualization",
"--simulate_generator_forward",
"--num_frame_per_block",
"3",
"--enable_gradient_masking",
"--gradient_mask_last_n_frames",
"21",
"--independent_first_frame",
"False",
"--same_step_across_blocks",
"True",
"--last_step_only",
"False",
"--context_noise",
"0",
"--use_ema",
"True",
"--ema_decay",
"0.99",
"--ema_start_step",
"100",
])
# Call the main training function
main(args)
def test_distributed_training():
"""Test the distributed self-forcing training setup"""
os.environ["WANDB_MODE"] = "offline"
data_dir = Path("data/crush-smol_processed_t2v")
if not data_dir.exists():
print(f"Downloading test dataset to {data_dir}...")
snapshot_download(repo_id="wlsaidhi/crush-smol_processed_t2v",
local_dir=str(data_dir),
repo_type="dataset",
local_dir_use_symlinks=False)
# Get the current file path
current_file = Path(__file__).resolve()
# Run torchrun command
cmd = [
"torchrun", "--nnodes", NUM_NODES, "--nproc_per_node", NUM_GPUS_PER_NODE, "--master_port",
os.environ["MASTER_PORT"],
str(current_file)
]
process = subprocess.run(cmd, capture_output=True, text=True)
# Print stdout and stderr for debugging
if process.stdout:
print("STDOUT:", process.stdout)
if process.stderr:
print("STDERR:", process.stderr)
# Check if the process failed
if process.returncode != 0:
print(f"Process failed with return code: {process.returncode}")
raise subprocess.CalledProcessError(process.returncode, cmd, process.stdout, process.stderr)
if __name__ == "__main__":
if os.environ.get("LOCAL_RANK") is not None:
# We're being run by torchrun
run_worker()
else:
# We're being run directly
test_distributed_training()