Papers
Topics
Authors
Recent
Search
2000 character limit reached

AutoSP: Compiler-Driven Long-Context Optimization

Updated 5 July 2026
  • AutoSP is a compiler-based system that optimizes long-context transformer training by automating sequence parallelism within PyTorch.
  • It implements two compiler passes—automated sequence parallelism and modified activation checkpointing—to significantly reduce activation memory and extend trainable sequence lengths.
  • The system integrates seamlessly into the PyTorch 2.x compiler pipeline, eliminating manual distributed code while maintaining near baseline performance with minimal runtime overhead.

AutoSP is a compiler-based, PyTorch-native system for automatically optimizing transformer-style LLM training for long contexts. Its design target is the regime in which sequence length, rather than parameter count alone, becomes the dominant systems bottleneck: activation memory grows rapidly with context length, existing training stacks largely optimize for model-size scaling through ZeRO-3/FSDP, tensor parallelism, and pipeline parallelism, and practical deployment of sequence parallelism ordinarily requires invasive hand-written distributed code. AutoSP addresses that mismatch by compiling standard PyTorch models and applying two passes—automated sequence parallelism and long-context-aware activation checkpointing—within the PyTorch 2.x compiler pipeline, with reported gains of up to 2.7×2.7\times longer trainable contexts on NVIDIA hardware and 2.5×2.5\times on AMD hardware over competitive hand-written baselines at negligible cost to runtime performance (Gupta et al., 29 Apr 2026).

1. Long-context training as a compiler problem

The motivating premise of AutoSP is that mainstream distributed training methods primarily optimize for large parameter counts rather than long input sequences. ZeRO-3 / FSDP reduce per-device memory for parameters, gradients, and optimizer state; tensor parallelism shards computation within layers; pipeline parallelism shards layers across devices. In long-context LLM training, however, memory pressure is dominated by sequence-dependent activations, especially around attention, so these methods do not directly solve the core bottleneck. Sequence parallelism is the natural remedy because it shards tensors along the sequence dimension and aggregates device memory across token ranges, but practical implementations such as DeepSpeed-Ulysses and RingAttention typically require manual insertion of all_to_all, explicit tracking of sequence-sharded versus head-sharded layouts, careful buffer resizing, manual recomputation of indexed tensors such as masks, and explicit forward/backward correctness engineering. AutoSP reframes that work as a compiler transformation rather than a hand-coded distributed systems exercise (Gupta et al., 29 Apr 2026).

This design is as much about usability as about memory efficiency. The system is presented as the first automated solution to automatically optimize LLM training for longer contexts, and its central claim is that long-context support should be exposed through compiler abstractions rather than through framework-specific eager-mode rewrites. A plausible implication is that AutoSP belongs to the same broader trend as compiler-driven FSDP automation, but it targets a different systems axis: sequence length rather than model size.

2. Compiler placement and execution pipeline

AutoSP is integrated into the PyTorch 2.0 compiler stack. The end-to-end pipeline is: standard PyTorch model input; TorchDynamo trace capture into Torch-IR; an AutoSP sequence-parallel pass on Torch-IR; AOTAutograd lowering to Aten-IR; an activation-checkpointing pass on Aten-IR with AutoSP’s sequence-aware modification; TorchInductor lowering and code generation; and distributed runtime execution on GPU clusters (Gupta et al., 29 Apr 2026).

The split between IR levels is deliberate. The sequence-parallel transformation is implemented on Torch-IR because that representation still exposes high-level structure such as linear and attention, making it feasible to identify transformer layer boundaries and apply legality-sensitive rewrites. Aten-IR is already lowered into fine-grained matmuls, reshapes, permutes, and layout changes, so recovering the sequence dimension and rewriting both forward and backward graphs there would be substantially harder. Activation checkpointing, by contrast, is implemented on Aten-IR because AutoSP modifies PyTorch’s existing min-cut-based rematerialization machinery rather than replacing it.

