Deep LearningDeep Learning Comparison Series

Data Parallelism vs Model Parallelism

Question 316 of 316 · Updated

On this page

Data parallelism and model parallelism are two ways to distribute neural-network training across multiple devices. Data parallelism keeps a full model replica on each device and gives replicas different portions of the training data. Model parallelism divides the model itself across devices because its parameters, activations, or computation are too large or expensive for one device.

The central distinction is what gets split: data parallelism splits examples; model parallelism splits model computation or state. They solve different scaling problems and are often combined.

1. Data parallelism: same model, different data#

Each worker (commonly one process per GPU) holds a replica of the model. Each worker processes a different mini-batch, computes gradients locally, and synchronizes gradients with the other workers. After synchronization, each replica applies the same optimizer update and remains in sync.

A typical step is:

  1. Initialize identical model parameters on each worker.
  2. Give each worker a different portion of the global batch.
  3. Run forward and backward passes on each local batch.
  4. Aggregate gradients, commonly with an all-reduce operation.
  5. Apply the same optimizer update on every replica.

Example: With four GPUs and a local batch size of 32 per GPU, each step processes a global batch of 128 examples. Each GPU still stores the complete model.

DistributedDataParallel (DDP)#

PyTorch DistributedDataParallel synchronizes gradients across model replicas. It does not automatically divide the input batch; the training program or a DistributedSampler must provide the intended data partition.

Illustrative per-process training step:

PYTHON
model = MyModel().to(local_device) ddp_model = torch.nn.parallel.DistributedDataParallel( model, device_ids=[local_device] ) for inputs, targets in train_loader: inputs, targets = inputs.to(local_device), targets.to(local_device) optimizer.zero_grad(set_to_none=True) loss = loss_fn(ddp_model(inputs), targets) loss.backward() # DDP synchronizes gradients optimizer.step()

A complete multi-process program also needs process-group initialization, rank/device assignment, data sampling, optimizer setup, and cleanup.

Strengths and limitations

  • Increases throughput by computing on different examples concurrently.
  • Keeps model placement straightforward because each worker has the full model.
  • Gradient communication and synchronization can limit scaling, especially over slower network links.
  • Ordinary DDP does not solve a model that cannot fit on one GPU: every replica stores the full model and its associated state.
  • Increasing worker count often increases global batch size; learning-rate schedules and convergence must be evaluated.

2. Model parallelism: split the model across devices#

Different devices hold or execute different parts of one model. A forward pass sends intermediate activations between devices, and backward propagation sends corresponding gradients through the partitioned computation.

Pipeline parallelism#

Pipeline parallelism assigns groups of layers to different devices. For example:

  • GPU 0: embedding and Transformer blocks 1–8
  • GPU 1: blocks 9–16
  • GPU 2: blocks 17–24
  • GPU 3: blocks 25–32 and output head

A batch can be split into micro-batches so different stages process different micro-batches concurrently. Scheduling is important: pipeline bubbles, stage imbalance, activation storage, and communication all affect efficiency. GPipe demonstrated layer partitioning across accelerators with batch-splitting to improve utilization.

Tensor parallelism#

Tensor parallelism splits operations within a layer across devices. A large matrix multiplication, for example, can be divided into row-wise or column-wise pieces. Devices compute their portions and exchange or combine intermediate results using collectives such as all-reduce, all-gather, or reduce-scatter, depending on the operation and layout.

Unlike pipeline parallelism, which assigns different layer ranges to devices, tensor parallelism distributes computation within the same layer. It can reduce per-device parameter and activation footprints, but introduces communication within layers. Fast interconnects are often important.

The term model parallelism is sometimes used broadly for partitioning model computation or state. Fully Sharded Data Parallel (FSDP) and related approaches distribute parameter, gradient, and optimizer-state storage across workers while retaining data-parallel computation patterns. They are related distributed-training strategies, but are not simply a pipeline split.

3. Side-by-side comparison#

