Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a 512-GPU Distributed RLHF
& GRPO Post-Training Pipeline.

Architect a 512-GPU H100/B200 distributed RLHF/GRPO post-training pipeline that eliminates straggler stalls and GPU bubbles using disaggregated vLLM rollout workers, a Ray Object Store prioritized replay buffer, FSDP2 trainers, and non-blocking NCCL weight sync.
Start the journey7 stages· Last modified Nov 24, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When inference latency or GPU memory limits bind throughput, split the 512-GPU cluster into disaggregated vLLM Rollout Workers (GPUs 1-256) and FSDP2/ZeRO-3 Trainers (GPUs 257-512), bridged by a bounded-staleness Ray replay buffer and an InfiniBand NCCL weight-sync ring.

TL;DR30-second simplified summary
▾

GPUs 1-256 run 64 TP=4 vLLM replicas with G=8 shared prompt prefixes and length bucketing, streaming finished trajectories into a Ray Plasma replay buffer filtered to policy staleness K<=3.

GPUs 257-512 run FSDP2 ZeRO-3 with FlashAttention varlen sequence packing (32K cu_seqlens) and selective activation checkpointing. Every K steps, an isolated InfiniBand NCCL ring broadcasts layer-bucketed weights directly into vLLM HBM.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Distributed RLHF, DPO & GRPO Post-Training
Distributed post-training aligns base LLMs via multi-model RL loops (PPO/GRPO) or offline preference optimization (DPO), coordinating high-throughput vLLM rollout actors, reward/verifier pools, frozen reference KL penalties, and FSDP policy trainers.
Full walkthrough · 7 stages
01
foundation

512-GPU Cluster Topology & Disaggregated Pool Sizing.

Why this matters: Partition 512 H100/B200 GPUs across Rollout Actors, Verifiers, and FSDP2 Trainers based on throughput balance.

Think of 512-GPU Cluster Topology & Disaggregated Pool Sizing as the intuition layer for Design a 512-GPU Distributed RLHF & GRPO Post-Training Pipeline: Partition 512 H100/B200 GPUs across Rollout Actors, Verifiers, and FSDP2 Trainers based on throughput balance.

In a 70B GRPO run with G=8 completions per prompt (avg 1,500 output tokens, max 16K) and 2,048 prompts per global step (~24.5M generated tokens/step), rollout generation dominates wall-clock time (~3.5x the FLOPs of the forward/backward trainer pass). Splitting 512 GPUs (64 × 8-GPU NVLink nodes) as 256 GPUs (32 nodes, TP=4 × 64 vLLM replicas) for Rollout Workers and 256 GPUs (32 nodes, DP=32 × FSDP2 TP=8) for Policy + Reference Trainers balances the producer-consumer rate so the replay buffer neither starves nor overflows.

STAGE 1 · TOPOLOGY

512-GPU Disaggregated Rollout vs. Trainer Pool Split

Global Prompt Queueprompt-sourcevLLM Rollout Pool(1-256)rollout-clusterCPU/SandboxedVerifiersreward-clusterFSDP2 Trainer Pool(257-512)trainer-clusterStreams completed traces

1.Dynamic Rebalancing: When CoT lengths grow from 1.5K to 8K, shift 8 nodes from Trainer to Rollout pool.

2.NVLink vs. InfiniBand: Keep TP=4/8 strictly inside 8-GPU NVLink domains; run FSDP DP and weight sync over 400Gbps IB.

Splitting 64 8-GPU nodes evenly between TP=4 vLLM actors and ZeRO-3 FSDP2 trainers balances rollout throughput with backward-pass speed.

02
foundation

Dynamic Length-Bucketing & Continuous Batching on Rollout GPUs.

Why this matters: Eliminate intra-batch padding and straggler stalls during G=8 trajectory generation.

Generating G=8 completions for a 16K-token coding prompt alongside a 300-token trivia prompt inside a static batch wastes 95% of KV-cache slots waiting for the 16K trace.

