Manuscript Offprint
arXiv:2610.35989Layerwise Repacking: Variable-Length Hybrid-Attention Training without an Extra Redistribution Pass
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Kling Infra Team
KlingAI Research
Beijing, China
Dongliang Huang
KlingAI Research
Beijing, China
Jiahao Zhang
KlingAI Research
Beijing, China
Xiaoling Zhou
KlingAI Research
Beijing, China
Junwei Feng
KlingAI Research
Beijing, China
Yiqiao Liao
KlingAI Research
Beijing, China
Chengru Song
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 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.
1 Introduction
Full attention captures long-range dependencies, but its quadratic cost makes it expensive at long sequence lengths. Hybrid-attention models therefore interleave a small number of full-attention layers with cheaper alternatives, retaining periodic global information flow while reducing training cost. Examples include Gemma 2's alternating local and global layers [8], MiniMax-01's one softmax layer after every seven linear-attention layers [22], Jamba's interleaving of attention and Mamba layers [18], and Kimi Linear's three linear-attention layers per full-attention layer [14]. In the 1F3S pattern studied here, every full-attention layer is followed by three sparse-attention layers. As these cheaper layers become more efficient, an increasing fraction of the model no longer needs the degree of parallelism required by full attention.
Variable-length training creates distinct parallelism requirements for full-attention and sparse-attention layers. Here, each full or sparse layer denotes an entire Transformer block, including attention and MoE, classified by its attention type. In the evaluated steps, the longest sample is the length of the shortest (median: ). Because full-attention computation scales quadratically with sequence length and its activations must be distributed, the longest samples require sequence-parallel (SP) groups of 16 or 32 ranks (SP16/32). The sparse layers of the profiled model, by contrast, are dominated by approximately length-linear MoE and other per-token work, so their share of the same samples' work balances within one eight-GPU node (Section 2.1).
Placement systems for variable-length training choose one group per sample or packed micro-batch and use it for every layer [6, 16, 25]. A wide group sized for the longest samples' full attention is then carried through the three sparse layers that follow, moving their Ulysses all-to-all [12] from the intra-node fabric to inter-node links. In our workload, this lowers the observed effective Ulysses rate by relative to node-local SP8 groups, and all-to-all occupies 21.4% of a wide-parent step on wide ranks, against 4.3% on SP8 ranks (Section 2.2).
Assigning node-local groups to sparse layers requires more than changing their sequence-parallel degree. Because the full-and sparse-layer groups place each sample's tokens on different ranks, every transition between the two layer types requires an activation-layout conversion. Implemented as a separate redistribution phase, this conversion adds cross-node activation traffic on top of the full layer's existing exchange. In our workloads, such a
This work was conducted during the authors' internship at KlingAI.
Corresponding authors.
(a) Layer view: the sparse trunk stays in S

hidden states stay in S; sparse-layer A2A stays inside each node
existing full-layer Ulysses A2A = head transpose + sample repacking (no redistribution pass)
(b) Physical view: one SP32 full parent
(c) Planning view: per-parent decision chain


Figure 1: Overview of LAYERWISE REPACKING. (a) Hidden states use the node-local sparse layout S between full-attention layers; transitions to the wide layout F are fused with the existing Ulysses exchanges. (b) An SP32 full-attention parent spans four nodes, while its sparse-layer children remain node-local. (c) Planning assigns samples to parents, optionally rebalances parent membership, and then forms sparse-layer children; dashed arrows indicate fallback paths.
phase would offset approximately 30–60% of the communication savings from node-local sparse-layer execution, depending on the data redistributed (Section 2.3).
Accordingly, we propose LAYERWISE REPACKING to enable layer-specific parallel layouts without adding a dedicated activation-redistribution pass, as shown in Figure 1, where full-attention parents keep SP{8, 16, 32}, while the samples of each SP16/32 parent are repacked into node-local sparse children S with SP{1, 2, 4, 8}. Hidden states persist in S, which we call the sparse trunk, and visit only inside full attention. The key observation is that each full layer's mandatory Ulysses exchange already moves every token across the parent group: generalizing its two call sites to variable split sizes and a deterministic permutation lets the same all-to-all perform the standard sequence/head transpose and the sample repacking between S and , so no redistribution pass or second payload transfer is added.
Child planning can redistribute work only within each parent, so its achievable load balance depends on parent membership. The baseline solver (round 1A) assigns samples to parents using weights calibrated to full-attention compute, as in schedulers for homogeneous Transformer stacks [6, 16, 25]. When full and sparse layers use different parallel groups, these weights do not capture sparse-layer costs and may place several expensive samples in the same parent; child planning cannot redistribute them across parents. We therefore introduce an auxiliary parent solver (round 1B) that rebalances membership using separate full- and sparse-layer cost components while preserving each parent's rank interval. The child planner (round 2) then partitions the revised parents (Section 5).
We evaluate LAYERWISE REPACKING on all 22 training steps with SP16/32 parents among the first 200 steps of a 1F3S hybrid-attention model. By separately enabling repacking and the auxiliary parent solver, we isolate their contributions: repacking alone reduces mean end-to-end time by 5.95%, while the complete system reduces it by 7.61% and increases model FLOPs utilization by 4.83 percentage points, relative to the baseline without repacking. These gains apply to steps that trigger wide parents rather than the full 200-step window. Repacking improves all 20 steps with a single SP16 parent, but slows the two remaining steps, where an extremely long sample limits the load balance achievable within node-local children.
Overall, our main contributions are as follows:
-
We propose LAYERWISE REPACKING, which assigns full- and sparse-attention layers different sequence-parallel layouts and fuses layout conversion into the existing Ulysses exchanges without an additional redistribution pass.
-
We design an auxiliary parent solver that accounts for both full- and sparse-layer costs when assigning samples to parent groups, improving the load balance achievable by node-local children.
-
We evaluate the framework on variable-length 1F3S training workloads, quantify the individual and combined gains
of repacking and parent rebalancing, and identify cases where node-local repacking does not improve performance.
2.1 Sample and Layer Heterogeneity
Two gaps shape the workload: an inter-sample gap between samples of one step and an inter-layer gap between layer types for the same sample. Between samples, the gap is visible directly in the sample lengths: on the 22 wide-parent steps evaluated in Section 6, the longest sample of each step is 9.8–175× (median 23×) as long as the shortest. Because full attention is quadratic in length, the gap in full-layer cost is larger still. Between layers, the gap is set by the design of the cheaper layer: a full-attention query attends to all L tokens of its sample, whereas sparse attention bounds the entries one query attends to, and a linear-attention layer keeps a constant-size state. DeepSeek-V3.2's sparse attention selects 2048 tokens per query, reducing core attention from to ; at a 128K context a query attends to 64× fewer keys [3]. DeepSeek-V4's compressed sparse branch selects 512 or 1024 entries that each compress four tokens, so at a one-million-token context a query covers about 250–500× fewer original positions; its heavily compressed branch attends to all entries compressed 128-fold, which shrinks the quadratic term by 128× but keeps it quadratic, [4].
These figures count attended entries or covered positions, not layer runtime, and omit indexing and sliding-window branches. What this paper relies on is the resulting layer cost: in the profiled model and length range, sparse-layer time is dominated by projections and MoE work, which are near-linear in length in either layer type. Only the attention term separates the two layer types, so the inter-layer gap widens with sample length and is carried by the long samples. Wide groups are therefore sized by a minority of samples for a minority of layers.
2.2 Layerwise Topology Mismatch
Wide SP16/32 groups are a product of the inter-sample gap: the baseline solver allocates them only when a step's sample mix includes samples whose full-attention work calls for wider parallelism, and the same group then also hosts the shorter samples of that step. The inter-layer gap determines what such a group costs in the sparse layers. Full attention benefits from wide SP16/32 because its quadratic attention and activation state are distributed across more ranks. For the longest samples studied here, capping it at SP8 is no alternative: a group's makespan cannot fall below its heaviest sample's cost on eight ranks, and for these samples the quadratic full-attention term makes that cost far exceed the group's average per-rank load, so full attention would run badly imbalanced. Sparse layers are different: for most evaluated workloads, their near-linear MoE-dominated
(a) Exposed A2A time

