---
title: Step-Level Sequence Parallelism in Transformers
url: https://www.emergentmind.com/topics/step-level-sequence-parallelism
type: topic
---

# Step-Level Sequence Parallelism in Transformers

Searching arXiv for recent and foundational papers on step-level/sequence parallelism.
Step-level sequence parallelism denotes a family of parallelization techniques that expose concurrency at the granularity of sequence positions, contiguous sequence chunks, or sequential steps of an iterative computation. In contemporary transformer systems, the term most often refers to splitting the sequence-length dimension so that attention and adjacent operators execute over distributed or subdivided token ranges rather than over a fully replicated sequence; in decode-time kernels it can also refer to sequence-level splitting used purely as scheduling logic before any attention math is executed [2105.13120, 2604.00028]. Recent work extends the concept from exact distributed self-attention and compiler-inserted collectives to hierarchy-aware masking for packed hybrid-context data, heterogeneity-adaptive per-step assignment, and chunkwise serving-time scheduling [2604.27089, 2606.30460, 2412.01523, 2511.06247]. In a broader algorithmic lineage, related work studies how “steps” of sequential programs can be re-expressed as parallel frontiers or antichains under explicit dependence constraints [2205.13077, 0810.5575].

## 1. Conceptual scope and relation to other parallelisms

Sequence parallelism, in its canonical transformer form, splits each input sequence of length \(L\) into \(N\) contiguous chunks of length \(L/N\), placing chunk \(i\) on device \(i\). All devices share the same model parameters but only hold their local subsequence. This differs structurally from data parallelism, which splits batch \(B\); tensor parallelism, which splits large weight matrices or head/hidden dimensions; and pipeline parallelism, which splits layer stacks. The distinctive systems property is that sequence parallelism reduces activation and attention costs that scale with \(L\) by a factor of \(N\), while requiring explicit communication to reconstruct full-context attention semantics [2105.13120].

The newer literature broadens that basic definition in three directions. First, compiler systems treat sequence parallelism as a graph rewrite over high-level IR, automatically resizing activations and inserting collectives around attention. Second, topology-aware and hierarchy-aware systems combine multiple sequence-parallel regimes—such as all-to-all and ring communication, or inter-group and intra-group partitioning—to preserve exact causal attention on long and packed inputs. Third, inference systems introduce step-level sequence parallelism at decode time, where the mechanism may be a scheduler-level override that increases the number of launched CTAs by splitting the K/V sequence, even when the numerical attention kernel is otherwise unchanged [2604.27089, 2405.07719, 2606.30460, 2604.00028].

A useful consequence is that the phrase is not confined to a single communication primitive or to one deployment regime. In the cited work it can describe ring self-attention over distributed training shards, all-to-all head/sequence transpositions, JIT-generated NCCL P2P schedules for packed causal masks, dynamic per-step reassignment of sequences to heterogeneous SP groups, or CTA-level sequence splitting in a Hopper decode kernel.

## 2. Exact sequence-dimension partitioning in transformer training

A standard formalization starts from the transformer-layer input
\[
X\in\mathbb R^{B\times L\times H},
\]
with batch \(B\), sequence length \(L\), and hidden size \(H\). Sequence parallelism decomposes
\[
X \rightarrow \{X_0,\dots,X_{N-1}\},\qquad X_i\in\mathbb R^{B\times (L/N)\times H},
\]
so that each device stores only one sequence shard. In “Sequence Parallelism: Long Sequence Training from System Perspective,” each device computes local projections \(Q_i=X_iW^Q\), \(K_i=X_iW^K\), \(V_i=X_iW^V\), and exact self-attention is recovered by Ring Self-Attention (RSA) in two ring phases: one for \(QK^\top\) score construction and one for \(AV\) output accumulation. The ring rotates \(\widetilde K_i^{(r)}\) and \(\widetilde V_i^{(r)}\) across neighboring devices, concatenates partial scores into \(S_i\in\mathbb R^{B\times (L/N)\times L}\), normalizes with softmax, and produces the full output for shard \(i\). The resulting per-device memory is
\[
M_{\rm seq}=O(H^2)+O(BLH/N),
\]
while the quadratic attention term is reduced from \(O(BL^2H)\) to \(O(BL^2H/N)\). On up to 64 NVIDIA P100 GPUs, the paper reports \(13.7\times\) maximum batch size and \(3.0\times\) maximum sequence length relative to tensor parallelism, and with sparse attention it handles over 114K tokens, over \(27\times\) longer than existing sparse-attention work holding the whole sequence on a single device [2105.13120].

