Skip to content

HybridFlow: A Flexible and Efficient RLHF Framework

optionalcorefundamentalpaperrubric 10/122024 · EuroSys 2025 · ~55 min

Guangming Sheng, Chi Zhang, Zilingfeng Ye, …, Chuan Wu

Read first: Proximal Policy Optimization (PPO) · RL infrastructure: verl, OpenRLHF and AReaL

Status

TL;DR. RL fine-tuning of an LLM is a dataflow of several large models: an actor generates, a critic, a reference policy and a reward model score, and the actor and critic train. HybridFlow lets you write that dataflow as a short single-process program. Each model runs as a distributed group of workers underneath, and the actor’s weights are resharded between its training and generation layouts without duplication. The open-source release of this design is verl, which many agentic RL systems now build on, including RAGEN, Agent Lightning’s trainer and many search-agent papers.

Why it matters now. If you train a search agent with RL, the GPU time goes into two things: generating long rollouts and updating the policy. HybridFlow is the clearest account of how one framework moves the same weights between those two jobs and places models on GPUs. That is what you need in order to read a verl config or decide whether a run will fit on your nodes. It is a 2024 paper about single-turn RLHF: the agent features of modern verl came later.

The RLHF dataflow. For PPO, each iteration has three stages (§2.1):

  1. Generation: the actor samples responses.
  2. Preparation: the critic, reference policy and reward model each run one forward pass, giving values, reference log-probabilities and rewards.
  3. Training: the actor and critic update.

Actor training and generation together took 58.9% of iteration time in the paper’s profile. They also want different parallelism: training is compute-bound and wants large model-parallel sizes, while generation is memory-bound and wants more data-parallel replicas.

Hybrid controllers. A single controller (one process dispatching all work) makes the dataflow easy to write but becomes a bottleneck when it drives every GPU operation. A multi-controller (every GPU runs its own SPMD program, as in Megatron) is fast but hard-wires the algorithm. HybridFlow uses both:

  • Between models, a single controller. The driver calls coarse operations such as generate_sequences, compute_values and update_actor on worker groups via Ray RPC, passing data futures.
  • Within a model, multiple controllers. The workers run Megatron, FSDP or DeepSpeed for training and vLLM for generation.

Three pieces make this work:

  • ParallelWorker classes (3D-parallel, FSDP and ZeRO) wrap the training engines. 3D parallelism splits a model three ways at once: into pipeline stages (p), into tensor shards within each layer (t), and into data-parallel replicas (d).
  • @register transfer protocols say how inputs are split across a worker group and how outputs are collected. The paper defines eight, including 3D_PROTO, DP_PROTO and ONE_TO_ALL.
  • ResourcePool decides which models share GPUs.

With these, PPO is about eight lines of driver code, Safe-RLHF adds about five, and ReMax adds one extra generation call and drops the critic (Fig. 6).

3D-HybridEngine. The actor trains with pipeline, tensor and data-parallel sizes p-t-d on Na=p t dN_a = p\,t\,d GPUs, and generates with pgp_g-tgt_g-dgd_g-dd, where

dg=p tpg tgd_g=\frac{p\,t}{p_g\,t_g}

is a micro data-parallel size inside each training model-parallel group. The usual approach forms generation groups from consecutive ranks, so a GPU’s generation shard does not contain its training shard and both must be stored. HybridFlow instead forms generation TP and PP groups from ranks spaced t/tgt/t_g and p/pgp/p_g apart, and micro data-parallel groups from consecutive ranks (§5.3). Each GPU’s generation shard then contains its training shard, and one concurrent all-gather inside each micro data-parallel group completes it. With actor size M, Table 2 gives

commHybridFlow=t p−tg pgtg pg t p M=dg−1t p M,peak=Mtg pg,redundancy=0,\text{comm}_{\text{HybridFlow}}=\frac{t\,p-t_g\,p_g}{t_g\,p_g\,t\,p}\,M=\frac{d_g-1}{t\,p}\,M,\qquad \text{peak}=\frac{M}{t_g\,p_g},\qquad \text{redundancy}=0,