(b) Effective A2A rate
(c) SP16/32-rank A2A payload by layer type (278 GiB/step)
full layers (est.) 75 GiB (27%)
sparse layers 203 GiB (73%)
Figure 2: Ulysses communication on wide and node-local ranks for the evaluated workloads. Unless noted otherwise, measurements use the baseline solver with repacking disabled. (a) Exposed all-to-all time per rank and step is 7.97 s for SP16/32 ranks and 1.60 s for node-local SP8 ranks. (b) The corresponding effective rates are 39.5 and 275.6 GiB/s. Both measures include full-layer exchanges. (c) Wide-rank payload by layer type; the full-layer share is estimated from the conversion payload measured with repacking enabled.
work already balances within node-local SP8, while moving Ulysses to SP16/32 crosses the node boundary.
We define exposed all-to-all time as the time a rank spends in all-to-all calls, comprising launch time and deferred wait time; the latter includes waiting for slower peers. A rank's effective rate is its all-to-all payload divided by that time; because slower ranks make others wait inside the collective, we take per step the rate of the rank that waited least and average over steps. Measured with the same timer and estimator in the same run, the effective Ulysses rate is 275.6 GiB/s on node-local SP8 ranks and 39.5 GiB/s on cross-node SP16/32 ranks, a 7.0× gap; these are effective runtime path rates rather than hardware link specifications. Widening a sparse block beyond the node therefore divides its computation over more ranks but moves its exchange onto a much slower path. Under the baseline configuration (B0) of the evaluated workloads, wide SP16/32 ranks expose 7.97 s of all-to-all per step versus 1.60 s on node-local SP8 ranks (Figure 2); all-to-all thus occupies 21.4% of the 37.22 s wide-parent step on wide ranks, against 4.3% on SP8 ranks. These totals cover the Ulysses exchanges of all layers. A wide rank transfers 278 GiB per step, of which approximately 75 GiB is attributable to full layers, as estimated from the conversion payload measured with repacking enabled (Section 6.3; Figure 2(c)). The remaining approximately 203 GiB is attributable to sparse layers. This motivates retaining wide SP groups for full attention while moving sparse-layer exchanges to node-local groups, thereby avoiding their cross-node execution.
2.3 Switching Layouts Moves Token Ownership
Node-local groups for the sparse layers are not a change of degree on the same tokens. An SP16 parent spreads its tokens over sixteen ranks in two nodes, whereas an SP8 child holds whole samples inside one node, so moving between the layouts changes which ranks own each sample's tokens. A 1F3S block crosses this boundary twice per full layer, into and out of full attention, in the forward, recomputation, and backward passes. Realized as its own phase, each crossing would move the converted activations across nodes in addition to the full layer's own Ulysses exchange. On measured payloads and rates, such a dedicated pass would cost about 0.9–1.9 s per step depending on whether it moves the hidden state or the attention tensors, roughly 30–60% of the exposed-all-to-all reduction that repacking achieves (Section 6.3). Changing layouts per layer type pays off fully only if it avoids that second transfer.
2.4 Parent Composition Limits Child Balance
Repacking balances work within a parent, so the balance it can reach is limited by which samples share the parent, a decision made in planning. Parent membership is chosen by the baseline solver's scalar weight, an empirical score fitted to full-attention compute profiles. This approach is consistent with dynamic sequence-parallel schedulers for homogeneous Transformer stacks, which assign each sample a profiled cost under a shared parallel layout, as in FlexSP [25] and ByteScale [6]. When layers have similar cost structures and use the same parallel groups, balancing aggregate sample costs provides a basis for balancing group workloads.
A 1F3S hybrid stack under repacking breaks the premise in two ways. First, each sample now carries a two-component compute cost, quadratic full-layer work and near-linear sparse-layer work, and the baseline's weight, calibrated to full attention, misjudges how unequal samples are: a long sample worth many short ones under the quadratic term is worth only a few on the near-linear sparse path. Summing the two components into one per-sample total would fix the totals but not the balance, because the two layer types now run on different groups: full attention is balanced over the parent, whereas a sparse layer finishes with its slowest child. Membership that equalizes a per-sample total can therefore sit far from balance on one layer class's critical path. Second, the empirical weight absorbs no communication cost; the omission is benign while groups stay node-local, but the large samples studied here force cross-node SP16/32 groups, where the un-priced communication share becomes first-order. Repacking removes that cross-node term structurally (Section 3); the two compute components remain for the planner. The resulting mis-composition is visible in both layouts. A wide-parent step also contains ordinary SP8 parents, which serve as a reference: with baseline membership and repacking disabled, the forward rank max of the SP16/32 parent region exceeds that of the ordinary SP8 ranks by 2.418 s. This imbalance motivates reassigning samples among parents while preserving the parent topology, using a cost model that accounts for both full- and sparse-layer computation. Section 6.4 indicates that the imbalance persists, albeit to a lesser extent, when repacking is enabled.
2.5 Why Pure Ulysses rather than USP
Pure Ulysses parallelism (pure UP) transposes sequence shards and attention heads with all-to-all. USP adds a Ring-Attention dimension so ring communication can overlap attention computation [5]. In this workload, sparse attention provides too little computation for effective overlap, and the following MoE work lies outside that overlap window. We therefore build on pure UP as a design choice rather than a measured comparison with USP: it avoids a parallel dimension whose overlap we expect to bring little benefit in this workload, and its mandatory all-to-all can also carry sample repacking (Section 3). Ring-based overlap of the remaining full-layer exchange is orthogonal to repacking and could be combined with it; we leave that combination to future work.
3 LAYERWISE REPACKING Design
LAYERWISE REPACKING separates three decisions that the baseline couples: the wide parent topology required by full attention, the node-local child layout utilized by the sparse trunk, and the sample permutation between those layouts. This section first formalizes the problem and its layer-specific layouts, then describes a communication-fused transition and its correctness requirements.
3.1 Problem Formulation
Consider one training step on a data-parallel world whose ranks form eight-GPU nodes, and let sample i have packed length . The baseline solver (round 1A) partitions the world into contiguous parent buckets
where is a rank interval and is its ordered sample list; every rank in holds an identical assignment record. With this parent topology ( ) held fixed, we choose (i) the membership of every parent and (ii) for each SP16/32 parent a set of children
Here is the rank interval assigned to child j, is its sequence-parallel degree, and is its ordered sample list. The child groups tile , each inside one eight-GPU node, and their non-empty sample lists partition the parent's repaired sample list. The sample assignment evolves through four stages:
Here is the baseline assignment, is the assignment after optional parent reallocation (Section 5), and is the assignment after repair (Section 4); is the resulting child partition. Repair may transfer small samples between parents to ensure that non-empty children can be formed, but no such transfers were needed in the evaluated workloads ( ). Child partitioning alone is restricted to samples within a fixed parent. Parent rank boundaries stay fixed throughout, and a parent that cannot reach samples stays unsplit. Full attention runs on the parents (layout ) and the sparse layers on the children (layout ). The objective is the step's critical-path time, set by the slowest rank's computation and exposed communication, subject to the requirement that moving between the two layouts adds no redistribution pass; per-rank memory is not modeled explicitly and is checked empirically (Section 3.2). Section 4 solves (ii) for a given membership, and Section 5 improves (i) with the topology held fixed.
3.2 Layer-Specific Layout Formulation
The full layout keeps each parent's fixed rank interval with its repaired membership . After the Q/K/V Ulysses exchange, one rank holds the full parent token stream for its corresponding head slice, approximately
Here denotes the rank-local attention tensor in the full layout, with the parent token stream and one rank's share of the attention heads. The sparse layout S uses the rank's shard of one child stream,
Here denotes the rank-local tensor in the sparse layout; the ceiling gives its padded token-shard length. Here and are the packed lengths of the parent and of child , is the head count, and is head width. exists only inside full attention, between its two Ulysses exchanges; the projections and MoE work of a full layer, like all sparse-layer work, run on shards. Padding is local to each child. The correctness contract is that all shards in a parent form a disjoint partition of the parent's real packed tokens, and that the inverse permutation reconstructs the original packing order. For token-proportional state, moving a sample from an parent to an child can increase that sample's per-rank residency by up to relative to : SP32→SP8 is a case, while the most concentrated SP32→SP1 case is . This is a per-sample analytical bound; whole-device peaks are a different metric, which the bound does not predict directly. In the four-configuration runs of Section 6, worst-rank active memory peaks at 71% and reserved memory at 86–90% of per-rank device memory; enabling repacking shifts either peak by at most 0.5% of capacity, and no allocator retry occurs in any configuration (per-step worst over all ranks).
3.3 Communication-Fused Repacking
For a repacked parent, the existing full-layer Q/K/V Ulysses site gathers the node-local S shards into the wide F parent while performing the standard sequence-to-head transpose. The existing output site applies the inverse sample permutation while returning to S. Concretely, write , assume R divides H, and let the children give parent rank q the ordered set of real token positions in the parent packing order. Here index ranks within the parent, , and . At the Q/K/V site, rank q sends to every parent rank p its tokens restricted to head slice p,
so its send splits are tokens to every destination and its receive splits are . The received stream is ordered by source rank, , and the permutation indexes this rank-major stream in ascending parent token order, yielding exactly the head-sharded input that full attention consumes without repacking. The output site inverts the map: rank reorders its attention output by , sends tokens to each rank , and each reassembles all heads for . Q, K, and V each pass through the Q/K/V site, separately for each modality stream. With uniform shards, is the -th contiguous chunk, is the identity, and both sites reduce to standard Ulysses.
Generalizing the split sizes therefore carries repacking inside communication that the full layer already requires. Every tensor still traverses each mandatory exchange once; only split sizes and the local permutation change, so no payload is transferred twice. The absence of an additional pass means that repacking requires no separate inter-rank redistribution; the local permutation still uses buffers, and the full layer retains its mandatory Ulysses exchanges. The performance gain comes from keeping the three sparse layers node-local.
3.4 What the Fused Exchange Must Preserve
Reusing the mandatory exchange is a correctness burden rather than a free generalization; variable split sizes deliver repacking only if four properties hold simultaneously. First, the forward and reverse layout transitions must be exact inverses. The gather must map each child-shard token to its unique position in the parent packing order, and the return must restore the original child-shard assignment. This establishes the disjoint-partition and inverse-permutation requirements of Section 3.2. Second, every rank must derive the permutation independently and identically: repacking metadata cannot itself become a new collective, so all ranks build the same deterministic rank-major index tables from the shared plan. Third, padding and packed-length bookkeeping must stay local to each child so that existing attention and MoE kernels see ordinary packed inputs. Fourth, the backward and recomputation graphs must traverse the same uneven exchanges in reverse with consistent split metadata, and the loss path must reconstruct global packed order without adding a phase. Section 4 realizes these requirements.
4 Runtime Realization
This section realizes the design of Section 3 for a given parent membership, produced by either solver. The runtime first repairs sample counts, plans the children, and constructs deterministic token indices. At each full layer, the existing Ulysses Q/K/V and output exchanges temporarily realize F and return to S.
4.1 Child Planning and Repair
For sample feature vector , a calibrated sparse-work predictor gives the sparse-layer work score
a deterministic score summarizing sparse-attention and near-linear MoE-dominated per-token work. Here contains the profiled features of sample , is the sparse-layer work predictor, and denotes its calibrated parameters. The child planner approximately minimizes, for each repaired parent,
(2)
where each is an interval of ranks aligned to a multiple of within the parent, so every child lies inside one eight-GPU node. It reuses the SP-size allocator of round 1A, run in pure-Ulysses mode inside the parent with the four child sizes as candidate degrees.
Before child planning, the runtime repairs parent memberships to ensure that every rank can be assigned to a non-empty, node-local child group of at most eight ranks. This requires
Here is the minimum number of samples required to form non-empty node-local children for parent b; the constraint applies to its membership after repair. Thus, an SP16 parent needs at least two samples and an SP32 parent at least four. For a deficient parent, it selects the donor with the largest predicted per-rank sparse cost among donors with surplus, then moves that donor's smallest-cost sample. Donors retain their own minimum. Ties follow rank and sample order, so identical inputs produce identical plans.
Repair changes sample membership and total length while preserving parent rank intervals. The child planner then operates on the repaired parent pools. Repair runs only when repacking is enabled, so the repacking-only effect in Section 6 includes it; in the evaluated workloads every wide parent already met its minimum and repair moved no sample.
After repair, child planning follows one of three execution paths:
• Primary. The child planner returns non-empty children and the result is materialized.
• Uniform SP8. An exception or empty-rank result triggers greedy assignment into uniform SP8 bins. This preserves node locality.
• Unsplit. SP8 parents are unchanged by design. An SP16/32 parent also remains unsplit if repair cannot reach samples.
4.2 Sparse-Trunk Execution
The route carries the parent rank start, parent SP, repaired sample order, and child descriptions. At model entry, every rank builds the same rank-major token-index table for each modality. The table serves three roles: it selects the rank's input shard, permutes an S receive stream back into F order, and gathers an F output into destination-major S order. Model inputs are globally replicated at this point, so selecting the initial S shard is a local indexed selection; it is not a network collective. Hidden states, residuals, masks, time conditioning, positional metadata, and attention-residual history remain in S for the complete trunk. Sparse layers receive child-specific packed lengths and run their existing attention stack under the subgroup of size .
Every repacked child has SP≤ 8 and remains inside one eight-GPU node, so no sparse layer runs a parent-wide cross-node attention Ulysses exchange. Sparse layers use the normal Ulysses primitive within the child group when ; an SP1 child needs no attention Ulysses exchange, although other collectives of the training step remain. The near-linear MoE-dominated work is thus approximately balanced over local ranks while its exchange stays on the intra-node fabric.
Let and be the numbers of full and sparse layers. Counting the two pre/post-attention Ulysses sites in the forward graph gives
Here and count cross-node Ulysses call sites per repacked parent's forward pass under the baseline and repacked layouts, respectively. A 1F3S stack has , so for a repacked parent the cross-node Ulysses call sites fall from to , a 75% structural reduction. This count describes the forward graph; backward and recomputation preserve the same layer-type ratio.
4.3 Communication-Fused Execution
For a repacked parent, a full layer performs:
(1) on Q/K/V. Each rank splits heads by parent destination, executes an uneven all-to-all over , and permutes the rank-major receive stream into parent packing order.
(2) Full attention in F. Each rank owns all parent tokens for heads.
(3) on output. The parent stream is gathered in destination order, exchanged with uneven splits, and reshaped to all heads on the local S token shard.
Steps 1 and 3 are the original Ulysses call sites with the split sizes and permutation of Section 3.
After the trunk, an uneven all-gather reconstructs each active modality in global packed order for the loss path. It replaces the baseline uniform all-gather rather than adding a new loss-path phase. Parents with insufficient samples retain their original layout.
5 Improved Parent Solver
The improved solver is an auxiliary planner: it does not change how repacking executes, only the parent membership repacking starts from.
5.1 Why Membership Matters
Within-parent runtime repacking changes how a wide parent executes sparse layers, but not which samples the parent contains. Repair moves only enough samples across parents to make children feasible, and the child planner then partitions each parent independently, so it cannot balance a heavy parent with light samples held by another parent. This imposes a hard lower bound: with the sparse-work score of Equation (1), the best achievable sparse makespan of parent b satisfies
Here denotes the minimum predicted sparse-layer makespan over feasible child partitions of parent . Under this per-sample cost model, the first term is the ideal average over the parent; the second follows from the child-SP cap : even the heaviest sample can use at most eight ranks.
The improved solver (round 1B) targets the first term of this bound. The second depends on membership only through which parent holds each heavy sample: moving a heavy sample lowers its old parent's term, but the step's heaviest sample sets the term in whichever parent receives it, and no membership change removes that bound (Section 7). Before child planning, it keeps each parent topology fixed while reassigning sample membership across parents. We write and for the membership after
Table 1: Planner stages and optimization domains.
| 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 planner | child and | Per-parent child groups |
rounds 1A and 1B. Repacking remains the communication and layout mechanism; round 1B improves the children it can produce.
Table 1 summarizes the planning stages, their fixed constraints, and their outputs. Execution follows Table 1: round 1A fixes the parent topology, optional round 1B changes only parent membership, repair restores feasibility, and round 2 forms the node-local children. Round 1B optimizes sample membership while preserving the parent topology , thereby restricting the search space to sample reassignment. The round-1A assignment is retained as a fixed fallback if no route yields a valid candidate; it is not scored against the generated candidates. The baseline and improved evaluation configurations use the same repair and round-2 implementation; they differ only in whether round 1B runs.
5.2 Parent Reallocation
Round 1B evaluates parent membership with a calibrated modality-aware predictor rather than only the baseline scalar weight; the predictor is fitted to profiled data per modality and per SP degree. For sample and parent degree , the predictor returns a reference work score and an SP-dependent marginal :
Here denotes the calibrated parameters of the parent cost model; and predict reference work and SP-dependent incremental load, respectively. Each greedy bucket starts with
then accumulates . Here is the initial load predicted by for an empty SP- parent. The predictor combines modality, attention, dense, and MoE forward/backward effects into deterministic scores used for allocation ordering and comparison.
After allocation, the evaluator rebuilds each aggregate bucket and scores it with an aggregate critical-path predictor rather than merely trusting the marginal sum:
Here is the fixed set of parents, is a candidate assignment, and predicts its step-level critical-path time . The evaluator is a parent-level surrogate for the slowest-rank symptom, not average work; it does not model repair or child partitioning. It scores the membership before repair and child planning. Repair moved no sample in the evaluated workloads, so the scored and executed memberships coincide there; the executed child plan is still not scored (Section 7).
5.3 Candidate Portfolio and Selection
The solver generates a small portfolio of candidate memberships rather than optimizing one weighted compute–memory objective. Two resource-priority routes, COMPUTE-LPT and MEMORY-LPT, are two priority views of one greedy allocator: they order samples by SP-dependent marginal work or by packed length, pre-place required heavy samples in distinct wide parents, and place each remaining sample where the projected global makespan is smallest, under the baseline per-parent length cap. An optional ANCHOR-FILL route instead shapes each wide parent explicitly for the downstream child planner, combining anchor/filler decomposition [27] with classical large/small-job organization [11]. Every valid candidate is rebuilt from its sample lists and scored by Equation (6); selection takes the tolerance-tied minimum of with a fixed route order as tie break. Here indexes the candidate-generation routes, and is the assignment produced by route . The evaluator thus chooses among routes per workload, and the evaluation reports the complete portfolio as one improved-solver configuration. Appendix A specifies the queue keys, placement rule, budget, selection equation, and pseudocode.
Solver cost. Each route sorts the samples once and places each sample with a constant number of balanced-tree and heap queries per SP class, so one route costs for parents and SP classes, and the evaluator is linear in . The measured solve time is at most 4 ms per step.
6 Experiments
We evaluate the end-to-end performance of repacking alone and the complete system, then analyze communication-time savings and the incremental gains from the improved parent solver.
6.1 Experimental Setup
All runs use 64 GPUs on eight nodes (eight GPUs per node) with bf16 training; Section 2.2 characterizes the interconnect by its measured effective rates. We collected the first 200 training steps of our 1F3S hybrid-attention model; 22 of them contain an SP16 or SP32 parent and therefore trigger repacking. We call each of these steps a workload and run all 22 under four configurations, together with 20 SP8-only steps from the same window as controls. The configurations are labeled by parent solver and repacking state: B0 (baseline solver, repacking OFF; the original system), B1 (baseline solver, ON), N0 (improved solver, OFF), and N1 (improved solver, ON; the complete system). The baseline solver follows the design of Megatron-Core's Dynamic Context Parallelism [16]: it chooses each packed micro-batch's parallel degree from pre-created power-of-two groups that every layer then shares; its groups run pure Ulysses here. The child planner uses SP, while the improved solver preserves the parent SP topology. The set contains 20 one-SP16 workloads, one two-SP16 workload, and one one-SP32 workload, so the evidence chiefly covers one-SP16 parents; the two-SP16 and SP32 topologies are each represented by a single workload. Means are taken over the 22 workloads, and 95% confidence intervals use a workload-level bootstrap. MFU follows the standard definition: theoretical model FLOPs of the non-padding tokens (forward plus backward, excluding recomputation) per device-second, divided by
Table 2: Performance on all 22 SP16/32 workloads. Values average the 22 workloads; B0→N1 is the complete-system comparison. All reported changes are calculated from unrounded means.
| 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 |