AutoSP moves this step-level sequence partitioning into the PyTorch-2.0 compiler. Its SP pass operates on Torch-IR, where layer-level operators are still visible and the sequence axis is not yet obscured by lower-level reshapes and permutes. The pass reads the first input tensor to infer \(b\) and \(s\), scans for an Attention node producing shape \([b,s,h,d]\), resizes pointwise-across-sequence activations from \([b,s,D]\) to \([b,s/WS,D]\), and rewrites attention activations from \([b,s,h,d]\) to \([b,s,h/WS,d]\) after an inserted all-to-all. Before attention it inserts
\[
\texttt{all\_to\_all(input=[b, s/WS, h, d], split\_axis=1, concat\_axis=2)},
\]
so attention sees full sequence length \(s\) but only \(h/WS\) heads per device; after attention it inserts the inverse all-to-all to restore token sharding. AutoSP further modifies PyTorch-2.0’s automated activation-checkpointing by removing infinite-capacity edges on non-attention matmuls, allowing rematerialization when \(s\gg d,h\). In the reported experiments on GH200-96 GB and AMD MI250-64 GB, maximum trainable context increased up to \(2.7\times\) on NVIDIA and \(2.5\times\) on AMD over competitive hand-written baselines, while end-to-end throughput at 40K tokens remained near the hand-written SP baseline: \(1.03\) s versus \(1.06\) s on GH200 and \(1.12\) s versus \(1.15\) s on MI250 [2604.27089].

These systems establish the core invariant of exact sequence-dimension parallelization: each device holds only a shard of tokens for most operators, but attention must still recover full-sequence semantics, either by rotating K/V blocks in a ring or by temporarily exchanging token/head ownership through all-to-all collectives.

## 3. Topology-aware, hierarchical, and hybrid-context extensions

A major systems question is how to preserve the exactness of attention while matching hardware topology and model structure. USP addresses this by treating all-to-all-based Ulysses and P2P-based Ring attention as orthogonal axes of a 2D process mesh of shape \(U\times R=N\). Its `Unified_SP_Attention` first redistributes \(Q\), \(K\), and \(V\) across Ulysses groups with `AllToAll4D`, then runs `LoadBalanceRingAttention` within ring groups, and finally performs the reverse all-to-all to restore the original partition. In this formulation, pure Ulysses and pure Ring are limiting cases. The abstract reports \(47\%\) MFU on two 8xA800 nodes for LLAMA3-8B training at sequence length 208K [2405.07719].

DSP generalizes the sharding decision to multi-dimensional transformers whose attention alternates among multiple sequence dimensions \(d_1,\dots,d_D\). At stage \(s\), the system shards along the dimension \(d_{p(s)}\) used by that stage, and when the desired split dimension changes it performs a single AlltoAll to reshard. The paper’s communication model summarizes DeepSpeed-Ulysses as \(8M/N\) total activation volume per block and DSP as \(2M/N\), i.e. a \(75\%\) reduction relative to the best single-dimension method. The abstract reports throughput improvements ranging from \(32.2\%\) to \(10\times\), with less than \(25\%\) communication volume [2403.10266].

