# inclusionai/areal architecture

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

- Interactive diagram: https://gitdiagram.com/inclusionai/areal
- Repository: https://github.com/inclusionai/areal

## Overview

##### Main Components and Their Roles
- Core RL Training Pipeline:
- Located primarily in the “realhf” directory, this module contains subcomponents for the API, base utilities, experiments (training recipes), and implementations for model backends (e.g., Megatron, VLLM) including specialized support for parallelism (model and pipeline parallel).
- Also includes dedicated directories for scheduling (“realhf/scheduler”) and system management (“realhf/system”) that orchestrate distributed training, task distribution, and resource monitoring.
- Performance and Accelerator Components:
- “csrc” holds C++/CUDA implementations (such as “cugae” and “interval_op”) that optimize lower-level operations and possibly enhance throughput for compute-intensive tasks.
- The “functioncall” directory provides components for function handling, logging, and verification—key in managing code execution, function call tracing, and ensuring robustness during training or evaluation.
- Evaluation Framework:
- The “evaluation” directory comprises multiple scripts and submodules for dataset processing, model evaluation (with different benchmark datasets like AIME and GPQA), and results aggregation.
- It also contains separate modules for transforming LaTeX to symbolic representations, indicating support for math reasoning evaluation.
- Examples and Configurations:
- The “examples” folder provides configuration templates and quick-start scripts, which guide users in setting up training with various model sizes (1.5B, 7B, 32B).
- External Interfaces and APIs:
- The “realhf/api” subdirectories (including “quickstart” and “from_hf”) indicate interfaces for integrating with external models/datasets (like those on Hugging Face) and provide utility functions for launching training or inference jobs.

##### Relationships and Interactions
- The system is modular and layered:
- The frontend (command line entry points from “realhf/api/quickstart” and “examples”) acts as a user interface to trigger training jobs.
- The training and model-execution layer (in “realhf/impl/model” and related “backend” files) processes the core algorithms for RL-based training.
- Underlying these, accelerator and performance modules (“csrc”, “functioncall”) provide optimized primitives.
- Distributed control and scheduling are handled through “realhf/system”, “realhf/scheduler”, and related modules, which communicate with various backend training processes.
- Evaluation utilities (in “evaluation”) tap into outputs from training and perform benchmarking and correctness evaluation.
- Data and configuration flow:
- Training configurations (YAML files in “examples/configs”) and launch scripts share parameters with the training components via APIs.
- Data flows from dataset loading (possibly using components both in “evaluation/data” and “realhf/impl/dataset”) to processing pipelines and then to training and evaluation routines.

##### Architectural Patterns and Design Principles
- Modularity and separation of concerns: Different directories are responsible for specific functions – training logic, evaluation, C++/CUDA acceleration, distributed scheduling, and API interfacing.
- Layered architecture: A high-level API layer (CLI entry points) interacts with a distributed resource management layer (scheduler/system), which in turn calls into performance-sensitive components (csrc, functioncall) and model implementations.
- Extensibility: The structure (especially in realhf/impl, experiments, and API subdirectories) suggests that the system is designed to easily integrate additional RL recipes, model types, or new domains (e.g., coding or vision-language models, as mentioned in the roadmap).
- Distributed and parallel processing: With clear separation into modules for model parallelism and pipeline parallelism, along with scheduler modules for local, SLURM, and potentially cloud-based clusters.

##### Relevant Technologies, Frameworks, and Libraries
- CUDA and C++ for performance-critical operations (“csrc” directory).
- Python and modern tooling (as evidenced by setup.py, pyproject.toml, Makefile) for orchestration and experimentation.
- Use of YAML configuration files (in “examples/configs”) for specifying training parameters.
- Integration with external repositories and third-party projects (e.g., Hugging Face models, SGLang, Megatron, VLLM).

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Frontend Layer"
        A["API/Quickstart"]:::frontend
        B["Examples"]:::frontend
        EC["Configuration Files"]:::frontend
    end

    subgraph "Distributed Orchestration"
        C["Distributed Scheduler"]:::orchestration
        D["System Manager"]:::orchestration
    end

    subgraph "Training Engine"
        E["Core RL Pipeline"]:::training
        F["Model Training & Parallelism"]:::training
    end

    subgraph "Performance Optimization"
        G["Accelerator Kernels"]:::accelerator
        H["Function Call & Logging"]:::accelerator
    end

    subgraph "Evaluation Layer"
        I["Evaluation Engine"]:::evaluation
    end

    %% Frontend triggers Distributed Orchestration
    A --> C
    A --> D
    B --> C
    B --> D

    %% Distributed Orchestration invokes Training Engine
    C --> E
    C --> F
    D --> E
    D --> F

    %% Integration within Training Engine
    E -->|"integrates"| F

    %% Configuration injection from Examples to Training
    EC --> F

    %% Training Engine depends on Performance Optimization
    F --> G
    F --> H

    %% Training results are passed to Evaluation Layer
    E --> I
    F --> I

    %% Styles
    classDef frontend fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef orchestration fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef training fill:#CCCCFF,stroke:#333,stroke-width:2px;
    classDef accelerator fill:#FF99CC,stroke:#333,stroke-width:2px;
    classDef evaluation fill:#CCFFFF,stroke:#333,stroke-width:2px;

    %% Click Events
    click A "https://github.com/inclusionai/areal/tree/main/realhf/api"
    click B "https://github.com/inclusionai/areal/tree/main/examples"
    click EC "https://github.com/inclusionai/areal/tree/main/examples/configs"
    click C "https://github.com/inclusionai/areal/tree/main/realhf/scheduler"
    click D "https://github.com/inclusionai/areal/tree/main/realhf/system"
    click E "https://github.com/inclusionai/areal/tree/main/realhf"
    click F "https://github.com/inclusionai/areal/tree/main/realhf/impl/model"
    click G "https://github.com/inclusionai/areal/tree/main/csrc"
    click H "https://github.com/inclusionai/areal/tree/main/functioncall"
    click I "https://github.com/inclusionai/areal/tree/main/evaluation"
```
