Layerwise Repacking: Variable-Length Hybrid-Attention Training without an Extra Redistribution Pass
Organizations: KlingAI Research Beijing, China
Abstract
Variable-length training creates conflicting parallelism requirements across the layers of a hybrid-attention model. The longest samples require wide sequence-parallel (SP) groups of 16 or 32 ranks for full attention, whose cost grows quadratically with sequence length. Sparse-attention layers, dominated by near-linear MoE work, can instead balance most evaluated workloads within node-local SP8 groups. Reusing the wide groups for these layers pushes their all-to-all communication across nodes, where the observed effective rate is 7.0x lower. Yet switching to smaller groups changes which ranks own each sample; a separate redistribution at every full-sparse boundary would introduce another data transfer. Layerwise Repacking keeps each SP16/32 parent for full attention and repacks its samples into node-local sparse children at SP{1, 2, 4, 8}, where hidden states persist between full layers. The layout change rides on the two existing full-layer Ulysses sites: at each, one variable-size all-to-all performs both the head exchange and the sample repacking, so no redistribution pass is added. Because the balance the children can reach depends on which samples share a parent, an auxiliary parent solver rebalances parent membership before the children are formed. On all 22 steps with SP16/32 parents among the first 200 training steps of a 1F3S hybrid-attention model (one full-attention layer per three sparse-attention layers), repacking alone reduces the mean end-to-end time by 5.95% and raises model FLOPs utilization (MFU) by 3.75 percentage points over the baseline with repacking disabled; with the improved solver, end-to-end time falls by 7.61% and MFU rises by 4.83 percentage points.
Figures & tables
| Stage | Fixed | Optimized output |
| Round-1A baseline | DP world, allowed SP | Seed topology and membership |
| Round-1B improved | All from round-1A | Global parent membership |
| Repair | All | Feasible membership ( ) |
| Round-2 child planner | and | Per-parent child groups |
| Cell | Configuration | Mean E2E (s) | Mean MFU (%) | Fwd max (s) | Bwd max (s) |
| B0 | baseline solver / OFF (original) | 37.221 | 56.47 | 8.864 | 23.316 |
| B1 | baseline solver / ON | 35.007 | 60.22 | 7.437 | 22.302 |
| N0 | improved solver / OFF | 35.887 | 58.52 | 8.241 | 22.766 |
| N1 | improved solver / ON (complete) | 34.390 | 61.30 | 7.218 | 21.900 |
| Metric | Baseline | Improved |
| Conversion payload (GiB) | 74.6 | 70.5 |
| Pass moving attention tensors (s) | 1.89 | 1.78 |
| Pass moving hidden state (s) | 0.94 | 0.89 |
| A2A reduction from repacking (s) | 3.20 | 2.99 |
| Fraction of reduction lost to the pass | 30–59% | 30–60% |
Communication-Efficient Distributed Training
Communication-efficient distributed training reduces the data exchanged among devices so models can be trained faster and over limited-bandwidth networks.
See all 228 papers