HybridFlow: A Flexible and Efficient RLHF Framework

Guangming Sheng, Chi Zhang, Zilingfeng Ye, Xibin Wu, Wang Zhang, Ru Zhang, Yanghua Peng, Haibin Lin, Chuan Wu · DOI

Abstract

Reinforcement Learning from Human Feedback (RLHF) is widely used in Large Language Model (LLM) alignment. Traditional RL can be modeled as a dataflow, where each node represents computation of a neural network (NN) and each edge denotes data dependencies between the NNs. RLHF complicates the dataflow by expanding each node into a distributed LLM training or generation program, and each edge into a many-to-many multicast. Traditional RL frameworks execute the dataflow using a single controller to instruct both intra-node computation and inter-node communication, which can be inefficient in RLHF due to large control dispatch overhead for distributed intra-node computation. Existing RLHF systems adopt a multi-controller paradigm, which can be inflexible due to nesting distributed computation and data communication. We propose HybridFlow, which combines single-controller and multi-controller paradigms in a hybrid manner to enable flexible representation and efficient execution of the RLHF dataflow. We carefully design a set of hierarchical APIs that decouple and encapsulate computation and data dependencies in the complex RLHF dataflow, allowing efficient operation orchestration to implement RLHF algorithms and flexible mapping of the computation onto various devices. We further design a 3D-HybridEngine for efficient actor model resharding between training and generation phases, with zero memory redundancy and significantly reduced communication overhead. Our experimental results demonstrate 1.53x to 20.57x throughput improvement when running various RLHF algorithms using HybridFlow, as compared with state-of-the-art baselines. HybridFlow source code is available at https://github.com/volcengine/verl.

Introduction

Aligning Large Language Models (LLMs) via Reinforcement Learning from Human Feedback (RLHF) is a complex engineering challenge. Unlike standard supervised fine-tuning, an RLHF pipeline (such as PPO) requires the coordination of at least four distinct models: an actor, a critic, a reference model, and a reward model. Each of these models has unique computational requirements, ranging from memory-bound generation to compute-bound training.

Existing frameworks typically struggle with a trade-off between flexibility and efficiency. Single-controller systems offer ease of use but suffer from high dispatch overhead in distributed environments. Conversely, multi-controller systems are efficient but often result in rigid, "spaghetti" code that is difficult to adapt to new algorithms or hardware configurations.

The HybridFlow Paradigm

HybridFlow introduces a hierarchical hybrid programming model that combines the best of both worlds. It utilizes a single controller (built on Ray) to manage high-level dataflow orchestration—determining how data moves between models—while delegating the heavy intra-model computation to a multi-controller paradigm using engines like Megatron-LM or vLLM.

Flexible Algorithm Representation

By representing RLHF algorithms as directed acyclic graphs (DAGs), HybridFlow allows researchers to implement diverse alignment strategies with minimal code changes. The framework's hierarchical APIs encapsulate complex distributed strategies (e.g., 3D parallelism, ZeRO), enabling the implementation of algorithms like PPO, Safe-RLHF, and ReMax by simply defining their dataflow dependencies.

Dataflow representations of PPO, Safe-RLHF, and ReMax algorithms as supported by HybridFlow's flexible API.

Efficient Execution and Optimization

To maximize performance, HybridFlow addresses the two primary bottlenecks in RLHF: model placement and the transition between generation and training phases.

Auto-Mapping and Placement

Selecting the optimal distribution of models across a GPU cluster is a combinatorial challenge. HybridFlow includes an automated mapping tool that simulates various placement and parallelism strategies to identify the configuration that minimizes end-to-end latency. This often leads to "splitting" models across different GPU sets rather than simple colocation, which can significantly improve throughput on large clusters.

The mapping process from a logical dataflow graph to physical execution patterns across multiple machines.

3D-HybridEngine

The Actor model creates a unique bottleneck as it switches between a memory-bound generation phase and a compute-bound training phase. HybridFlow’s 3D-HybridEngine performs "zero-redundancy" weight resharding. By intelligently overlapping training and generation weights on the same GPUs, it eliminates memory waste and reduces transition communication time by up to 89%.

Experimental Results

HybridFlow was evaluated using Llama models ranging from 7B to 70B parameters on the "Dahoas/ful-hh-rlhf" dataset. The framework demonstrated massive speedups over state-of-the-art baselines like DeepSpeed-Chat, OpenRLHF, and NeMo-Aligner. For 70B models, HybridFlow achieved 5x to 18x higher throughput than existing systems, proving its scalability and efficiency in large-scale alignment tasks.

Conclusion

HybridFlow provides a robust and high-performance solution for the evolving needs of LLM alignment. By decoupling the control plane from the data plane and introducing specialized engines for model resharding, it enables both rapid algorithmic iteration and industry-leading execution efficiency. Future work will focus on extending the auto-mapping algorithm to heterogeneous hardware and exploring spatial sharing for even finer-grained GPU utilization.

Summary updated

BibTeX
@inproceedings{sheng2024hybridflow,
  author = {Guangming Sheng and Chi Zhang and Zilingfeng Ye and Xibin Wu and Wang Zhang and Ru Zhang and Yanghua Peng and Haibin Lin and Chuan Wu},
  title = {{HybridFlow: A Flexible and Efficient RLHF Framework}},
  booktitle = {EuroSys},
  year = {2024},
  doi = {10.1145/3689031.3696075},
}
Figure