Editor’s introduction
Piper is a distributed training system designed for PyTorch that decouples strategy specification from execution. Users define training strategies using model annotations and scheduling directives, which transform a unified global training DAG—representing all computation and communication. This intermediate representation enables the system to generate per-device execution plans independently of the strategy. The study shows Piper maintains performance parity with established methods like ZeRO while enabling efficiency gains through joint scheduling of compute and communication in advanced strategies such as DeepSeek-V3’s DualPipe. The evidence focuses on performance and flexibility in composed parallelism strategies, including data, pipeline, and expert parallelism.
Introduction
As machine learning (ML) models have increased in size, pretraining now requires scaling across hundreds to thousands of accelerators. This is challenging because there are many ways to shard and replicate the model, and each introduces different and possibly interacting communication overheads. For example, modern workloads now use combinations of data (DP), tensor (TP), expert (EP), context (CP) and pipeline (PP) parallelism together with memory-saving optimizations such as ZeRO. There is no one-size fits-all solution, as the right strategy depends on the workload and hardware.
A workload’s distributed training strategy can be decomposed into: (1) the high-level parallelism strategy, such as the dimensions along which to shard and replicate the model and activations, and (2) each device’s low-level strategy for executing the compute and communication operations dictated by the high-level parallelism strategy. The former strategy determines the minimum memory, compute, and communication load per-device, which in turn upper-bounds the overall system throughput. The latter strategy determines how close the system can get to the upper bound by effectively scheduling each device’s resources. The two strategies together determine the workload’s actual throughput.
The sheer size of the combined space of strategies has so far made full automation intractable. Thus, while some solutions can find an optimal strategy within a particular subspace, the systems deployed in practice still rely overwhelmingly on human experts. For example, DeepSeek-V3 introduced DualPipe, a custom PP schedule that when composed with EP enables each device to use local micro-batch overlapping to hide EP communication overheads. This solution required human-engineered codesign of the high-level parallelism strategy with a hand-implemented per-device execution strategy to manage intra-GPU resources, such as the streaming multiprocessors (SMs) allocated to compute vs. communication. Such systems require high effort; experts must design and implement a fixed strategy that is specialized to a particular model and cluster. This results in a system that is hard to adapt to new strategies.
On the other hand, general-purpose frameworks such as Megatron, DeepSpeed, and TorchTitan offer a more flexible and model-agnostic interface, with knobs for tuning the distributed training strategy. However, these frameworks eagerly dispatch operations for each high-level parallelism dimension as if the dimensions are independent, making it challenging to jointly schedule operations from composed strategies. For example, conceptually DualPipe shares a GPU between two PP microbatches; this is challenging to implement in existing frameworks that assume that each microbatch is allocated the full GPU. While compiler-based frameworks such as JAX/XLA present a more generic tensor placement abstraction instead of a fixed set of knobs, they cannot easily support arbitrary PP schedules nor control over each device’s resources. Thus, again it requires high effort to introduce novel strategies such as DualPipe.
The key problem we address is extensibility in distributed training systems. Our goal is to build a system that minimizes the effort needed to specify and implement an arbitrary distributed training strategy. Thus, we build a system that provides good performance for common strategies and control when needed for higher performance, making it amenable to both expert engineering and automated search. Our key insight is to decouple what the overall execution strategy should be from how it is realized by the runtime.
Scheduling directives
By default, the system also supports a dimension named PASS, to indicate a specific part of the forwards-backwards pass for the same Chunk. Valid values are F for forwards, B for full backwards, Bi for backwards for inputs and Bw for backwards for weights. This is useful for cases like ZeroBubble, a PP schedule that splits the backwards pass into two stages for better pipelining across devices.
The placement directives are Place, Replicate, and Shard, as described next. Placement directives take in a device mesh (an N-D array of devices) which represents devices with unique integers. Placement filters must have PASS=* (included by default), i.e. we cannot have different placements for the forwards and backwards passes of the same Chunk.
Placement directives may add communication nodes to the training DAG. Thus, we also allow these directives to pass a logical GPU stream that any inserted communication operations should execute on. During execution, the runtime will create one physical stream per logical stream on the participating devices. If no stream was provided, then the system uses the default stream, the same stream on which the compute operators run. This allows users to have full control over stream execution without having to manage streams themselves.
The user can optionally pass in a bucket_size, and the Piper runtime will attempt to bucket communications to not exceed this size. If the bucket size is smaller than the weights for a Chunk, the system transforms the DAG by breaking each Chunk into smaller Chunks. If the user wants more control over buckets, they can use multiple Replicate rules. For example, to ensure that each model layer is launched as one bucket, the user could annotate each layer of the model with dim=layer, then run Replicate on each layer index.
To express overlapped execution of different microbatches, the user can pass in a nested list of filters. For example, in Listing, line 11 specifies that the forwards for microbatch 0 of PP stage 1 should execute before an overlapped pair comprising the forwards for microbatch 1 of PP stage 1 and the backwards for microbatch 0 of PP stage 1. In this case, the Piper runtime will interleave the two sub-DAGs of matched Chunks and Comms (Section 4.3).
Centralized scheduler
The Piper runtime executes arbitrary training DAGs on a set of distributed workers. Execution starts at the centralized scheduler, which takes in the transformed training DAG that provides a partial ordering and resource assignment (device and stream) for Chunks and Comms. The goal is to produce a partial ordering per device. The ordering is partial because Chunks and Comms on the same stream are totally ordered, while Chunks and Comms on different streams are only ordered if they have a data or temporal dependency.
Decomposing the DAG simply involves gathering the sub-DAG of nodes for each device. Compute operators that execute on different devices are connected by a send-recv node; this decomposes into a send for the sending rank and a recv for the receiving rank. Ranks with the same PP stage replicate all communication operations within that stage.
The sub-DAG includes only the data dependencies between the worker’s local compute and communication operators, as well as any temporal dependencies specified by Order rules. The centralized scheduler resolves the ordering between any Chunks and Comms that do not depend on each other (i.e. there is no path between them) and that are assigned the same stream. For example, these can originate from the nested filters in the Order directive, which indicates the user’s intent to overlap sub-DAGs.
After this process, each worker will have an ordered list of Chunks and Comms per stream, plus all cross-stream data and temporal dependencies. Then, once before execution, the centralized scheduler dispatches each device’s sub-DAG to the corresponding worker. The dispatch to a worker also includes the model weights to load for Chunks and Comms.
Worker execution
Each worker loads its shard of model weights then executes the compute and communication operators according to the order determined by the centralized scheduler. The worker is responsible for managing the GPU’s local resources that may be shared between tasks: GPU streams, communicators, and memory. We rely on the GPU to allocate the shared physical resources such as SMs and HBM or network bandwidth between concurrent kernels. Our approach is complementary to other approaches that provide more precise control over physical resources, e.g., adding an SM limit on specific Chunks.
Note that when using multiple streams, there will often be multiple tasks that are ready for dispatch. This is because the compiler produces a total ordering of tasks per stream, but only a partial ordering across streams based on data and temporal dependencies. When tasks could be scheduled in any order, the worker must make a local decision about dispatch order.
Although individual kernels execute asynchronously on the GPU, the dispatch order of tasks is still important because dispatch time on the CPU can delay critical GPU kernels, especially when there are many kernels to dispatch in a single task. For example, when using gradient sharding in ZeRO-2, prioritizing gradient reduction could free memory sooner by shortening the lifetime of full gradient state. On the other hand, prioritizing all-to-all communication over gradient reductions may reduce latency along the critical path. Piper currently prioritizes send communication first, defers receive communication last to reduce point-to-point communication interference, and among remaining communication tasks prioritizes critical-path over reduction operators. The prioritization is deterministic, to ensure that all ranks in a collective group dispatch communications in the same order. Future work could include other heuristics and/or online profiling to more precisely determine the best dispatch order.
Communication management
Avoiding bubbles from unnecessary synchronization can be challenging due to complex interactions between inter- and intra-device dependencies. GPU collective communication typically requires a “communicator”, which represents one rank’s context in a given collective group. Communication operations must be executed in the same order on all ranks’ communicators in the same group, or else the device may hang because GPU collective communications are synchronous.
The inter-device communication order can create bubbles when combined with the intra-device dependencies created by shared CUDA streams. For example, in PP, most workers are continually sending and receiving microbatches to and from another worker. Thus, if we use one collective group for a PP schedule, then the send and receive operations need to be globally ordered across all workers’ communicators. However, choosing an optimal serial order at compile time is hard because it would require exact predictions of the execution time per microbatch stage as well as communication time. For example, when choosing between sending and receiving, a worker needs to choose whether to send first, which would unblock the downstream worker’s compute, or receive first, which would unblock communication operations queued after the upstream worker’s send.
To resolve this problem, Piper allocates separate streams for point-to-point communications, one for sending and one for receiving. To avoid deadlock, Piper also allocates one communicator per stream. Using separate communicators reduces scheduling burden. Instead of requiring that all P2P operations are ordered consistently for every pair of workers, the system only needs to guarantee that P2P operations in each direction are ordered consistently for every pair of workers. This does not require knowing actual run times and is already naturally satisfied by common PP schedules. In particular, the requirement on the PP schedule is that downstream workers process data in the same order that it is produced by upstream workers, e.g., if rank 0 executes microbatch 1 before 2, then rank 1 also executes microbatch 1 before 2. Piper currently rejects schedules that do not meet this requirement.
Common PP strategies
We evaluate Piper’s support for common PP schedules against Megatron and TorchTitan, which both provide out-of-the-box support for the 1F1B schedule and its interleaved variant. Interleaved 1F1B can improve training throughput for large models compared to 1F1B due to better microbatch overlapping from finer-grained interleaved stages.
TorchTitan allows users to provide a PP schedule, similar to Piper, and provides generic PP schedule-builders for 1F1B and interleaved 1F1B. We adapt the 1F1B and interleaved 1F1B schedule builders from TorchTitan to the Piper API in 29 LoC and 38 LoC, respectively.
We distribute the Qwen3 1B model with PP-8 x DP/EP-4 across 32 A100 GPUs and the Qwen3 9B model with PP-4 x DP/EP-4 across 16 A100 GPUs. We make DP the outer dimension to simulate larger-scale settings where cross-node DP is required. Megatron requires placing PP as the outermost dimension, so we route intra-node traffic over PCIe to simulate lower inter-node bandwidth for Megatron.
TorchTitan’s performance suffers due to a larger memory footprint compared to the other systems, leading to CPU-side delays inserted by the PyTorch CUDA allocator. The memory footprint is caused by memory buffers needed by TorchTitan’s DP implementation. Additionally, TorchTitan’s interleaved schedule does 14% worse than its own 1F1B schedule. This is due to sends and recvs executing on the same stream, creating bubbles across ranks in the interleaved schedule.
Piper’s performance is comparable with Megatron’s. We note that Megatron often uses hand-tuned fused kernels targeted to transformer operators, enabling faster single-device execution time: on a single device, one microbatch forward pass of a single PP stage takes about 30 ms in Megatron vs 40 ms in Piper for Qwen3 1B. In general, Piper is orthogonal to approaches like kernel fusion which apply to the low-level operator graph contained within a Piper Chunk.exec function. Thus, we believe that the two approaches could be combined to further improve performance gains.
PP x ZeRO
While all systems support ZeRO variants 1-3, the support for ZeRO 2 (parameter sharding) and 3 (weights sharding) when combined with PP is incomplete. Megatron and DeepSpeed do not support either when combined with PP. TorchTitan supports the variants but the rematerialized buffers are not resharded between all PP microbatches. This reduces communication overhead but also defeats the purpose of ZeRO sharding, which is to save per-device memory from redundant states. We believe that this uneven support for ZeRO-2 and ZeRO-3 is due to the fact that gradient and weights sharding requires careful management of pre- and post-layer hooks, whereas ZeRO-1 only operates on the optimizer states. Meanwhile, Piper correctly supports all combinations of PP x ZeRO; it simply adds the proper allgather, reshard, and reduce-scatter operations to the matched Chunks in the DAG IR, irrespective of the PP strategy.
We validate the implications of this compatibility matrix by evaluating peak memory of composed PP x ZeRO strategies. We distribute Qwen3 9B with 8-way PP and 4-way DP across 32 A100 GPUs. We expect peak training memory to decrease from ZeRO-2 to ZeRO-3, as the latter introduces parameter sharding in addition to gradient state sharding.
For Piper, we achieve correct resharding by reducing gradients after every backward pass instead of accumulating gradients between PP microbatches. This adds communication time compared to TorchTitan but achieves the full ZeRO memory savings. As a result, Piper is able to execute with much higher batch sizes than TorchTitan without OOM: 8x higher for ZeRO-2 (up to batch size 32) and 3.3x higher for ZeRO-3 (up to batch size 40).
General-purpose training frameworks
Most general-purpose training frameworks for PyTorch implement a fixed set of parallelism strategies. DP/ZeRO strategies are model-agnostic and implemented with pre- and post-layer hooks. Megatron-LM and DeepSpeed implement custom-built layers for TP/EP/CP and schedules for PP. TorchTitan supports more general strategies by using DTensor for sharding, an API inspired by GSPMD, and PiPPy for PP schedules. However, in all systems, each parallelism dimension dispatches its compute and communication operations eagerly with little to no synchronization with other operations, making it difficult to jointly schedule shared GPU resources such as communication bandwidth or memory.
Compiler-based systems such as JAX/XLA provide high-level tensor sharding and replication annotations based on GShard and GSPMD. Piper’s API is inspired by these works. The annotations allow the compiler to insert the necessary communications and lower to a per-device program, although it is limited to homogeneous SPMD strategies. Later work extended the API and runtime to support arbitrary PP schedules and heterogeneous strategies or clusters. However, JAX/XLA does not support user scheduling of the low-level execution strategy; per-device resources such as GPU streams are opaque to the user and changes to the low-level execution strategy would require modifications deep within the XLA compiler.
Conclusion
We present Piper, a distributed training system for PyTorch that decouples the distributed execution strategy specification from the model and runtime using a unified IR: the global training DAG. By making the placement, granularity, and ordering of computation and communication operations explicit, Piper allows users to express a wide range of distributed training strategies combining PP, DP, and EP with arbitrary ZeRO memory optimizations. Piper provides a useful interface for encoding both expert-designed schedules and future automated search over a rich space of composed strategies.