HSAP is aimed at hybrid-context packed sequences, where naive sequence parallelism can violate causal masking by permitting cross-segment attention. Its construction splits \(Q,K,V\in \mathbb R^{N\times H\times d}\) along sequence length into \(P_{\text{inter}}\) inter-group chunks and then partitions heads within each chunk across \(P_{\text{intra}}\) via all-to-all. Exact causality is preserved because attention is computed only within each original packed segment, using JIT-compiled masks that impose lower-triangular structure and zero out any cross-segment positions, for example through `cu_len` cumulative-length arrays. SAP’s JIT hook derives attention-block maps, balances regions, resolves conflicts globally, and emits per-rank instruction lists containing operations such as `create $send-op {kv} %{dst}`, `create $recv-op {kv} %{src}`, `copy-kv comm→comp`, and `computing`. At the HSAP level, inter-group P2P exchanges partial \(K/V\), intra-group all-to-all redistributes heads, and the full output is reconstructed by summing partial \(Y_t\) without duplication. The reported results include scalability to 64 GPUs at 32K sequence-per-GPU, linear continuation to 512K sequence length on 64 GPUs with only \(20\%\) throughput drop, and per-GPU peak activation memory that remains near constant at approximately \(30\) GB on A100 40GB as \(N\rightarrow 512\)K [2606.30460].

Together, these variants show that sequence parallelism is not a monolithic scheme. The implementation space spans 2D meshes, dynamic switching among sequence axes, and hierarchy-aware decomposition designed specifically to preserve causal masks on packed data while keeping communication bounded.

## 4. Adaptive per-step assignment for heterogeneous training and online serving

Static sequence-parallel degrees assume homogeneous sequence lengths. FlexSP targets the long-tail distributions observed in LLM training corpora by solving a per-step assignment problem over heterogeneous SP groups. For a training step with packed sequences \(\{\mathcal S_k\}\) of lengths \(s_k\), \(N\) GPUs, and up to \(P\) candidate SP groups, it introduces a binary group-selection vector \(\mathbf m\), assignment matrix \(A\), and a makespan variable \(C\), then solves the MILP
\[
\min_{\mathbf m,A,C}\; C
\]
subject to runtime, memory, group-budget, and assignment constraints. The profiled runtime is
\[
T_{\rm comp}= \frac1{d_p}\sum_k A_{k,p}(\alpha_1 s_k^2+\alpha_2 s_k)+\beta_1,
\qquad
T_{\rm comm}= \frac1{d_p v_p}\sum_k A_{k,p}\alpha_3 s_k+\beta_2,
\]
with \(\mathrm{Time}=T_{\rm comp}+T_{\rm comm}\), and memory
\[
\sum_k\frac{A_{k,p}s_k}{d_p}M_{\rm token}+M_{\rm ms}.
\]
The system reduces problem size by sequence-length bucketing and, when necessary, memory-balanced micro-batch chunking via dynamic programming, then uses SCIP on the reduced MILP. On the execution side it hot-switches NCCL communicators for the chosen groups and uses flash-attn-2 for variable length. Reported speedups are up to \(1.72\times\) over DeepSpeed and \(1.98\times\) over Megatron-LM, with case studies showing SP=64 for very long sequences, SP=32 or SP=16 for mid-lengths, and SP=8, SP=4, or SP=1 for abundant short sequences; the profiled All-to-All fraction drops from approximately \(40\%\) to approximately \(10\%\) [2412.01523].

Serving systems face a different heterogeneity problem: a single request may require different SP degrees across its own prompt. CDSP addresses this by partitioning a request of total prompt length \(L\) into \(N\) contiguous chunks of lengths \(\ell_i\), assigning chunk \(i\) an SP group \(G_i\) of size \(s_i\), and minimizing the end-to-end prefill time through a fitted latency model
\[
T_{\text{prefill}}(s;C,\ell)=a_s+b_s\ell+c_s(C\ell)+d_s\ell^2.
\]
Its recursive scheduler compares a single-chunk baseline against multi-chunk plans, uses `SolveChunkSize` to determine how many tokens should run before expanding the group size, and extends groups by selecting the least-busy instances on the same node first. The system is integrated into a disaggregated prefill/decoding cluster: prefill GPUs form an SP pool, chunk-level KV-cache is transferred to a decoding GPU through a handshake protocol, and the request is then inserted into a continuous batch chosen by Llumnix-style virtual usage. The abstract reports up to \(4.35\times\) lower TTFT under max sustainable loads, median TBT reduced by up to \(40.1\%\), and max request capacity increased by up to \(45\%\); the detailed ablations report per-request scheduling overhead of \(20\)–\(30\ \mu s\) on average and \(75\ \mu s\) at maximum [2511.06247].

