ML SYSTEM DESIGN & MLOPS Β· INTERVIEW QUESTION
Explain model parallelism vs data parallelism for training large models.
π΄ advanced Β· ML Pipelines
Hint: Splitting the model across GPUs vs splitting the data across GPUs.
Answer
Data parallelism: replicate the full model on each GPU, split data batches across GPUs, synchronize gradients after each step. Simple, scales well for models that fit on one GPU.
Tools: PyTorch DDP, Horovod. Limitation: model must fit in single GPU memory. Model parallelism: split the model across GPUs.
Two types:
-
Tensor parallelism: split individual layers across GPUs (e.g., split attention heads). Low latency but high communication. Used within a node.
-
Pipeline parallelism: split layers across GPUs (layers 1-24 on GPU 0, layers 25-48 on GPU 1). Less communication but has 'bubble' (idle time). Micro-batching reduces bubble.
Combined approaches: 3D parallelism (data + tensor + pipeline) for largest models. FSDP (Fully Sharded Data Parallel): shards parameters, gradients, and optimizer states across GPUs. Each GPU stores only 1/N of the model but reconstructs needed params on-the-fly. Used for training LLaMA, GPT-4 scale models. DeepSpeed ZeRO provides similar sharding with 3 optimization stages.
Related questions
- What is LLMOps and how does it differ from traditional MLOps?
- What is a feature store? Why is it important for ML systems?
- How do you handle versioning of LLMs in production?
- Outline the data pipeline for training an LLM from raw text to training batches.
- Design a real-time ML serving system for a recommendation engine handling 10k QPS.