Skip to content

Commit a801e82

Browse files
Merge pull request #64 from VEGA1215/wan2.2-packing-github
[Task] Wan2.2 data packing training support
2 parents 505e4e1 + eaee000 commit a801e82

11 files changed

Lines changed: 1504 additions & 69 deletions

File tree

docs/source/wan_tutorial/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Diffusion Training Tutorial
2+
============================
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
quick_start_wan_training
8+
wan_packing

docs/source/wan_tutorial/quick_start_wan_training.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Each `.pth` file contains the following three keys:
9999
Edit `examples/wan/convert_wan2.2.sh` (section `hg2mcore`):
100100
- `--checkpoint_path` → source HF folder (`high_noise_model` / `low_noise_model`)
101101
- `--save_path` → target Megatron checkpoint folder
102-
- `--tp`, `--pp`, `--num_layers`, `--num_checkpoints` → match your conversion setup
102+
- `--num_layers`, `--num_checkpoints` → match your conversion setup
103103

104104
Run from `examples/wan` because the script invokes conversion utilities with relative paths:
105105
```bash
@@ -137,6 +137,7 @@ CP_RING_DEGREE = CP_SIZE / CP_ULYSSES_DEGREE
137137
- `DATASET_PATH` → output path from Section 1 (e.g. `./data/preprocessed`)
138138
- `--context-parallel-size 4`
139139
- `--context-parallel-ulysses-degree 2`
140+
- Optional packing: add `--packing-sft-data` to enable WAN sample packing, and tune `--packing-buffer-size` for the packing buffer size.
140141

141142
**Step-2** Start
142143
- Single-node:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Wan2.2 Packing Training
2+
3+
Wan2.2 packing concatenates multiple variable-length video samples into one packed training sequence. It keeps per-sample attention and loss boundaries through THD `PackedSeqParams`, so packed samples do not attend to each other and padding tokens do not contribute to loss.
4+
5+
## When to Use
6+
7+
Enable packing when your Wan2.2 training set contains videos or text prompts with noticeably different lengths. Packing reduces wasted computation from padding and is compatible with context parallel training.
8+
9+
Supported context-parallel modes:
10+
- No CP: `CP_SIZE=1`
11+
- Ring CP: `CP_SIZE>1`, `CP_ULYSSES_DEGREE=1`
12+
- Ulysses CP: `CP_SIZE=CP_ULYSSES_DEGREE`
13+
- Hybrid Ring + Ulysses: `CP_SIZE>CP_ULYSSES_DEGREE>1`
14+
15+
## Data Requirements
16+
17+
Use the same preprocessed Wan dataset format as normal training. Each sample should provide:
18+
- `input_latents`: video latent tensor
19+
- `y`: optional image-conditioning latent
20+
- `context`: text embedding
21+
- `seed`: sample seed used for deterministic noise and timestep generation
22+
- `grid_sizes`: optional latent patch grid; when missing, LoongForge derives it from `input_latents`
23+
24+
Packing supports variable-length samples. For CP training, each sample in a packed bin is padded to the per-sample CP split boundary before the bin is concatenated.
25+
26+
## How to Enable
27+
28+
Add the packing flags to the Wan pretrain script:
29+
30+
```bash
31+
--packing-sft-data
32+
--packing-buffer-size 512
33+
```
34+
35+
Example launch:
36+
37+
```bash
38+
cd examples/wan
39+
CUDA_VISIBLE_DEVICES=0,1,2,3 \
40+
CP_SIZE=4 \
41+
CP_ULYSSES_DEGREE=2 \
42+
bash pretrain_wan2.2_i2v_a14b.sh
43+
```
44+
45+
`--packing-buffer-size` controls how many samples are buffered before forming packed bins. Larger buffers can improve packing density but use more host memory.
46+
47+
## Notes and Limitations
48+
49+
- Packing currently uses `micro_batch_size=1`; the validator enforces this when packing is enabled.
50+
- The packed attention path uses THD metadata and may not be bitwise identical to non-packed dense attention, but loss should stay numerically close.
51+
- Keep `seq_length` large enough for one packed bin. In CP mode, LoongForge aligns the effective sequence length to the required CP split boundary.
52+
- For accuracy checks, compare the first several training iterations against a packing-off run with the same data order and do not change `train-iters` between the two runs.

examples/wan/pretrain_wan2.2_i2v_a14b.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ TRAINING_ARGS=(
102102
--no-load-rng
103103
--no-strict-fsdp-dtensor-load
104104
--finetune
105+
# --packing-sft-data
106+
# --packing-buffer-size ${PACKING_BUFFER_SIZE:-512}
105107
${RECOMPUTE_ARGS[@]}
106108
)
107109

0 commit comments

Comments
 (0)