The usage model follows from this compiler placement. A user writes ordinary PyTorch model code, registers the AutoSP passes, initializes distributed training with a chosen sequence-parallel group size, compiles the model, and trains. The transformed graph then implements sequence-parallel multi-GPU execution without requiring the model author to manually manage communication placement, tensor layout transitions, or sharding-aware indexing.

3. Automated sequence parallelism

AutoSP implements a DeepSpeed-Ulysses-style sequence-parallel scheme. If the sequence length is ss and the sequence-parallel world size is WSWS, each device initially owns

part_seq=sWS.\text{part\_seq} = \frac{s}{WS}.

Outside attention regions, operators that are pointwise or local in the sequence dimension, such as linear projections and MLP layers, execute on sequence-sharded tensors whose local shape is represented as [b,s/WS,d][b, s/WS, d]. Within attention regions, AutoSP inserts an all_to_all before the first attention operator so that tensors become head-sharded with shape [b,s,h/WS,d][b, s, h/WS, d], allowing each device to operate on the full sequence but only a subset of heads. After the last attention operator, a second all_to_all restores sequence sharding with shape [b,s/WS,h,d][b, s/WS, h, d] (Gupta et al., 29 Apr 2026).

Correctness is preserved through three coordinated rewrites. First, the compiler inserts communication collectives at attention boundaries. Second, it resizes intermediate buffers according to whether the current region is sequence-sharded or head-sharded. Third, it recomputes manual indexing for tensors such as causal masks whose indexing semantics change under sharding. The transformation is driven by graph analysis over Torch-IR and manually curated operator classes such as ATTN_OPS, RESIZE_BUFS, and INDEX_OPS, derived from Dynamo FX graphs of compiled hand-written transformer implementations. The compiler also infers batch size, sequence length, and model dimension by inspecting graph inputs and attention outputs, because those quantities are not always explicit in IR.

The resulting automation is not model-universal. It targets transformer computation graphs whose structure matches recognizable Torch-IR patterns, including Llama-family models with Grouped-Query Attention and full attention. This suggests that AutoSP is best understood as an automatic transformer-specific sequence-parallelizer rather than a general auto-sharder.

4. Long-context-aware activation checkpointing

The second major component is a sequence-parallel-aware activation-checkpointing pass. PyTorch 2.0 already provides an automated activation-checkpointing mechanism based on a min-cut formulation over the joint forward-backward graph, but that implementation is conservative: many compute-heavy operators, especially matmuls and scaled matmuls, are effectively protected from rematerialization by infinite-capacity source edges. AutoSP argues that this policy is mismatched to the long-context regime. When sequence length becomes very large, attention’s s2s^2-scaling dominates runtime so strongly that recomputing projection and MLP matmuls becomes comparatively inexpensive, while storing their activations remains costly (Gupta et al., 29 Apr 2026).

AutoSP therefore mutates the joint graph before invoking the standard PyTorch activation-checkpointing optimizer. Specifically, it removes those conservative source-to-node infinite-capacity edges for compute-heavy operators outside the attention layer, allowing them to be rematerialized. The method does not introduce a new objective function; it changes the admissible rematerialization set within PyTorch’s existing optimizer. In effect, AutoSP treats long-context rematerialization as a compiler policy problem rather than a user-authored checkpoint-placement problem.

The paper’s breakdown analysis illustrates the tradeoff. On a Llama-3.2 1B model at sequence length 40k on GH200-96GB, attention activation memory is reduced by 13.03×13.03\times and MLP activation memory by 2.5×2.5\times0, while the backward pass incurs about a 2.5×2.5\times1 slowdown and forward time remains similar (Gupta et al., 29 Apr 2026). This supports the paper’s core analytical point: in sufficiently long contexts, selective recomputation of non-attention operators can deliver large memory savings at modest throughput cost.

5. Empirical performance and ablations

The evaluation covers Llama-3.2 1B and 3B, Llama-3.1 8B, and Llama-2 13B on NVIDIA GH200-96GB, NVIDIA A100-80GB, and AMD MI250-64GB systems, against ZeRO-3 (FSDP) + torch.compile, hand-written DeepSpeed-Ulysses, and hand-written RingAttention / RingFlashAttention baselines (Gupta et al., 29 Apr 2026).

