Skip to content
tezvyn:

Difference between data and model parallelism, and when to prefer each

Source: docs.pytorch.orgEasyHow cards are made

Difference between data and model parallelism, and when to prefer each

Tests split axis: data parallelism replicates model and shards data; model parallelism shards model across devices. Use data parallelism for throughput; model parallelism when layers exceed GPU memory.

What's really being asked

Whether you understand the axis along which work is distributed in distributed training. Data parallelism and model parallelism are not interchangeable optimizations; they solve different constraints. The interviewer wants to see that you know what is replicated, what is partitioned, and how that maps to hardware limitations like GPU memory versus data throughput.

The full answer

First, define data parallelism as replicating the entire model on each worker and splitting the global batch across workers, citing PyTorch Distributed Data Parallel or Fully Sharded Data Parallel as examples. Second, define model parallelism as splitting the model itself across workers, citing Tensor Parallel or Pipeline Parallelism as examples. Third, give a clear decision rule: use data parallelism when the model fits comfortably in a single GPU and you need to train on more data faster; use model parallelism when a single layer or the full model exceeds GPU memory. Fourth, mention that hybrid strategies exist and that real systems often combine both.

The mistakes people make

Calling FSDP model parallelism is a frequent mistake; FSDP is still a data parallel strategy. Another red flag is saying data parallelism is only for small models; it is used at massive scale when the model fits. Ignoring communication overhead is also weak; both strategies introduce network traffic that can bottleneck training. Finally, giving a vague scenario without memory constraints suggests you have not operated these systems in practice.

What usually comes next

How does FSDP differ from DDP and why is it still data parallelism? When would you combine Tensor Parallel with Pipeline Parallelism? How do you handle idle time in pipeline parallelism? What changes in the backward pass for model parallelism compared to data parallelism? How do you partition data when using model parallelism so that every worker still sees the same input batch?

A concrete example

Imagine a ten billion parameter transformer where a single transformer layer consumes twenty gigabytes of parameters in fp32. A single A100 with eighty gigabytes cannot hold the full model, let alone activations. You would choose Tensor Parallel to shard individual matrix multiplications within a layer across devices, or Pipeline Parallel to place different layers on different GPUs. Conversely, if you have a one hundred million parameter ResNet that fits in four gigabytes, you would replicate it on eight A100s with DDP and feed each GPU a distinct microbatch, scaling throughput nearly linearly.

Interview question

You have a 100M-parameter image classifier that fits in 4 GB on one GPU and eight A100s available. What is the best strategy to maximize training throughput?

  • a.Replicate the model on each GPU with DDP and feed each a distinct microbatchCorrect
  • b.Use Tensor Parallel to shard individual layers across all eight GPUs
  • c.Use Pipeline Parallelism to place different layers on different GPUs
  • d.Adopt FSDP because it is a model-parallel approach that shards parameters
Why?

Replicating the model with DDP and splitting the batch is correct when the model fits on one GPU and throughput is the goal. Tensor Parallel and Pipeline Parallelism are model-parallel strategies for when layers exceed GPU memory, and FSDP is still data parallelism despite sharding parameters.

Just read this? Test yourself on what you have been reading.

Read the original → docs.pytorch.org

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles