Data and model parallelism
Quick answer
Data parallelism replicates a model and assigns different samples to each worker; model parallelism partitions the computation or parameters of a single model. Both can cooperate, but the placement of data, parameters and synchronization differs. Examples use small synthetic inputs and Python or local CPU PyTorch. ByteMind execution is unverified.
Assign unique rows
rows=list(range(7))shards=[rows[r::3] for r in range(3)]print(shards)print(sorted(sum(shards,[]))==rows)Expected output (locally tested): [[0, 3, 6], [1, 4], [2, 5]] True. Strided ownership is disjoint and covers all seven rows.
How it works
Data parallel workers must begin a synchronous step with the same parameters and combine their gradient contributions before applying the same update. Split examples without duplication when evaluating; a distributed training sampler may pad or drop examples and must be accounted for. Tensor parallelism splits operations such as a matrix multiplication along a compatible axis, then combines partial results. Pipeline parallelism assigns sequential layers to stages and moves microbatch activations forward and gradients backward. A pipeline has warmup and drain bubbles; increasing microbatches may improve utilization but changes memory needs. A sharded parameter layout is not the same as splitting the dataset. Hybrid strategies require explicit process groups and communication ordering. The first example checks sample ownership; the second computes a split dot product, not actual inter-device messaging.
Combine partial dot products
x=[1,2,3,4]; w=[2,1,-1,3]parts=[sum(a*b for a,b in zip(x[i:i+2],w[i:i+2])) for i in (0,2)]print(parts, sum(parts))Expected output (locally tested): [4, 9] 13. The scalar result is the sum of partial dot products.
Common mistakes
Do not assume two replicas see different data automatically or concatenate partial sums from a column-partitioned dot product. Replication does not reduce per-replica parameter memory. Model partitioning does not automatically increase throughput.
Practice and next steps
Draw a two-stage pipeline with three microbatches. Label activation transfers and identify when each stage is idle. Compare the data ownership with two independent model replicas.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Data and model parallelism — knowledge check
Apply data and model parallelism to small examples and debugging scenarios.
What is replicated in ordinary data parallelism?
What moves between pipeline stages in the forward pass?
Why combine partial dot products by addition?
What can pipeline bubbles reduce?
Does data parallelism alone shard model memory?