against tpd−1tpdM\frac{tpd-1}{tpd}M communication, peak memory M and redundancy 1tpdM\frac{1}{tpd}M for DeepSpeed-Chat. HybridFlow-V, a variant that gathers within the tp group, sits in between at tp−1tpM\frac{tp-1}{tp}M, M and 1tpM\frac{1}{tp}M.

Auto-mapping. Algorithm 1 enumerates placements of the models onto device sets; PPO’s four models give 15 placements (a Bell number). It searches parallelism for each placement with a simulator and picks the fastest.

HybridFlow: hybrid controllers and zero-redundancy actor resharding Top: a single-controller driver program calls coarse operations such as generate_sequences, compute_values and update_actor on three worker groups (actor, critic, and reference plus reward), each running multi-controller SPMD code, via Ray remote calls with register-declared transfer protocols. A ResourcePool decides whether groups are colocated, split or standalone. Bottom: the Figure 8 example on 8 GPUs. In training (tensor parallel 4, data parallel 2) GPUs G1 to G4 hold quarters q1 to q4 and G5 to G8 repeat them. In generation (tensor parallel 2) each GPU needs a half: G1 and G2 all-gather to get h1 equal to q1 plus q2, G3 and G4 get h2 equal to q3 plus q4, and so on. Dashed boxes mark the micro data-parallel pairs, which all-gather concurrently. Generation tensor-parallel groups are G1 with G3, G2 with G4, G5 with G7 and G6 with G8, so every GPU's generation half contains its training quarter and no weight is stored twice. single controller (driver) actor.generate_sequences() critic.compute_values() actor.update_actor() actor group (SPMD) critic group (SPMD) ref + reward groups ResourcePool colocate / split / standalone placement Ray RPC between models; @register protocols split inputs and collect outputs 3D-HybridEngine (Fig. 8): train p-t-d = 1-4-2, generate 1-2-2-2 train TP 4, DP 2 generate TP 2, μDP 2 G1·q1 G1·h1 G2·q2 G2·h1 G3·q3 G3·h2 G4·q4 G4·h2 G5·q1 G5·h1 G6·q2 G6·h1 G7·q3 G7·h2 G8·q4 G8·h2 Dashed pairs = micro-DP groups [G1,G2] [G3,G4] [G5,G6] [G7,G8], all-gathering at once Generation TP groups [G1,G3] [G2,G4] [G5,G7] [G6,G8]: no weight is stored twice h1 = q1 + q2, h2 = q3 + q4; each GPU receives only M/4 (Table 2: M/4, peak M/2)
Original sketch. Top: a single-process driver calls coarse operations on worker groups; each group runs multi-controller SPMD code, and ResourcePool decides which groups share GPUs. Bottom: the Figure 8 example. The actor trains as 1-4-2 on 8 GPUs and generates as 1-2-2-2; interval-spaced generation TP groups mean each GPU only all-gathers with its micro data-parallel partner, with no duplicate weights.