DimensionData parallelismModel parallelism
What is divided?Training examples / batchesModel layers, tensor operations, or model state
Model placementFull replica on each worker in ordinary DDPDifferent portions or shards reside on different workers
Main purposeIncrease training throughputFit or execute a model too large or costly for one device
CommunicationUsually gradient synchronizationActivations and activation gradients; tensor collectives or state transfers
Memory per deviceFull model plus local activations and gradientsA portion of model state plus local activations and buffers
Main bottleneckGradient communication, input pipeline, synchronization, global-batch effectsInter-device communication, partition imbalance, pipeline bubbles
Typical methodsPyTorch DDPPipeline parallelism, tensor parallelism, sharded training

4. Numerical example: four GPUs#

Assume a training job has four GPUs and a model with 40 billion parameters. This example illustrates placement, not a complete memory estimate; actual memory also includes activations, gradients, optimizer states, temporary buffers, and framework overhead.

Option A — Data parallelism

  • Each of the four GPUs stores the complete 40-billion-parameter model.
  • Each GPU processes different examples.
  • Gradients are synchronized before the optimizer update.

This can increase examples processed per step, but each GPU still needs enough memory for the full model and training state.

Option B — Model parallelism

  • Each GPU stores or computes one portion of the model.
  • Activations and gradients move between relevant partitions.
  • If partitioning is balanced and communication is manageable, the model may fit even when a complete replica cannot fit on one GPU.

A poor partition can leave devices idle or spend too much time transferring tensors.

5. Can they be combined?#

Yes. Large training systems commonly combine tensor parallelism within a model replica, pipeline parallelism across layer stages, and data parallelism across multiple replicas of that partitioned model. Combining tensor, pipeline, and data parallelism is often called 3D parallelism.

The Megatron-LM research demonstrates composing these techniques to train very large language models across GPU clusters. The combination introduces multiple communication groups, more complicated placement and scheduling, and additional configuration choices.

6. How to choose#

  • The model fits on one GPU, but training is too slow: Start with data parallelism such as DDP. Profile scaling efficiency and communication as workers are added.
  • Model parameters and training state do not fit: Consider sharded approaches such as FSDP, or model parallelism, depending on which memory components dominate.
  • Transformer layers or matrix operations are very large: Tensor parallelism may split those operations. It is most attractive when device-to-device communication is fast enough.
  • The model has many sequential layers: Pipeline parallelism can distribute layer ranges. Balance stage compute and account for bubbles and micro-batch scheduling.
  • The model and cluster are both very large: Combine parallelism dimensions, then profile end-to-end throughput, memory, communication, and convergence.

Do not choose based only on GPU count. Measure step time, tokens or examples per second, peak memory, communication time, GPU utilization, and validation behavior. Using every GPU does not guarantee the fastest or most cost-effective run.

7. Common misconceptions#

  • “Data parallelism splits the model.” Ordinary DDP replicates the model; it distributes examples.
  • “Model parallelism means pipeline parallelism.” Pipeline parallelism is one form. Tensor parallelism splits operations within layers; sharding distributes model state.
  • “DDP automatically shards the input.” DDP synchronizes gradients; input partitioning is the user's responsibility.
  • “Model parallelism always reduces communication.” It can require frequent activation or tensor communication.
  • “More GPUs guarantee linear speedup.” Synchronization, network bandwidth, load imbalance, pipeline bubbles, and batch-size changes can reduce scaling efficiency.
  • “The approaches are mutually exclusive.” They can be composed in one training job.

Key takeaway: Data parallelism replicates the model and distributes different training examples across workers, while model parallelism distributes parts of model computation or state across devices. Use data parallelism when the model fits on each device and throughput is the goal; use model partitioning or sharding when model size or operation-level scaling is the constraint. Combine them when large-scale training requires both.

Research and technical references: PyTorch, Distributed Overview; PyTorch, DistributedDataParallel; PyTorch, Pipeline Parallelism; Huang et al., GPipe (NeurIPS 2019); Narayanan et al., Megatron-LM (SC 2021).

Related questions

Explore other topics:Forward Deployed EngineeringMachine LearningLarge Language Models