Skip to content

Commit 7a8c837

Browse files
lightx2v_train big refactor (#1325)
1 parent a34806c commit 7a8c837

338 files changed

Lines changed: 12012 additions & 32683 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lightx2v_train/cache_data.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import argparse
2+
3+
import torch
4+
from loguru import logger
5+
6+
from lightx2v_train.data import build_data, build_sample_processor
7+
from lightx2v_train.model_zoo import build_model
8+
from lightx2v_train.runtime import (
9+
cleanup_distributed,
10+
init_distributed,
11+
load_config,
12+
setup_logger,
13+
)
14+
from lightx2v_train.trainers import build_trainer
15+
16+
17+
def parse_args():
18+
parser = argparse.ArgumentParser(description="Build a training dataset cache with LightX2V.")
19+
parser.add_argument("--config", required=True, help="Path to a YAML config file.")
20+
parser.add_argument("--output_dir", required=True, help="Directory for cache_data.jsonl and cached tensors.")
21+
parser.add_argument("--save_dtype", choices=("bf16", "fp16", "fp32"), default="bf16")
22+
parser.add_argument("--seed", type=int, default=0)
23+
parser.add_argument("--overwrite", action="store_true")
24+
return parser.parse_args()
25+
26+
27+
def main():
28+
args = parse_args()
29+
config = load_config(args.config)
30+
config["training_cache"] = {
31+
"output_dir": args.output_dir,
32+
"save_dtype": args.save_dtype,
33+
"seed": args.seed,
34+
"overwrite": args.overwrite,
35+
}
36+
config["data"]["train"]["preserve_records"] = True
37+
38+
torch.backends.cuda.matmul.allow_tf32 = True
39+
torch.backends.cudnn.allow_tf32 = True
40+
init_distributed(config)
41+
setup_logger(config)
42+
43+
try:
44+
sample_processor = build_sample_processor(config)
45+
dataloader = build_data(config, train_or_val="train", sample_processor=sample_processor)
46+
47+
model = build_model(config)
48+
model.load_components(
49+
load_transformer=False,
50+
load_vae=True,
51+
load_condition_encoder=True,
52+
)
53+
54+
trainer = build_trainer(config)
55+
trainer.set_model(model)
56+
trainer.set_data(dataloader)
57+
trainer.train()
58+
except Exception:
59+
logger.exception("Training cache build failed")
60+
raise
61+
finally:
62+
cleanup_distributed()
63+
64+
65+
if __name__ == "__main__":
66+
main()

lightx2v_train/configs/infer/lingbot_video_t2v_dmd_lora.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ data:
3434
name: prompt_dataset
3535
data_path: /data/nvme5/gushiqiao/datatets/lingbot_video/vidprom_filtered_extended_first5k_auto_negative.jsonl
3636
max_samples: 5
37-
batch_size: 1
3837
num_workers: 0
3938
pin_memory: true
4039
shuffle: false
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
model:
2+
name: longcat_image_edit
3+
pretrained_model_name_or_path: /path/to/LongCat-Image-Edit
4+
attention_backend: _native_flash
5+
running_dtype: bf16
6+
7+
data:
8+
processor:
9+
target_area: 1048576 # 1024 * 1024
10+
val:
11+
name: image_dataset
12+
num_workers: 4
13+
shuffle: false
14+
data_path:
15+
- /path/to/LightX2V_train_data_examples/dataset_edit/val.jsonl
16+
17+
scheduler:
18+
num_train_timesteps: 1000
19+
timestep_distribution: logitnormal
20+
logitnormal_mean: 0.0
21+
logitnormal_std: 1.0
22+
min_t: 0.001
23+
max_t: 1.0
24+
time_shift_settings:
25+
do_time_shift: true
26+
shift_type: exponential
27+
time_shift_power: 1.0
28+
dynamic_shift: true
29+
patch_size: [2, 2]
30+
shift_x1: 256
31+
shift_x2: 4096
32+
shift_y1: 0.5
33+
shift_y2: 1.15
34+
35+
inference:
36+
method: image_infer
37+
negative_prompt: ""
38+
default_width: 1024
39+
default_height: 1024
40+
num_inference_steps: 50
41+
enable_cfg: true
42+
cfg_guidance_scale: 4.5
43+
seed: 42
44+
output_dir: ./output_infer/longcat_image_edit_lora
45+
lora_config:
46+
path: /path/to/pytorch_lora_weights.safetensors
47+
48+
logging:
49+
rank_zero_only: true
50+
infer_log_every_steps: 10

lightx2v_train/configs/infer/wan.yaml

Lines changed: 0 additions & 75 deletions
This file was deleted.

lightx2v_train/configs/infer/wan2_1_t2v_14b_tf_chunkwise_ar.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ data:
3737
data_path:
3838
- /path/to/prompts/wan_t2v_prompts.txt
3939
max_samples: 1
40-
batch_size: 1
4140
num_workers: 0
4241
shuffle: false
4342

lightx2v_train/configs/infer/wan2_1_t2v_1_3b_tf_chunkwise_ar.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ data:
3737
data_path:
3838
- /path/to/wan_t2v_prompts.txt
3939
max_samples: 1
40-
batch_size: 1
4140
num_workers: 0
4241
shuffle: false
4342

lightx2v_train/configs/infer/wan2_2_ti2v_5b_tf_ar.yaml

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)