A recurrent systems implication is that “the SP degree” is not necessarily a fixed job-level hyperparameter. In both training and serving, recent systems elevate it to a per-step or per-chunk optimization variable governed by communication cost, memory headroom, and instantaneous resource fragmentation.

## 5. Decode-time kernel scheduling and the sequence-aware split heuristic

In low-head-count autoregressive decoding, step-level sequence parallelism can occur entirely inside kernel-dispatch logic. FlashAttention-3 originally computed
\[
\text{num\_n\_blocks}=\lceil L_K/128\rceil,\qquad \text{total\_mblocks}=\text{batch\_size}\times H_{KV},
\]
and applied a hard guard:
if \(\text{num\_n\_blocks}\le 4\) (equivalently \(L_K\le 512\)), force \(s=1\); otherwise run the usual occupancy-sweep loop. On an H100 with \(132\) SMs, that rule produces a blind spot in low-head MQA/GQA decoding, because a case such as batch \(=1\), \(H_{KV}=1\), \(\text{num\_n\_blocks}=4\) launches only \(4\) CTAs, leaving \(96+\) SMs idle. The sequence-aware split policy changes only the boundary case \((nblk=4, M<4)\), where \(nblk=\lceil L/128\rceil\) and \(M=B\cdot H\). Its decision rule is:
\[
\begin{aligned}
&\text{if } nblk\le 3 && s\leftarrow 1,\\
&\text{else if } (nblk=4)\land(M\ge 4) && s\leftarrow 1,\\
&\text{else if } (nblk=4)\land(M<4) && s\leftarrow 3,\\
&\text{else} && s\leftarrow \text{heuristic\_loop}(nblk,M).
\end{aligned}
\]
The occupancy proxy is
\[
\mathrm{Occupancy}(L,H,s)=\min(N_{SM},M\cdot s).
\]
This logic is evaluated before any attention arithmetic; once \(s\) is fixed, the kernel launches \(M\cdot s\) CTAs, each handling one \((\text{head},\text{batch},\text{subsequence})\) tile and processing \(L_K/s\) tokens [2604.00028].

Raising \(s\) increases CTA count by \(s\times\), improves SM residency, and helps hide memory latency. Each CTA works on a shorter subsequence \(L_K/s\), loading its K/V slice into shared memory or reading it directly from global memory. Because the selected override is small (\(s=3\)), the paper states that reuse remains good and the shared-memory budget is not exceeded. The cost is an additional reduction across CTAs, implemented by atomic adds on global memory or by a small tree reduction via shared memory or warp intrinsics. In the override regime, the paper characterizes that extra cost as small and more than offset by the \(3\times\) increase in CTAs.

For the metadata-enabled path, kernel time was measured under CUDA Graph replay and A/B interleaved timing for batch \(=1\), \(L_K=512\):

| \(H_{KV}\) | \(E_{\text{base}} \rightarrow E_{\text{new}}\) | gain / pct\_gain |
|---|---|---|
| 1 | \(13.72 \rightarrow 11.37\ \mu s\) | \(1.21\times\) / \(21.2\%\) |
| 2 | \(13.52 \rightarrow 10.93\ \mu s\) | \(1.24\times\) / \(23.9\%\) |
| 8 | \(13.56 \rightarrow 13.56\ \mu s\) | \(1.00\times\) / \(0\%\) |

