|
| 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. |
0 commit comments