Figure 3: Results on the 22 SP16/32 workloads. (a, b) Paired E2E reduction and MFU gain for the two repacking contrasts (B0→B1, N0→N1), the two solver contrasts (B0→N0, B1→N1), and the complete system (B0→N1); bars are means over the 22 workloads and whiskers are workload-level 95% bootstrap confidence intervals. (c) E2E reduction from repacking on each workload, relative to the same solver without repacking.
the device peak FLOPs. Because the four configurations run as separate jobs, the control steps, on which neither lever changes the plan, provide a diagnostic reference for cross-run machine-efficiency differences (after a configuration-blind exclusion of one isolated stall): on identical SP8 plans, the configuration means differ by at most 0.346 s, about one eighth of the 2.83 s headline gain.
We assess numerical consistency by comparing training losses across the four configurations, using the same initial state and training steps. The first step, which precedes any wide parent, has bitwise identical loss across configurations, confirming a common starting state. Measured against B0, the mean absolute loss difference over the wide-parent steps is (B1), (N0), and (N1). On the control steps, where no wide parent exists and neither lever changes execution, it is already : nondeterministic reduction order makes trajectories drift apart through optimizer updates, so later steps are not expected to match bitwise. On the first wide-parent step, where repacking first changes the layout, is , within the range seen on the control steps (up to ). Loss agreement is a necessary check rather than a proof; correctness rests on the bijection and reverse-path requirements of Section 3.4, which the implementation is designed to satisfy, rather than on a separate output- or gradient-equivalence test.
6.2 Overall End-to-End Performance
Table 2 and Figure 3 show the results. Repacking alone lowers E2E by 2.214 s (5.95%) with the baseline solver and 1.497 s (4.17%) with the improved solver; the corresponding MFU gains are 3.75 and 2.78 pp. Figure 3(c) shows that these gains are not driven by the mean alone: median per-workload E2E gains are 2.46 and 1.85 s, and the workload-level 95% confidence intervals exclude zero for both E2E (1.44–2.88 s and 0.76–2.15 s) and MFU (2.55–4.79 pp and 1.61–3.85 pp). Under both solvers, repacking lowers mean E2E on all 20 one-SP16 workloads (by 2.6–11.7% under the baseline solver) and raises it on the two-SP16 and SP32 workloads, where the SP8 child cap leaves one long sample dominating its parent (Section 7).
With the improved solver, the complete system (N1 versus B0) lowers mean E2E from 37.221 to 34.390 s, a 2.831 s (7.61%) reduction with a workload-level 95% confidence interval of 1.86–3.77 s, and raises MFU from 56.47% to 61.30%, a 4.83 pp (3.31–6.27 pp) increase. Forward and backward rank-max time fall by 1.646 and 1.416 s, respectively; the two maxima need not come from the same rank, so they do not add up to the E2E change.
Whole-window arithmetic makes the scope of that headline explicit. Wide parents arise only when a step's sample mix leads the baseline solver to allocate SP16/32 groups, which happens on 22 of the 200 collected steps; the other 178 steps run entirely on SP8 groups, which the two levers leave untouched by construction: repacking splits only SP16/32 parents and the improved solver is disabled on pure-SP8 topologies, so all four configurations execute the same plan on these steps. Estimating each of them by the 28.27 s B0 mean of the SP8-only control steps, wide-parent steps (37.221 s) are the slowest steps in the window and account for about 14% of its estimated wall-clock (22 × 37.221 s out of ≈5851 s). The 7.61% headline is a per-triggered-step figure; the window-level saving is approximately the wall-clock share of triggered steps times the per-step gain, so it varies with how often a workload triggers wide parents. Under a given scheduler and constraints, the share can
(a) Exposed A2A time

