# rm-r1-uiuc/rm-r1 architecture

> Architecture diagram of the GitHub repository rm-r1-uiuc/rm-r1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rm-r1-uiuc/rm-r1
- Repository: https://github.com/rm-r1-uiuc/rm-r1

## Overview

##### Project type and purpose
- RM-R1 is an open-source machine-learning pipeline/tool for **Reward Modeling as Reasoning**. It provides end-to-end scripts for distillation (SFT) and reinforcement learning (RLVR), a unified evaluation harness, dataset generation utilities, and a Python library (OpenRLHF) exposing CLI commands and core modules (datasets, models, trainers, utils).

##### File structure
- Top-level:
- README, figures/ (asset for the paper)
- rm_r1/ (project root containing OpenRLHF library, dataset code, orchestration scripts)
– OpenRLHF/ (Python package)
· cli/ – entry-point scripts for inference & training
· datasets/ – data-loading & processing
· models/ – actor, loss, base model abstraction
· trainer/ – implementations of PPO, DPO, KD, RM, SFT trainers + ray-based distributed training
· utils/ – deepspeed wrappers, distributed utils, logging, remote RM helper
· Dockerfile & workflow for packaging
– dataset/ – standalone scripts for mixing data & generating reasoning chains
– scripts/ – shell scripts (Distill & RLVR) for local and Slurm runs
– verl/ – pinned veRL code & configs
- Configuration files: pyproject.toml, setup.py, requirements.txt, trainer YAML config

##### README for additional insights
- Two-stage pipeline: (1) Distillation (SFT) via OpenRLHF; (2) RL fine-tuning (RLVR) via veRL + vLLM + Flash-Attention.
- External dependencies: pinned commits of veRL & vLLM, flash-attention.
- Support for multi-node/multi-GPU via Ray, Slurm, deepspeed.

– User / Developer (CLI & scripts)
– Orchestration layer (shell scripts under rm_r1/scripts/)
– Container / Environment (Conda env, Docker)
– OpenRLHF Python library
- CLI submodule
- Dataset module
- Model module
- Trainer module (local and Ray-based)
- Utility module (deepspeed, distributed)
– External frameworks & libraries
- veRL (reinforcement learning framework)
- vLLM + Flash-Attention (efficient LLM serving)
- Ray (distributed execution)
- Slurm (cluster scheduler)
– Data stores
- Raw datasets (mixed + reasoning chains)
- Checkpoints & metadata directory
- Logs & metrics (Tensorboard, WandB)
– Output artifacts
- Trained reward model
- Evaluation reports

– User triggers shell scripts → launches Python CLI → calls OpenRLHF library
– CLI invokes dataset processing → loads data from rm_r1/dataset or Hugging Face
– Trainer module orchestrates training:
· Local: uses deepspeed / PyTorch
· Distributed: uses Ray actors + vLLM engine
· veRL abstractions wrap around trainer to implement RLVR algorithms
– Model module is loaded by trainer, computes forward/backward, uses Flash-Attention kernel
– Output checkpoints written to SAVE_MODEL_PATH / SAVE_META_DIR
– Evaluation harness consumes checkpoints → produces benchmarks performance

c. Architectural patterns & design principles
– **Modular CLI library**: clear separation of entry points (train_ppo, serve_rm, batch_inference)
– **Separation of concerns**: dataset, model, trainer, utils each in own package
– **Two-stage pipeline**: distillation → RL fine-tuning
– **Pluggable backends**: local, Ray distributed, Slurm
– **Containerization**: reproducible Docker image + Conda environments

d. Key technologies/frameworks
– Python3.11, Conda
– OpenRLHF (custom library)
– veRL (RL framework)
– vLLM + Flash-Attention (LLM inference speed)
– Ray (distributed actors)
– Slurm (scheduler)
– Docker (packaging)
– Hugging Face Datasets & Models