All numbers are paper-reported (§8), on up to 128 A100 GPUs with Llama models from 7B to 70B, the full-hh-rlhf dataset, 1024-token prompts and responses, and a global batch of 1024.

  • Overall throughput. 1.53× to 20.57× higher than the baselines across PPO, ReMax and Safe-RLHF.
  • PPO specifically (Fig. 9). Average speedups of 3.67× over DeepSpeed-Chat (up to 7.84×), 3.25× over OpenRLHF (up to 5.93×) and 12.52× over NeMo-Aligner (up to 20.57×).
  • 70B models. The average speedup is highest (9.64×), and the training-to-generation transition overhead is cut by up to 71.2% against DeepSpeed-Chat and 89.1% against OpenRLHF.
  • Scaling. Strong-scaling efficiency is 66.8%, averaged over algorithms and model sizes.
  • Placement (§8.3, Fig. 13).
    • Colocation was best from 16 to 64 GPUs.
    • Split placement was best for 34B at 96–128 GPUs and for 13B at 96 GPUs.
    • For 13B on 128 GPUs a standalone plan was best: 64 actor, 32 critic, 16 reference and 16 reward GPUs.
  • Implementation (§7). About 12k lines of Python: 1.8k for the APIs, 2.4k for the 3D-HybridEngine and 1.9k for auto-mapping.
  • Single-turn RLHF only. Responses are bounded and synchronous, so the paper does not face long-tail agent rollouts, tool latency or environment state.
  • Baselines are 2024 versions. The speedups compare against the frameworks as they were then; those frameworks have since changed.
  • The placement search assumes homogeneous GPUs and simulated costs. The paper notes that extending it to heterogeneous devices is possible but leaves it untested.
  • The codebase has moved on. The verl repository has evolved substantially since the paper, for example adding multi-turn and agent workflows. Attribute those features to verl’s documentation and later papers, not to HybridFlow.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    The actor trains with 3D parallel sizes p = 1, t = 4, d = 2 on 8 GPUs and generates with p_g = 1, t_g = 2. Compute the generation micro data-parallel size d_g, then fill in Table 2's communication volume, peak memory and redundancy for DeepSpeed-Chat, HybridFlow-V and HybridFlow in units of the actor size M. Check the HybridFlow number by counting what each GPU holds before and after resharding.

    What a strong answer covers
    • d_g = p·t/(p_g·t_g) = 4/2 = 2.
    • DeepSpeed-Chat all-gathers across all tpd = 8 GPUs: communication (tpd − 1)/tpd · M = 7M/8, peak memory M, redundancy M/8.
    • HybridFlow-V gathers within the tp = 4 group: communication (tp − 1)/tp · M = 3M/4, peak memory M, redundancy M/4.
    • HybridFlow: communication (tp − t_g·p_g)/(t_g·p_g·tp) · M = (4 − 2)/(2·4) · M = M/4, peak memory M/(t_g·p_g) = M/2, redundancy 0.
    • Check: in training each GPU holds M/(tp) = M/4; in generation it needs M/(t_g·p_g) = M/2, which includes its own training shard, so it receives only M/2 − M/4 = M/4 from its micro data-parallel partner.
  2. Mechanism

    Explain why the usual way of forming generation tensor-parallel groups (consecutive ranks) leaves redundant weights during the training-to-generation switch, and how HybridFlow's grouping (generation TP and PP groups take ranks at intervals t/t_g and p/p_g; micro data-parallel groups are consecutive) removes it. Use the Figure 8 example.

    What a strong answer covers
    • With consecutive ranks, the generation shard a GPU needs does not contain the training shard it already holds, so it must keep the training weights and also store a new, mostly different generation shard: that duplicate is the redundancy.
    • Figure 8: training TP groups of 4 hold quarters 1–4; with interval grouping the generation TP groups are [G1, G3], [G2, G4], [G5, G7], [G6, G8], and the micro data-parallel groups are [G1, G2], [G3, G4], [G5, G6], [G7, G8].
    • Because G1 and G2 hold adjacent training quarters, an all-gather inside the micro data-parallel group [G1, G2] gives each the half they need for generation, and that half contains their own quarter, so no weight is stored twice.
    • All micro data-parallel groups do their all-gathers concurrently, which is why communication drops to (d_g − 1)/(tp) · M.
  3. Mechanism

    HybridFlow uses a single controller between models and multiple controllers within each model. Explain what each paradigm costs on its own, how a PPO step becomes about eight lines of driver code, and what the @register transfer protocols and ResourcePool add.

    What a strong answer covers
    • A pure single controller (one process dispatching every operation) is easy to program but has high dispatch overhead when it drives every GPU operation of large models.
    • A pure multi-controller (every GPU runs its own program, as in Megatron) is fast but hard-wires the dataflow; changing the algorithm means editing code on every worker and the communication between models.
    • HybridFlow's driver calls coarse model operations such as generate_sequences, compute_values and update_actor on worker groups through Ray RPC; inside each group, workers run as multi-controller SPMD programs (Megatron, FSDP, DeepSpeed, vLLM).
    • A @register decorator states each operation's transfer protocol (how inputs are distributed to and outputs collected from the workers, for example 3D_PROTO or ONE_TO_ALL), and ResourcePool sets which models share GPUs. This is why swapping PPO for ReMax or Safe-RLHF changes only a few driver lines.
  4. What if…

    Section 8.3 compares placements (colocate all models, split into two sets, standalone) across cluster sizes. Summarise what was best where, explain why colocation wins on small clusters but not large ones, and say what this ablation does not cover.

    What a strong answer covers
    • From 16 to 64 GPUs, colocating all four PPO models on the same devices was best; split won for 34B at 96–128 GPUs and 13B at 96 GPUs; standalone won for 13B at 128 GPUs (64 actor, 32 critic, 16 reference, 16 reward).
    • On small clusters every model can use all GPUs in its stage, so colocation keeps utilisation high; on large clusters with a fixed global batch, colocated models run sequentially with too little work per GPU, and running models in parallel on separate GPUs scales better.
    • With a 13B actor and 70B critic and reward model, colocation was 44.8% better on average up to 64 GPUs; at 128 GPUs the best plan put actor, reference and reward on 64 GPUs and the critic on the other 64.
    • Not covered: multi-turn tool use, variable-length agent rollouts, or asynchronous generation. All runs are single-turn RLHF with fixed 1024-token prompts and responses.
  5. Design

    An academic lab has one node of 8 GPUs and wants to RL-train a 7B search agent with GRPO (no critic, no learned reward model; the reward is computed by a script). Using HybridFlow's concepts, decide the placement, the actor's training and generation parallelism, and what in the paper's analysis no longer applies.

    What a strong answer covers
    • Without a critic or reward model the dataflow has an actor and an optional reference model; colocating them on all 8 GPUs follows the paper's small-cluster result.
    • Training could use FSDP or a small TP (for example t = 2 or 4) across the node; generation should use the smallest TP that fits the model and long contexts, giving more generation replicas.
    • The 3D-HybridEngine logic still matters: the actor switches between training and generation shardings every step, and avoiding duplicate weights frees memory for the KV cache of long multi-turn rollouts.
    • No longer applicable: the four-model placement search and the fixed 1024-token workload. Agent rollouts have tool latency and highly variable lengths, so the bottleneck shifts to the slowest rollout, which the 2024 paper does not address.
  6. Critique

    Many agentic RL projects say they are built on verl. Separate what the 2024 HybridFlow paper actually contributes from what a reader might assume, and identify which assumptions in its design and evaluation break for long-horizon tool-using agents.

    What a strong answer covers
    • Paper contributions: the hybrid single-/multi-controller programming model, transfer protocols, the 3D-HybridEngine with zero-redundancy resharding, and automatic device mapping, evaluated on single-turn RLHF (PPO, ReMax, Safe-RLHF).
    • Not in the paper: multi-turn agent loops, tool calling, asynchronous rollouts, and GRPO-style recipes. These were added to the verl codebase later and should be cited from verl documentation, not from this paper.
    • Broken assumptions: generation is synchronous and bounded (fixed 1024-token responses), so a training step waits for all responses; agent rollouts have long-tail lengths and external tool latency.
    • The speedups (1.53× to 20.57×) are against 2024 versions of DeepSpeed-Chat, OpenRLHF and NeMo-Aligner on RLHF workloads, so they say little about throughput for agentic workloads.

Done with this page?

Status