(b) A2A payload
Figure 4: Communication on SP16/32 ranks before and after repacking. “Original” is the parent-wide Ulysses path without repacking; “child” and “conversion” are the node-local sparse-layer exchanges and the fused full-layer exchanges. Exposed A2A time falls from 7.97/7.59 s to 4.76/4.60 s under the baseline/improved solvers. Total payload changes by less than 5%, and more than 70% of the repacked payload uses the node-local child path.
increase with the spread of sample lengths, since the further a step’s longest samples outgrow the rest, the more often the baseline solver may need to allocate wide groups.
6.3 Communication Reduction
Figure 4 shows the central mechanism at work: repacking replaces sparse-layer parent-wide A2A with node-local child A2A and uses the mandatory full-layer exchange for conversion, so exposed A2A on wide ranks falls by 3.20/2.99 s while total payload stays nearly unchanged; most traffic is relocated without a second payload traversal.
Time shares and rates show where the remaining communication sits. On wide ranks, all-to-all falls from 21.4% to 13.6% of the step under the baseline solver and from 21.1% to 13.4% under the improved solver. After repacking, the node-local child exchanges carry more than 70% of the wide-rank payload yet take only 14–17% of the remaining all-to-all time, because they stay on the intra-node fabric (Section 2.2). The other 83–86% (4.08/3.82 s) is the mandatory full-layer exchange, which any wide-SP full attention must send across nodes. For repacked parents, the residual communication is therefore the traffic full attention itself requires; the avoidable cross-node sparse-layer traffic is gone.
A dedicated redistribution pass is the natural alternative realization, so Table 3 estimates the pass that fusion avoids. The conversion streams carry 74.6/70.5 GiB per wide rank per step under the baseline/improved solvers. The cost of a separate pass depends on what it moves. A pass that converts the same attention tensors (Q, K, and V on entry, the output on exit) would send that payload across nodes a second time, about 1.89/1.78 s per step at the observed 39.5 GiB/s. A pass that instead moves the hidden state before the Q/K/V projection and after the output projection sends two tensors of the same width as each attention tensor, at the same precision, rather than four, halving the bytes to about 0.94/0.89 s. Either way the pass would return roughly 30–60% of the 3.20/2.99 s exposed-A2A reduction that repacking achieves. Across the other observed