##### Detail
- Both **static structure** (packages & modules) and **dynamic flow** (pipeline execution).
- Do not over-simplify—break the system into as many logical components as needed to expose:
- entry points (CLI scripts)
- pipeline stages (Distill vs RLVR)
- distributed vs local execution
- data sources & sinks
- external frameworks

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Orchestration Layer
    subgraph "Orchestration Layer"
        direction TB
        User["User/Developer"]:::external
        Scripts["rm_r1/scripts (Distill & RLVR)"]:::orchestration
    end

    %% Environment Layer
    Container["Container/Env (Docker & Conda)"]:::env

    %% Core Library
    subgraph "OpenRLHF Library"
        direction TB
        CLI["CLI Entry Points"]:::orchestration
        Dataset["Dataset Module"]:::core
        Model["Model Module"]:::core
        Trainer["Trainer Module"]:::core
        Utils["Utility Module"]:::core
    end

    %% External Frameworks
    subgraph "External Frameworks"
        direction TB
        veRL["veRL Framework"]:::external
        vLLM["vLLM + Flash-Attention"]:::external
        Ray["Ray Distributed"]:::external
        Slurm["Slurm Scheduler"]:::external
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        RawData["Raw Datasets"]:::data
        Checkpoints["Checkpoints & Metadata"]:::data
        Logs["Logs & Metrics"]:::data
    end

    %% Output Artifacts
    subgraph "Outputs"
        direction TB
        RewardModel["Trained Reward Model"]:::data
        Reports["Evaluation Reports"]:::data
    end

    %% Connections
    User -->|triggers| Scripts
    Scripts -->|launches| CLI
    CLI -->|runs within| Container
    Container -->|imports| CLI
    CLI -->|calls| Dataset
    CLI -->|calls| Trainer
    Dataset -->|loads data from| RawData
    Trainer -->|loads| Model
    Trainer -->|uses| Utils
    Trainer -->|local execution| Container
    Trainer -->|distributed execution| Ray
    Ray -->|schedules jobs via| Slurm
    Trainer -->|integrates| veRL
    Model -->|inference kernel| vLLM
    Trainer -->|writes| Checkpoints
    Trainer -->|logs to| Logs
    Reports -->|consumes| Checkpoints
    Reports -->|outputs| EvaluationReports

    %% Click Events
    click Scripts "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/scripts/"
    click CLI "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/OpenRLHF/openrlhf/cli/"
    click Dataset "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/OpenRLHF/openrlhf/datasets/"
    click Model "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/OpenRLHF/openrlhf/models/"
    click Trainer "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/OpenRLHF/openrlhf/trainer/"
    click Utils "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/OpenRLHF/openrlhf/utils/"
    click RawData "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/dataset/"
    click veRL "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/verl/"
    click Docker "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/OpenRLHF/dockerfile/"
    click python-workflow "https://github.com/rm-r1-uiuc/rm-r1/blob/main/rm_r1/OpenRLHF/.github/workflows/python-package.yml"
    click config-files "https://github.com/rm-r1-uiuc/rm-r1/blob/main/rm_r1/OpenRLHF/pyproject.toml"
    click examples "https://github.com/rm-r1-uiuc/rm-r1/tree/main/rm_r1/OpenRLHF/examples/scripts/"
    click customReward "https://github.com/rm-r1-uiuc/rm-r1/blob/main/rm_r1/OpenRLHF/custom_reward_function.py"
    click version "https://github.com/rm-r1-uiuc/rm-r1/blob/main/rm_r1/OpenRLHF/version.txt"

    %% Styles
    classDef orchestration fill:#c2f0c2,stroke:#2d662d;
    classDef core fill:#cce5ff,stroke:#335d9e;
    classDef external fill:#ffd9b3,stroke:#bf7f00;
    classDef data fill:#e6e6e6,stroke:#7a7a7a;
    classDef env fill:#e5ccff,stroke:#6b33a2;
    class User external;
    class Scripts orchestration;
    class Container env;
    class CLI orchestration;
    class Dataset,Model,Trainer,Utils core;
    class veRL,vLLM,Ray,Slurm external;
    class RawData,Checkpoints,Logs,RewardModel,Reports data;
```