A split sweep over \(s\in[1..64]\) at \((L_K=512,H_{KV}=1)\) shows that latency drops once \(s\ge 3\) into a plateau near \(11.2\)–\(11.5\ \mu s\), with the best point at \(s=64\) around \(11.14\ \mu s\); \(s=3\) was selected because it is the smallest split that captures approximately \(98\%\) of the benefit. Shorter contexts \(L_K\le 384\) are unchanged, heavier workloads \(H_{KV}\ge 4\) or longer \(L_K\) remain on the original split sweep, and a 160-config sweep reported no regression beyond \(-1\%\) [2604.00028].

This decode-time result is notable because it inverts a common intuition: the benefit arises not from a longer context per se, but from under-occupancy at the kernel level when head count is too small to fill Hopper SMs.

## 6. Algorithmic lineage, dependence structures, and recurrent misconceptions

Outside transformer systems, the underlying problem is older: how to expose parallelism among steps that appear sequential. In “Detection of parallel steps in programs with arrays,” a loop is transformed into a separated form whose body is a sequence of controllers \(P_1,\dots,P_{k-1}\) and a final kernel \(P_k\). The controllers compute indices used later; the kernel performs the data update. The paper states that any loop may be algorithmically represented in this form and that the number of controllers is invariant. Immediate data dependence between two instruction instances reduces to solving an integer connection equation
\[
K(i\mid \vec c^{(1)})=K'(j\mid \vec c^{(2)}).
\]
The same work further states that if index expressions are more complex than cubical, dependence detection is algorithmically unsolvable, and specifically that polynomial indices of total degree \(\ge 4\) yield undecidability via Diophantine reduction. Its proposed escape hatch is predecessor semantics, where the right-hand side explicitly names the iteration from which data is read, trivializing dependence detection and enabling parallel execution of antichains such as hyperplanes \(k+i+j=\ell\) in stencil-style updates [0810.5575].

The phase-parallel framework of “Many Sequential Iterative Algorithms Can Be Parallel and (Nearly) Work-efficient” recasts the same issue in DAG terms. Each object \(x\) is assigned a rank \(\mathrm{rank}(x)\), interpreted as the earliest phase in which it can be processed. All objects of one rank form a frontier
\[
T=\{x\in S:\mathrm{rank}(x)=i\},
\]
which can be processed in parallel. The paper distinguishes work-efficiency from round-efficiency, proposes Type 1 algorithms that extract each frontier by range queries and Type 2 algorithms that wake an object when its last predecessor completes, and gives detailed instantiations for activity selection, unlimited knapsack, LIS, and greedy MIS. For LIS, the Type 2 random-pivot method achieves \(O(n\log^3 n)\) work and \(O(r\log^2 n)\) span; implementations in C++/Cilk Plus on a 96-core machine show 10’s–100× speedups when dependence depth is reasonable [2205.13077].

This broader lineage suggests that step-level sequence parallelism is best understood as a dependence-management pattern rather than as a single transformer kernel trick. A recurring misconception is that it always means one static scattering strategy applied uniformly to all sequences. Recent work instead includes per-stage dimension switching, per-step MILP assignment across heterogeneous SP groups, and intra-request chunk-level SP expansion in serving [2403.10266, 2412.01523, 2511.06247]. Another misconception is that exact causality is incompatible with aggressive sequence partitioning on packed data; HSAP explicitly constructs JIT-compiled masks and communication schedules so that only original segments attend to themselves and all partial outputs are summed without duplication [2606.30460].

A plausible implication is that future systems will continue to collapse distinctions between compile-time graph rewriting, runtime communicator selection, and kernel-dispatch occupancy control. In the current literature, the same conceptual objective—extract more useful parallel work from a sequence-ordered computation—already appears at every layer of the stack, from dependence equations and frontier schedules to NCCL plans, process meshes, and Hopper CTA grids.

Source: https://www.emergentmind.com/topics/step-level-sequence-parallelism