MLCrack

    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:

    1. Tensor parallelism: split individual layers across GPUs (e.g., split attention heads). Low latency but high communication. Used within a node.

    2. 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.