bugger.

How DeepSpeed works: architecture & execution flow

Training7 MIN READ

DeepSpeed

GitHub

DeepSpeed wraps a PyTorch model with a training engine that coordinates precision, optimization and distributed execution. Its ZeRO optimizer removes replicated training state across data-parallel workers, enabling configurations that would otherwise exceed device memory.

ZeRO-3PyTorchCollectivesMixed precision
Explore the components or trace execution
SYSTEM ARCHITECTURE SELECT A COMPONENT TO EXPLORE
Orchestration Compute State & storage┄ Feedback / repeat
A simplified ZeRO Stage 3 data-parallel training path. Other ZeRO stages shard less state. CPU/NVMe offload is optional; tensor and pipeline parallelism are outside this view.

Training script

The application supplies a PyTorch module, training batches and a configuration. deepspeed.initialize() returns the wrapped engine and sets up the configured training components. The script calls the engine for forward, backward and optimization.

  • Training script DeepSpeed enginetraining API calls

One pass through the system.

4 steps

Select a step to highlight the components involved in the diagram.

Why it is built this way.

Sharding saves memory through communication

ZeRO-3 can fit more persistent state, but parameter gathers add traffic and synchronization. Interconnect bandwidth, bucket sizes and overlap with computation affect whether the memory saving also produces a useful step time.

Offloading moves the bottleneck

CPU or NVMe capacity extends what can fit, but those bytes must travel back when needed. Host memory bandwidth, transfer links and storage throughput can dominate. Offload is a capacity tool, not an automatic performance improvement.

A distributed step is a group operation

A single slow rank can hold up collective progress. Checkpointing and control flow must follow the engine’s distributed contract; saving only from rank zero can hang when other ranks are expected to participate.

Read the implementation.

deepspeed/runtime/engine.py

The training engine and its forward/backward/step boundary.

deepspeed/runtime/zero/stage3.py

Stage 3 optimization, gradient partitions and updates.

deepspeed/runtime/zero/partition_parameters.py

Parameter partitioning and gather lifecycle.

Go deeper with the official docs

Educational diagrams, synthesized from the linked project documentation. Components and boundaries vary by version and deployment.

More AI systems under the hood.

Practice AI debugging
Inference · 8 min read

vLLM

An inference engine and serving stack for language models. Its central problem is sharing finite GPU memory and compute among requests whose prompts and response lengths are different.

Inference · 8 min read

SGLang

A language-model serving runtime with scheduling, attention kernels and reusable prefix state. Its RadixAttention idea is especially useful when conversations or related prompts repeatedly share an initial token sequence.

Inference · 7 min read

Ray Serve

A model-serving framework built on Ray actors. It routes requests, composes deployments and scales replicas; a replica can run a PyTorch model, ordinary Python code or an LLM inference engine such as vLLM.

Training · 7 min read

PyTorch

PyTorch provides tensor operations, automatic differentiation and the building blocks for neural networks. Its central trick is to let a normal Python program describe a computation while the runtime selects hardware kernels and records how to differentiate it.

Models & tooling · 6 min read

Hugging Face Transformers

Hugging Face is an ecosystem; Transformers is its open-source model library. It connects pretrained checkpoints, model-specific implementations, preprocessing and generation APIs. Here we follow decoder-only text generation using the PyTorch backend.

Training · 8 min read

Unsloth

Unsloth adapts model loading and training operations around the PyTorch, Transformers, PEFT and TRL ecosystem. Follow a supervised LoRA or QLoRA run to see where the base model stays frozen, where gradients flow, and why specialized kernels help.

Inference · 8 min read

llama.cpp

llama.cpp provides C/C++ model inference across CPU and accelerator backends. Its core connects a model file, tokenization, a computation graph, device buffers and a sampling loop. A server can wrap this library, but HTTP is not required for local generation.