|
| 1 | +# Preparing OpenVid-1M Dataset for Wan Fine-tuning |
| 2 | + |
| 3 | +This guide walks through downloading a subset of the [OpenVid-1M](https://huggingface.co/datasets/nkp37/OpenVid-1M) dataset, preprocessing it, and converting it into the Energon WebDataset format for Wan training. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- `wget`, `unzip` available on your system |
| 8 | +- A Hugging Face account with access token (`HF_TOKEN`) |
| 9 | +- Python environment with Megatron-Bridge installed |
| 10 | + |
| 11 | +## Step 1: Download a Small Portion of OpenVid-1M |
| 12 | + |
| 13 | +```bash |
| 14 | +PROCESSED_DATA_PATH=<path/to/dataset_dir> |
| 15 | +cd ${PROCESSED_DATA_PATH} |
| 16 | + |
| 17 | +export HF_TOKEN=<HF_API_KEY> |
| 18 | +wget https://huggingface.co/datasets/nkp37/OpenVid-1M/resolve/main/OpenVidHD/OpenVidHD_part_1.zip |
| 19 | +wget https://huggingface.co/datasets/nkp37/OpenVid-1M/resolve/main/data/train/OpenVidHD.csv |
| 20 | +``` |
| 21 | + |
| 22 | +## Step 2: Extract a Subset of Videos |
| 23 | + |
| 24 | +Extract 200 videos as an example (adjust the number as needed): |
| 25 | + |
| 26 | +```bash |
| 27 | +unzip -Z1 OpenVidHD_part_1.zip | head -n 200 | xargs -I {} unzip OpenVidHD_part_1.zip "{}" -d OpenVidHD_part_1 |
| 28 | +``` |
| 29 | + |
| 30 | +## Step 3: Create Per-Video Caption JSON Files |
| 31 | + |
| 32 | +The preprocessing script reads the CSV caption file and creates a sidecar `.json` file next to each `.mp4`: |
| 33 | + |
| 34 | +```bash |
| 35 | +cd ${MBRIDGE_PATH} |
| 36 | +python examples/diffusion/recipes/wan/prepare_dataset/openvid1M_preprocess.py \ |
| 37 | + --csv_path ${PROCESSED_DATA_PATH}/OpenVidHD.csv \ |
| 38 | + --video_dir ${PROCESSED_DATA_PATH}/OpenVidHD_part_1 |
| 39 | +``` |
| 40 | + |
| 41 | +Each video will have a corresponding `.json` file with `video` and `caption` fields. |
| 42 | + |
| 43 | +## Step 4: Convert to Energon WebDataset Format |
| 44 | + |
| 45 | +Run the dataset preparation script using `torchrun` with 8 GPUs: |
| 46 | + |
| 47 | +```bash |
| 48 | +DATASET_SRC=${PROCESSED_DATA_PATH}/OpenVidHD_part_1 |
| 49 | +DATASET_PATH=${PROCESSED_DATA_PATH}/prepared_dataset_wds |
| 50 | + |
| 51 | +torchrun --nproc_per_node=8 \ |
| 52 | + examples/diffusion/recipes/wan/prepare_dataset/prepare_dataset_wan.py \ |
| 53 | + --video_folder "${DATASET_SRC}" \ |
| 54 | + --output_dir "${DATASET_PATH}" \ |
| 55 | + --output_format energon \ |
| 56 | + --model "Wan-AI/Wan2.1-T2V-1.3B-Diffusers" \ |
| 57 | + --mode video \ |
| 58 | + --height 480 \ |
| 59 | + --width 832 \ |
| 60 | + --resize_mode bilinear \ |
| 61 | + --center-crop |
| 62 | +``` |
| 63 | + |
| 64 | +The output directory `${DATASET_PATH}` can then be passed directly as `dataset.path` when launching Wan training. |
| 65 | + |
| 66 | +## Step 5: Launch Wan Fine-tuning |
| 67 | + |
| 68 | +Set the required environment variables and run the training script: |
| 69 | + |
| 70 | +```bash |
| 71 | +DATASET_PATH=${PROCESSED_DATA_PATH}/prepared_dataset_wds |
| 72 | +CHECKPOINT_DIR=<path/to/save/checkpoints> |
| 73 | +INIT_CHECKPOINT_DIR=<path/to/pretrained/wan/checkpoint> |
| 74 | +EXP_NAME=<experiment_name> |
| 75 | + |
| 76 | +NVTE_FUSED_ATTN=1 torchrun --nproc_per_node=8 scripts/training/run_recipe.py \ |
| 77 | + --recipe wan_1_3B_pretrain_config \ |
| 78 | + --step_func wan_step \ |
| 79 | + model.tensor_model_parallel_size=1 \ |
| 80 | + model.pipeline_model_parallel_size=1 \ |
| 81 | + model.context_parallel_size=4 \ |
| 82 | + model.sequence_parallel=false \ |
| 83 | + model.qkv_format=thd \ |
| 84 | + model.bias_activation_fusion=false \ |
| 85 | + dataset.path=${DATASET_PATH} \ |
| 86 | + dataset.packing_buffer_size=200 \ |
| 87 | + dataset.num_workers=10 \ |
| 88 | + checkpoint.save=${CHECKPOINT_DIR} \ |
| 89 | + checkpoint.load=${INIT_CHECKPOINT_DIR} \ |
| 90 | + checkpoint.load_optim=false \ |
| 91 | + checkpoint.save_interval=200 \ |
| 92 | + optimizer.lr=5e-5 \ |
| 93 | + optimizer.min_lr=5e-5 \ |
| 94 | + train.eval_iters=0 \ |
| 95 | + scheduler.lr_decay_style=constant \ |
| 96 | + scheduler.lr_warmup_iters=1000 \ |
| 97 | + model.seq_length=40000 \ |
| 98 | + dataset.seq_length=40000 \ |
| 99 | + train.global_batch_size=8 \ |
| 100 | + train.micro_batch_size=1 \ |
| 101 | + dataset.global_batch_size=8 \ |
| 102 | + dataset.micro_batch_size=1 \ |
| 103 | + logger.log_interval=1 \ |
| 104 | + logger.wandb_project="wan" \ |
| 105 | + logger.wandb_exp_name=${EXP_NAME} \ |
| 106 | + logger.wandb_save_dir=${CHECKPOINT_DIR} |
| 107 | +``` |
| 108 | + |
| 109 | +> **Note:** With a small dataset (e.g. 200 videos), set `dataset.num_workers=1` to avoid an |
| 110 | +> `IndexError` in the Energon sharder caused by too few samples in the val split shard. |
0 commit comments