The strongest quantitative result is increased trainability. On 8 A100-80GB GPUs, AutoSP enables up to 2.5×2.5\times2 longer sequences for the 3B model, 2.5×2.5\times3 for 8B, and 2.5×2.5\times4 for 13B relative to ZeRO-3. Against hand-written DeepSpeed-Ulysses, the gains are up to 2.5×2.5\times5, 2.5×2.5\times6, and 2.5×2.5\times7 for 3B, 8B, and 13B respectively; against RingAttention, they are up to 2.5×2.5\times8, 2.5×2.5\times9, and ss0. On 2 GH200-96GB GPUs, AutoSP enables ss1 longer sequence lengths for 1B and ss2 for 3B. On 2 MI250-64GB GPUs, it enables ss3 longer sequences for 1B and ss4 for 3B (Gupta et al., 29 Apr 2026).

Runtime remains close to hand-written sequence-parallel baselines. Averaged over 100 iterations on sequence lengths all methods can handle, AutoSP achieves about ss5 and ss6 the speed of DeepSpeed-Ulysses for 1B and 3B on NVIDIA, and about ss7 and ss8 on AMD. Relative to ZeRO-3 + torch.compile, AutoSP reduces per-iteration time by ss9 while increasing trainability by about an order of magnitude in the reported 8B setting (Gupta et al., 29 Apr 2026).

A concise ablation isolates the two compiler passes:

Configuration Max tokens Speed
DS-Ulysses 81,000 1.06 s
AutoSP SP-pass only 77,000 1.09 s
AutoSP SP + AC-pass 128,000 1.19 s

This ablation shows that the compiler-generated sequence-parallel pass alone reaches about 97% of hand-written Ulysses performance, while the major context-length increase comes from adding the long-context-aware activation-checkpointing pass: an incremental WSWS0 trainability gain over SP-only for about 7% extra runtime slowdown (Gupta et al., 29 Apr 2026).

6. Scope, limitations, and naming

AutoSP is explicitly targeted at transformer-like LLM training and, in the reported implementation, specifically at a Ulysses-style sequence-parallel regime. It is not presented as a universal automatic parallelization planner. Its rewrites depend on manually curated operator sets such as ATTN_OPS, RESIZE_BUFS, and INDEX_OPS, which implies that unusual graph structures, unsupported custom attention kernels, or non-transformer architectures may require extending those patterns. The system also does not expose a global cost-based search across sequence, tensor, pipeline, and parameter sharding strategies; it implements a fixed sequence-parallel transformation plus a specialized activation-checkpointing policy. The memory benefit is largest when activation storage dominates. For larger models such as Llama-2 13B, the paper notes that optimizer state becomes about 50% of memory, reducing the relative impact of activation savings (Gupta et al., 29 Apr 2026).

The paper also implies several open directions: more general compiler support for long-context parallelism beyond Ulysses, broader model coverage, richer automatic selection among sequence, tensor, pipeline, and parameter sharding, better integration of activation checkpointing with distributed graph transformations, and elimination of manual operator curation. These directions suggest that AutoSP is best viewed as an initial compiler framework for long-context optimization rather than a complete automatic distributed-training synthesizer.

A common source of confusion is the name itself. In the literature represented here, “AutoSP” refers to this long-context LLM training system; it should not be conflated with unrelated systems such as AutoSpec for IFU spectral extraction (Griffiths et al., 2018), ASP for automatic selection of proxy datasets in AutoML (Yao et al., 2023), or AutoSiMP for autonomous topology optimization from natural language (Yang et al., 27 Mar 2026). Within its own scope, however, AutoSP’s significance lies in making sequence parallelism and long-context-aware rematerialization first-class compiler transformations rather than specialized hand-written implementations (Gupta et al., 29 Apr 2026).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to AutoSP.