Rollout workers use vLLM continuous batching with Prefix Caching across the shared G=8 prompt prefix (saving 87.5% of prompt prefill KV memory!).

STAGE 2 · ROLLOUT ENGINE

Shared-Prefix vLLM Continuous Batching & Length Bucketing

Length-BucketedRouterlength-routerG=8 Shared Prompt KVprefix-cachevLLM ContinuousSchedulerslot-schedulerPer-Group Emittergroup-emitterShares prompt KV blocks

1.G=8 Prefix Sharing: Prefilling the prompt once and branching 8 decode heads cuts rollout TTFT by ~8x.

2.Straggler Isolation: Routing >8K CoT tasks to dedicated replicas keeps fast-turn throughput high.

Shared-prefix vLLM continuous batching and length-bucketed routing prevent long CoT stragglers from stalling short-turn rollouts.

Engineering Decision Framework
Problem
How to implement Design a 512-GPU Distributed RLHF & GRPO Post-Training Pipeline without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When inference latency or GPU memory limits bind throughput, split the 512-GPU cluster into disaggregated vLLM Rollout Workers (GPUs 1-256) and FSDP2/ZeRO-3 Trainers (GPUs 257-512), bridged by a bounded-staleness Ray replay buffer and an InfiniBand NCCL weight-sync ring.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a 512-GPU Distributed RLHF & GRPO Post-Training Pipeline experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

Ray Object Store Prioritized Replay Buffer & Bounded Staleness.

Why this matters: Decouple rollout production from trainer consumption using zero-copy Ray shared memory.

Finished (prompt, G_completions, rewards, old_logprobs) groups stream into a distributed Ray Object Store (Plasma shared-memory) Prioritized Replay Buffer.

To prevent off-policy divergence, every trajectory carries policy_version = v_t. The trainer only samples batches where current_step - policy_version <= K_max (typically K_max = 3), evicting staler items automatically.

STAGE 3 · REPLAY BUFFER

Ray Object Store Prioritized Buffer with K_max=3 Staleness

Completed G=8Groupsbuffer-ingressRay Plasma ObjectStoreshared-storeStaleness Evictor(K<=3)staleness-gateVariancePrioritizerbatch-samplerFilters policy_ver delta

1.Bounded Off-Policy: Capping staleness at K<=3 steps preserves GRPO convergence without synchronous blocking.

2.Zero-Copy IPC: Ray Plasma passes multi-megabyte token/logprob tensors via shared memory without pickle overhead.

A Ray Object Store replay buffer with K<=3 staleness filtering and reward-variance prioritization feeds high-signal batches to trainers.

04
intermediate

FSDP2 Trainer Pool with Sequence Packing & ZeRO-3 Checkpointing.

Why this matters: Maximize trainer MFU across GPUs 257-512 by packing variable-length trajectories and trading compute for HBM.

Even within a filtered batch, trajectory lengths vary from 200 to 8,000 tokens.

Padding every sequence to 8,000 wastes 75% of attention FLOPs. The trainer uses FlashAttention-2/3 varlen Sequence Packing (cu_seqlens) to concatenate multiple trajectories into a single 32K-token packed micro-batch with zero cross-trajectory attention leakage.

STAGE 4 · TRAINER POOL

FSDP2 ZeRO-3 Training with FlashAttention Varlen Packing

Varlen SequencePackerbatch-packerFlashAttention-3Varlenattention-kernelFSDP2 ZeRO-3 Shardssharded-trainerSelective Act. Ckptmemory-saverRuns fwd/bwd on shards

1.3x Effective FLOPs: Varlen sequence packing eliminates padding waste on heavy-tailed reasoning traces.

2.Reference Logprobs: Compute reference policy logprobs in packed mode too, maximizing memory bandwidth.

FlashAttention varlen sequence packing and FSDP2 ZeRO-3 sharding eliminate padding waste across variable-length RL trajectories.

05
intermediate

Non-Blocking NCCL Weight-Sync Ring (Every K Steps).