Figure 5: Where the improved solver’s gain lands: rank-max reduction in SP16/32 parent and ordinary-SP8 regions, equally averaging the repacking-OFF and -ON deltas over the same 23 wide parents.
rates—least-blocked conversion rates of 42.9/42.5 GiB/s (per step, the payload/time ratio of the rank that waited least inside its collectives, averaged over steps) and as-deployed wide-path rates of 34.9/34.2 GiB/s—the estimates span 1.7–2.1 s and 0.8–1.1 s for the two designs. Avoiding a separate redistribution pass is therefore a saving, estimated from measured payloads and rates at about 0.4–1.2 times the repacking E2E gain itself (2.214/1.497 s) at 39.5 GiB/s, and not only a structural property of the design.
6.4 Parent-Solver Gains
Parent-composition imbalance predates repacking (Section 2.4). With baseline membership, the parent-region forward rank max exceeds ordinary SP8 by 2.418 s with repacking OFF and 0.696 s with repacking ON; improved membership lowers the same gaps to 1.692 s and 0.452 s. Each value averages the 23 wide parents of the 22 workloads; the two-SP16 workload contributes two. Round 1B thus repairs a planning-level residual that exists in both layouts, rather than a condition repacking creates.
With repacking OFF, B0→N0 lowers E2E by 1.334 s (Figure 3(a)), raises MFU by 2.05 pp, and lowers forward/backward rank max by 0.624/0.550 s. With repacking ON, B1→N1 lowers E2E by 0.617 s, raises MFU by 1.08 pp, and lowers the two rank maxima by 0.219/0.402 s. The E2E confidence intervals are 0.70–2.02 s and 0.02–1.21 s, respectively; the near-zero lower end with repacking ON makes this residual gain less certain than the repacking effect. The gain is also not uniform: in each repacking state, the improved solver does not lower mean E2E on 7 of the 22 workloads, so its benefit is an average over workloads rather than a per-step guarantee.
The two levers overlap rather than add: the solver's E2E gain is larger with repacking OFF (1.334 s) than ON (0.617 s), and the combined B0→N1 improvement of 2.831 s falls 0.717 s short of the sum of the individual effects. Two mechanisms explain the overlap: repacking structurally removes the un-priced cross-node communication share (Section 2.4), and its child planner, which places samples of unequal cost within each parent, absorbs part of the mis-membership, so less residual imbalance remains for the improved solver.
The forward-timing reduction is concentrated where the solver changes membership. Across both repacking states, parent-region forward rank max improves by 0.414 s, against -0.071 s in the ordinary-SP8 region (Figure 5). Backward reduction is similar in the
Table 3: Estimated redistribution overhead avoided by communication fusion, per wide rank and step (forward, recomputation, and backward combined). Conversion payload and A2A time savings are measured. Estimates assume four attention-tensor transfers (Q/K/V in; output out) or two hidden-state transfers (in/out) per full layer and phase at the measured cross-node effective rate of 39.5 GiB/s, excluding additional launch and synchronization overheads. The fraction is estimated overhead divided by measured A2A time savings.
| 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% |
two regions (0.367 and 0.389 s), indicating that the solver's localized effect appears primarily in the forward parent composition.
7 Limitations and Future Directions
This section discusses the performance and applicability limits of LAYERWISE REPACKING, including the SP8 child cap, evaluation scope, and memory and calibration constraints. We then outline potential extensions for benefit-aware repacking, adaptive child-group sizing, and execution-plan evaluation.
The SP8 child cap. The current version caps every child at SP8 so that no sparse-attention Ulysses exchange crosses a node. The cap meets the same single-sample bound that rules out SP8 for full attention (Section 2.2), only far less often because sparse-layer work is near-linear. When a few extremely long samples dominate their parent, it bounds the parent's sparse makespan at the heaviest sample's SP8 cost (the second term of Equation (3)), and the resulting load imbalance can consume the communication saving. This happens on exactly the two-SP16 and SP32 workloads, the only ones on which repacking raises mean E2E (by up to 3.3 s): measured by length, their heaviest sample spread over eight ranks carries 1.47–1.70× its parent's average per-rank load, more than in any improving workload. The current version therefore does not improve the SP32 step.
Scope of the evaluation. All results come from one 1F3S model on one cluster and cover the 22 wide-parent steps among the first 200 collected training steps. The length distribution, and hence how often wide parents arise, may change later in training.
Applicability. The eight-GPU node here is one instance of a more general boundary: the high-bandwidth domain within which all-to-all runs fast. A larger domain postpones the mismatch, but it reappears whenever full attention needs a group wider than the domain. Nor is the mechanism tied to sparse attention: other layers whose work is near-linear in length, such as linear attention, are candidates for node-local children while full attention keeps its wide parent, provided their state, communication, and operator structure permit the same split; we have not validated this.
Memory and calibration. Repacking can raise a sample's per-rank activation residency by up to (Section 3.2); the evaluated steps show little change in whole-device peaks, but steps with larger samples may behave differently. The improved solver relies on a calibrated cost predictor, which must be recalibrated when the model or cluster changes.
Future directions. Three extensions address these limits directly. First, repacking could be gated by predicted gain rather than by feasibility alone. The fallback policy handles plans that cannot be built, but the two regressing workloads were feasible and slower. Keeping the unsplit parent as an explicit candidate, and repacking only when the predicted gain exceeds a margin, would target them; the second term of Equation (3) offers a cheap trigger: measured by length, the heaviest sample's eight-rank load is 1.47–1.70 times its parent's average per-rank load in the regressing workloads, against at most 1.34 in improving ones, although a threshold drawn from these 22 workloads needs validation elsewhere. Second, the child cap could become a choice: for an extremely long sample, the planner would compare an SP8 child, an SP16 child that crosses one node boundary, and keeping the parent, while the remaining samples stay node-local; the objective is the step's critical path rather than node locality of every sparse exchange. Third, the solver could score the executed plan. Its evaluator currently scores membership before repair and child planning; scoring each candidate after repair, child planning, and feasibility checks—including the slowest child's time, full- and sparse-layer communication, permutation and padding overhead, and peak memory—would close the gap between the scored and the executed plan and make memory an explicit constraint.
8 Related Work
8.1 Sequence Parallelism
Sequence parallelism partitions token activations across devices to extend context length and compose with other parallel dimensions [17]. Ulysses realizes the sequence/head transpose with all-to-all [12]; Ring Attention streams blockwise key/value states around a device ring [20]; USP combines the two dimensions [5]; LoongTrain's 2D-Attention likewise combines head- and context-parallel groups and studies their device placement [10]; and DSP switches the sharded sequence dimension across computation stages [30]. DSP is the closest transition mechanism: it also moves tokens with all-to-all between stages, but keeps each sample's participating rank set and the group width fixed, so its splits are uniform. LAYERWISE REPACKING instead changes a sample's participating ranks and group width per layer type, moving it between a wide parent and a node-local child, which requires variable split sizes and an explicit sample permutation inside the same exchange. DCP partitions attention data and computation into blocks mapped to devices per iteration [13], and MagiAttention balances mask-dependent attention work across context-parallel ranks with a dispatch solver [23]; both redistribute attention computation, whereas LAYERWISE REPACKING changes where a sample's persistent sparse-trunk state lives.
8.2 Sparse Attention Parallelism
Sparse Transformer established structured attention sparsity as a route to subquadratic long-sequence modeling [2]. db-SP balances sparse-attention workload at the head and block levels while selecting parallel degrees dynamically for visual-generation inference [1]. Native Sparse Attention combines token compression with blockwise token selection to make sparse attention trainable and hardware aligned [28]; such mechanisms bound or compress each query's attended keys and so shrink the attention term, leaving the sparse layers profiled here dominated by near-linear projection and MoE work. Our training setting instead targets a layer-level mismatch between wide full attention and node-local sparse execution. The sparse layers profiled here are MoE-dominated; expert-parallel systems balance token routing itself through dispatch/combine all-to-all [15], whereas our planner treats per-token expert work as approximately length-linear cost when placing samples and leaves the expert-routing code unchanged.
8.3 Layer-Wise Parallelism Planning
Automatic parallelism systems already choose strategies per layer or per stage: Galvatron selects a hybrid of data, sharded-data, tensor, and pipeline parallelism for each Transformer layer by dynamic programming [21], and Alpa jointly plans inter- and intra-operator parallelism [31]. MoE Parallel Folding decouples the parallel mappings of attention and MoE layers so that each layer type adopts its own configuration [19]. These mappings are fixed for a model and cluster before training. HotSPa varies the strategy within a step, applying different parallelism strategies to different groups of sequences and transferring parameters and gradients when it switches [7]; each sequence group keeps one strategy across all layers. LAYERWISE REPACKING instead changes, in every step, which ranks hold each sample as execution moves between full and sparse layers, driven by that step's sample mix, and makes the change inside the mandatory Ulysses exchange.
8.4 Variable-Length Workload Placement
FlexSP assigns each sequence a sequence-parallel degree by solving a linear program over profiled costs [25]; ByteScale unifies data and context parallelism with a dynamic communication mesh and a balance scheduler [6]; and WLB-LLM balances workload with variable-length document packing and per-document context-parallel sharding [26]; and Megatron-Core's Dynamic Context Parallelism, which our baseline follows, selects a context-parallel size per packed micro-batch [16]. NSP nests SP groups of different sizes on shared GPUs within one iteration, so long sequences use larger groups and short ones smaller groups [24]. In these placement systems one group serves every layer of a sample; Layerwise Repacking instead changes a sample's group between layer types within one step. KnapFormer combines global knapsack assignment with sequence parallelism for mixed-resolution DiT training and redistributes tokens with all-to-all at the two ends of the transformer trunk [29]; its groups then also serve every layer. The per-boundary dedicated pass that Table 3 estimates is our own alternative design, not a measurement of KnapFormer. Zellige organizes mixed image/video placement around heavy anchors and light fillers [27]. The candidate generators of our improved solver draw on greedy list scheduling [9] and large/small-job decomposition [11]; what distinguishes the solver is its two-component cost model and evaluator-based selection across candidates, while the runtime performs the selected repacking through the mandatory Ulysses exchange.
9 Conclusion
Variable-length hybrid-attention training creates distinct parallelism requirements for full and sparse layers, but adopting layer-specific layouts changes token ownership. LAYERWISE REPACKING retains wide parent groups for full attention and repacks samples into node-local children for sparse layers. Fusing layout conversion into the two mandatory full-layer Ulysses exchanges eliminates cross-node sparse-layer Ulysses communication for repacked parents without adding a separate redistribution pass. An auxiliary parent solver reassigns samples across fixed parent groups to improve the load balance achievable by the children.
Across all 22 steps containing SP16/32 parents in the first 200 training steps, repacking alone reduces E2E by 5.95% and 4.17% under the baseline and improved solvers, and the complete system reduces E2E by 7.61% and raises MFU by 4.83 pp over the baseline with repacking disabled. The gains hold on all 20 one-SP16 workloads; on the two-SP16 and SP32 workloads, the SP8 child cap leaves one long sample dominating its parent, and the resulting imbalance erases the gain. Gating repacking by predicted gain, making the child cap a per-sample choice, scoring the executed plan, and evaluating more multi-parent and SP32 steps are the next steps.
Open-Source Software Statement
This work uses the open-source project TorchTitan, released under the BSD 3-Clause License; our training system and the LAYERWISE REPACKING implementation are built on it. We strictly adhered to its license requirements; the original project’s copyright notice and license text can be found in its official repository at https://github.com/pytorch/torchtitan.
References
[1] Siqi Chen, Ke Hong, Tianchen Zhao, Ruiqi Xie, Zhenhua Zhu, Xudong Zhang, and Yu Wang. 2026. db-SP: Accelerating Sparse Attention for Visual Generative Models with Dual-Balanced Sequence Parallelism. In Proceedings of Machine Learning and Systems. https://openreview.net/forum?id=XgKteNxNe0
[2] Rewon Child, Scott Gray, Alec Radford, and Ilya Sutskever. 2019. Generating Long Sequences with Sparse Transformers. arXiv preprint arXiv:1904.10509 (2019). https://arxiv.org/abs/1904.10509
[3] DeepSeek-AI. 2025. DeepSeek-V3.2: Pushing the Frontier of Open Large Language Models. arXiv preprint arXiv:2512.02556 (2025). https://arxiv.org/abs/2512.02556
[4] DeepSeek-AI. 2026. DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence. arXiv preprint arXiv:2606.19348 (2026). https://arxiv.org/abs/2606.19348
[5] Jiarui Fang and Shangchun Zhao. 2024. USP: A Unified Sequence Parallelism Approach for Long Context Generative AI. arXiv preprint arXiv:2405.07719 (2024). https://arxiv.org/abs/2405.07719
[6] Hao Ge, Junda Feng, Qi Huang, Fangcheng Fu, Xiaonan Nie, Lei Zuo, Haibin Lin, Bin Cui, and Xin Liu. 2025. ByteScale: Efficient Scaling of LLM Training with a 2048K Context Length on More Than 12,000 GPUs. arXiv preprint arXiv:2502.21231 (2025). https://arxiv.org/abs/2502.21231
[7] Hao Ge, Fangcheng Fu, Haoyang Li, Xuanyu Wang, Sheng Lin, Yujie Wang, Xiaonan Nie, Hailin Zhang, Xupeng Miao, and Bin Cui. 2024. Enabling Parallelism Hot Switching for Efficient Training of Large Language Models. In Proceedings of the ACM SIGOPS 30th Symposium on Operating Systems Principles (SOSP). 178–194.
[8] Gemma Team. 2024. Gemma 2: Improving Open Language Models at a Practical Size. arXiv preprint arXiv:2408.00118 (2024). https://arxiv.org/abs/2408.00118
[9] Ronald L. Graham. 1969. Bounds on Multiprocessing Timing Anomalies. SIAM J. Appl. Math. 17, 2 (1969), 416–429. doi:10.1137/0117039
[10] Diandian Gu, Peng Sun, Qinghao Hu, Ting Huang, Xun Chen, Yingtong Xiong, Guoteng Wang, Qiaoling Chen, Shangchun Zhao, Jiarui Fang, Yonggang Wen, Tianwei Zhang, Xin Jin, and Xuanzhe Liu. 2024. LoongTrain: Efficient Training of Long-Sequence LLMs with Head-Context Parallelism. arXiv preprint arXiv:2406.18485 (2024). https://arxiv.org/abs/2406.18485
[11] Dorit S. Hochbaum and David B. Shmoys. 1987. Using Dual Approximation Algorithms for Scheduling Problems: Theoretical and Practical Results. J. ACM 34, 1 (Jan. 1987), 144–162. doi:10.1145/7531.7535
[12] Sam Ade Jacobs, Masahiro Tanaka, Chengming Zhang, Minjia Zhang, Shuaiwen Leon Song, Samyam Rajbhandari, and Yuxiong He. 2023. DeepSpeed Ulysses: System Optimizations for Enabling Training of Extreme Long Sequence Transformer Models. arXiv preprint arXiv:2309.14509 (2023). https://arxiv.org/abs/2309.14509
[13] Chenyu Jiang, Zhenkun Cai, Ye Tian, Zhen Jia, Yida Wang, and Chuan Wu. 2025. DCP: Addressing Input Dynamism in Long-Context Training via Dynamic Context Parallelism. In Proceedings of the ACM SIGOPS 31st Symposium on Operating Systems Principles (SOSP). doi:10.1145/3731569.3764849
[14] Kimi Team. 2025. Kimi Linear: An Expressive, Efficient Attention Architecture. arXiv preprint arXiv:2510.26692 (2025). https://arxiv.org/abs/2510.26692
[15] Dmitry Lepikhin, HyoukJoong Lee, Yuanzhong Xu, Dehao Chen, Orhan Firat, Yanping Huang, Maxim Krikun, Noam Shazeer, and Zhifeng Chen. 2021. GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding. In International Conference on Learning Representations. https://openreview.net/forum?id=qrwe7XHTmYb
[16] Kunlun Li, Tailai Ma, Parth Mannan, Sophia Yang, Guohao Wu, and Chenyu Wang. 2026. Speeding Up Variable-Length Training with Dynamic Context Parallelism and NVIDIA Megatron Core. NVIDIA Technical Blog. https://developer.nvidia.com/blog/speeding-up-variable-length-training-with-dynamic-context-parallelism-and-nvidia-megatron-core/
[17] Shenggui Li, Fuzhao Xue, Chaitanya Baranwal, Yongbin Li, and Yang You. 2023. Sequence Parallelism: Long Sequence Training from System Perspective. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers). 2391–2404. doi:10.18653/v1/2023.acl-long.134
[18] Opher Lieber, Barak Lenz, Hofit Bata, Gal Cohen, Jhonathan Osin, Itay Dalmedigos, Erez Safahi, Shaked Meirom, Yonatan Belinkov, Shai Shalev-Shwartz, et al. 2024. Jamba: A Hybrid Transformer-Mamba Language Model. arXiv preprint arXiv:2403.19887 (2024). https://arxiv.org/abs/2403.19887
[19] Dennis Liu, Zijie Yan, Xin Yao, Tong Liu, Vijay Korthikanti, Evan Wu, Shiqing Fan, Gao Deng, Hongxiao Bai, Jianbin Chang, Ashwath Aithal, Michael Andersch, Mohammad Shoeybi, Jiajie Yao, Chandler Zhou, David Wu, Xipeng Li, and June Yang. 2025. MoE Parallel Folding: Heterogeneous Parallelism Mappings for Efficient Large-Scale MoE Model Training with Megatron Core. arXiv preprint arXiv:2504.14960 (2025).
[20] Hao Liu, Matei Zaharia, and Pieter Abbeel. 2024. Ring Attention with Blockwise Transformers for Near-Infinite Context. In International Conference on Learning Representations. https://openreview.net/forum?id=WsRHpHH4s0
[21] Xupeng Miao, Yujie Wang, Youhe Jiang, Chunan Shi, Xiaonan Nie, Hailin Zhang, and Bin Cui. 2022. Galvatron: Efficient Transformer Training over Multiple GPUs Using Automatic Parallelism. Proceedings of the VLDB Endowment 16, 3 (2022), 470–479.
[22] MiniMax. 2025. MiniMax-01: Scaling Foundation Models with Lightning Attention. arXiv preprint arXiv:2501.08313 (2025). https://arxiv.org/abs/2501.08313
[23] Zewei Tao and Yunpeng Huang. 2025. MagiAttention: A Distributed Attention Towards Linear Scalability for Ultra-Long Context, Heterogeneous Mask Training. https://github.com/SandAI-org/MagiAttention.
[24] Yi'ou Wang, Xiaoyang Li, Yijie Zheng, Shouda Liu, and Yuxuan Wang. 2026. NSP: Accelerating Variable-Length LLM Training via Nested Sequence Parallelism. arXiv preprint arXiv:2609.22755 (2026). https://arxiv.org/abs/2609.22755
[25] Yujie Wang, Shiju Wang, Shenhan Zhu, Fangcheng Fu, Xinyi Liu, Xuefeng Xiao, Huixia Li, Jiashi Li, Faming Wu, and Bin Cui. 2025. FlexSP: Accelerating Large Language Model Training via Flexible Sequence Parallelism. In Proceedings of the 30th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 2 (ASPLOS '25). doi:10.1145/3676641.3715998
[26] Zheng Wang, Anna Cai, Xinfeng Xie, Zaifeng Pan, Yue Guan, Weiwei Chu, Jie Wang, Shikai Li, Jianyu Huang, Chris Cai, Yuchen Hao, and Yufei Ding. 2025. WLB-LLM: Workload-Balanced 4D Parallelism for Large Language Model Training. In 19th USENIX Symposium on Operating Systems Design and Implementation (OSDI 25). USENIX Association, Boston, MA, 785–801. https://www.usenix.org/conference/osdi25/presentation/wang-zheng
[27] Guangyu Xiang, Xueze Kang, Minwei Zhao, Yuxin Wang, Shaohuai Shi, Lin Zhang, and Xiaowen Chu. 2026. Zellige: Moldable Sequence Placement for Mixed Image-Video DiT Training. arXiv preprint arXiv:2608.01150 (2026). https://arxiv.org/abs/2608.01150
[28] Jingyang Yuan, Huazuo Gao, Damai Dai, Junyu Luo, Liang Zhao, Zhengyan Zhang, Zhenda Xie, Y. X. Wei, Lean Wang, Zhiping Xiao, et al. 2025. Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention. arXiv preprint arXiv:2502.11089 (2025). https://arxiv.org/abs/2502.11089
Algorithm 1 Resource-Priority Parent Allocation
Require: Samples I, fixed parents B, keep set K, and priority ;
Ensure: Valid parent assignment F, or failure;
1: Initialize and by Equation (5);
Anchor Placement
2: for each in descending order do
3: Restrict candidates to distinct empty SP > 8 parents;
4: Select by Equation (8) under this restriction;
5: if no candidate survives then
6: return failure;
7: end if
8: and update by Equation (4);
9: end for
Priority Allocation
10: Sort by in Equation (7);
11: for each in descending priority order do
12: if remaining samples equal empty parents then
13: Restrict to empty parents;
14: end if
15: Construct and select by Equation (8);
16: if then
17: return failure;
18: end if
19: ;
20: ;
21: end for
Validation and Scoring
22: Verify coverage, non-empty parents, anchors, and length caps;
23: if any invariant fails then
24: return failure;
25: end if
26: Rebuild F and compute by Equation (6);
27: return F
[29] Kai Zhang, Peng Wang, Sai Bi, Jianming Zhang, and Yuanjun Xiong. 2025. KnapFormer: An Online Load Balancer for Efficient Diffusion Transformers Training. arXiv preprint arXiv:2508.06001 (2025). https://arxiv.org/abs/2508.06001
[30] Xuanlei Zhao, Shenggan Cheng, Chang Chen, Zangwei Zheng, Ziming Liu, Zheming Yang, and Yang You. 2025. DSP: Dynamic Sequence Parallelism for Multi-Dimensional Transformers. In Proceedings of the 42nd International Conference on Machine Learning (Proceedings of Machine Learning Research, Vol. 267). 77390–77404. https://proceedings.mlr.press/v267/zhao25g.html
[31] Lianmin Zheng, Zhuohan Li, Hao Zhang, Yonghao Zhuang, Zhifeng Chen, Yanping Huang, Yida Wang, Yuanzhong Xu, Danyang Zhuo, Eric P. Xing, Joseph E. Gonzalez, and Ion Stoica. 2022. Alpha: Automating Inter- and Intra-Operator Parallelism for Distributed Deep Learning. In 16th USENIX Symposium on Operating Systems Design and Implementation (OSDI). 559–578.
A Solver Route Constructions
This appendix specifies the route constructions and the selection rule summarized in Section 5.
Let denote the keep set: heavy samples whose predicted work exceeds a fixed multiple of the mean per-rank work, each of which must anchor a distinct wide parent (the solve falls back to the round-1A membership if exceeds the number of wide parents). holds if assigning sample to parent satisfies the baseline per-parent length cap; Anchor-Fill does not apply it.
Algorithm 2 Anchor-Fill Parent Allocation
Require: Samples I, fixed parents B, and keep set K; Ensure: Valid parent assignment F, or failure; 1: Initialize by Equation (5); disable the length cap; 2: Order ascending by ; 3: for each in descending order do 4: Choose a distinct empty SP > 8 parent by Equation (8); fail if none exists; 5: Assign i and update its parent by Equation (4); 6: end for 7: Let follow anchor order; reserve one sample for each unanchored empty parent; 8: Compute and by Equation (9); 9: for each in anchor-placement order do 10: and ; 11: while and the empty-parent reserve is preserved do 12: Select the cheapest feasible by Equation (9); 13: if exists then 14: Move from U to and update ; 15: else 16: If , swap first() with first() and allow one budget overflow; 17: break 18: end if 19: end while 20: Commit to p, update per filler by Equation (4), and close p; 21: end for 22: Order residual U by and allocate it by Equations (7)–(8); 23: Verify coverage, non-empty parents, and anchors; fail on violation; 24: Rebuild F and compute by Equation (6); 25: return F
is the fixed numerical tolerance used only for deterministic tie handling.
A.1 Resource-Priority Allocation
Both resource-priority routes are longest-processing-time (LPT) style greedy allocators that differ only in their priority key. Let and , taken over the SP classes present in the fixed topology. The descending lexicographic queue keys are
serves as a token-count resource proxy. Each route sorts samples by one key in descending order. Required heavy samples are pre-placed; for every remaining sample, the allocator asks each SP class for its least-loaded feasible parent and chooses among those representatives by projected global makespan. Compute-LPT therefore gives expensive samples first access to scarce wide parents. Memory-LPT gives long samples first access to length-feasible capacity, reducing fragmentation by short samples. The allocation skeleton, feasibility predicates, and deterministic tie breaks are otherwise identical.
For a placement step , let contain only empty SP-R parents when the number of remaining samples equals the number of empty parents, and all SP-R parents otherwise. The route takes the least-loaded length-feasible parent of each SP class as that class's representative and places the sample on the representative that minimizes the projected global makespan:
(8)
Here contains the least-loaded feasible parent from each eligible SP class, and is the selected parent for sample . Near-ties within the tolerance prefer the smaller projected parent load, then the smaller SP class, then a fixed rank order, so identical inputs produce identical assignments.
Algorithm 1 summarizes the shared allocation skeleton for the compute- and memory-priority views.
A.2 Anchor-Fill Allocation
Anchor-Fill starts from the structural decision. It places each threshold-selected keep sample in a distinct eligible large parent; only these anchored parents enter the fill loop, so the number of anchors may be smaller than the number of large parents. It accepts cheap fillers while they fit below a fixed multiple of the global mean predicted work. When the next cheapest filler does not fit, it may replace the cheapest accepted filler once, intentionally allowing the parent to exceed that budget, then closes the parent and sends the remainder through the shared compute-LPT constructor. This creates a qualitatively different candidate: large parents are not merely containers for the most expensive samples; they also absorb flexible work that their full-layer parallelism can carry before round 2 redistributes that parent locally.
For an anchored parent , let be its current predicted work and let be the unassigned pool. Anchor-fill scales the global mean per-rank work by a fixed factor into a parent-sized budget, then chooses the cheapest filler that still fits:
Here is the mean reference work per rank, is parent 's work budget, and is its set of feasible fillers; lex denotes lexicographic selection by .
Unlike Zellige, which places anchors with CP-SAT [27], the route preserves the round-1A parent count, sizes, and rank intervals; uses a greedy heavy assignment and one optional swap; and later allows round 2 to split the resulting parent into sparse children.
Algorithm 2 summarizes the anchor-fill candidate. In Algorithm 2, lists the anchored parents and lists the fillers accepted by parent , both in placement order; is an empty list and first( ) selects its first element.
A.3 Candidate Selection Rule
Let V be the set of enabled routes that return a valid candidate . Final selection uses predicted E2E with a numerical tolerance and the fixed route order Compute-LPT, Memory-LPT, Anchor-Fill:
Here is the minimum predicted time, contains the routes tied within tolerance, and is the selected route. The function assigns priorities 0, 1, and 2 to COMPUTE-LPT, MEMORY-LPT, and ANCHOR-FILL, respectively.