Why this matters: Update 256 rollout GPUs from 256 trainer GPUs over InfiniBand without pausing inference or touching disk.

Every K optimizer steps (e.g., K=1–4), trainer rank-0s per FSDP group gather each transformer layer into a staging buffer and push it over a dedicated NCCL Weight-Sync Ring (400 Gbps InfiniBand NDR) directly to the vLLM rollout workers.

To make this non-blocking, vLLM workers use a double-buffered staging slot or brief pause-and-swap between continuous-batching decode steps (<2s for 70B BF16, <80ms for LoRA).

STAGE 5 · WEIGHT SYNC

Isolated InfiniBand NCCL Weight-Sync Ring

FSDP2 Layer Gatherparam-gathererNCCL Sync Ring (IBNDR)rdma-ringvLLM Staging Slotweight-receiverBump policy_ver =t+1version-taggerWrites to vLLM HBM

1.Communicator Isolation: Never reuse the FSDP training NCCL group for weight sync—isolate failure domains.

2.Step Tagging: Increment policy_ver atomically on swap so in-flight old rollouts are tagged accurately.

An isolated InfiniBand NCCL ring streams layer-bucketed weights into vLLM staging buffers in ~2 seconds with zero disk I/O.

06
advanced

Elastic Fault Tolerance & Straggler Node Replacement.

Why this matters: Survive GPU XID/ECC faults on 512-GPU runs without restarting from scratch.

On a 512-GPU cluster, hardware or InfiniBand link failures occur every 12–24 hours on average.

Disaggregated architecture makes recovery dramatically simpler for the rollout pool: if a TP=4 vLLM replica crashes, Ray restarts it on a spare node and pulls the latest weights via NCCL without interrupting the FSDP2 trainer or the other 63 rollout replicas!

STAGE 6 · FAULT TOLERANCE

Asymmetric Rollout vs. Trainer Fault Recovery

DCGM / XID HealthProbehardware-monitorRollout Hot-Swaprollout-recoveryTorchElasticRendezvoustrainer-recovery16 Hot-Spare GPUsspare-poolTriggers trainer rendezvous

1.Zero-Cascade Rollouts: Rollout replicas are stateless workers; losing one only dips generation rate by 1.5%.

2.Pre-Flight IB Burn-In: Run a 10s NCCL all-reduce test on spare nodes before admitting them to the FSDP ring.

Disaggregation isolates rollout replica crashes from FSDP training, while TorchElastic and hot-spare nodes recover trainer faults in <15 seconds.

07
advanced

Cluster MFU Profiling, Reward-Hack Guards & Benchmark Eval.

Why this matters: Monitor MFU, rollout-to-trainer queue depth, and held-out reasoning benchmarks continuously.

To keep a 512-GPU run cost-effective, an observability stack (Prometheus + TensorBoard/W&B + Nsight traces) tracks Rollout Token/s, Trainer MFU (target >45%), Replay Buffer queue depth, and Weight-Sync pause duration.

Simultaneously, every 50 steps, an async eval hook runs held-out benchmarks (MATH-500, SWE-bench-Lite, IFEval) and checks response-length vs.

STAGE 7 · OBSERVABILITY

512-GPU MFU Telemetry & Continuous Held-Out Benchmarks

MFU & Buffer DepthProbeperf-monitorLength-RewardCorrelatorhack-detector50-Step Held-OutEvalbenchmark-runnerRun ControlDashboardcontrol-planeAlerts on reward drift

1.Queue Depth Signal: Empty replay buffer = rollout-bound (shift GPUs to vLLM); growing staleness = trainer-bound.

2.Generalization Gate: Stop early if training reward climbs while held-out MATH/SWE scores plateau.

Monitoring replay-buffer depth, trainer MFU, and held-out benchmark curves catches hardware imbalances and reward hacking early.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

In a 512-GPU disaggregated RLHF pipeline, you notice the Ray Replay Buffer is consistently empty and FSDP2 Trainer GPUs are idling 35% of the time waiting for batches. What is the root cause and best fix?

Recommended Learning Flow