# leaplabthu/absolute-zero-reasoner architecture

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

- Interactive diagram: https://gitdiagram.com/leaplabthu/absolute-zero-reasoner
- Repository: https://github.com/leaplabthu/absolute-zero-reasoner

## Overview

##### Project Type and Purpose
- This is an open-source reinforcement-learning research codebase for "Absolute Zero Reasoner", implementing a self-play pipeline that generates and solves reasoning tasks without external data.
- Core features include: data construction, reward computation, PPO-based training (via veRL), rollout engines (vLLM, Ray), and utilities for model conversion and logging.

##### File-Structure Analysis
- Top-level folders:
- absolute_zero_reasoner: main application modules (configs, data_construction, rewards, trainer, utils).
- data: seed datasets for self-play.
- scripts: shell wrappers for data seeding and self-play.
- verl: embedded veRL framework (trainer core, models, utilities, workers).
- tests: unit and end-to-end tests.
- Configuration files (YAML) live in configs under both absolute_zero_reasoner and verl/trainer/config.
- Entrypoints:
- main_azr_ppo.py in absolute_zero_reasoner
- scripts/selfplay/*.sh and scripts/seeding/*.sh
- conversion utility in utils/convert2hf.py
- External integrations: vLLM for rollout, Ray for distributed training, Weights & Biases for logging, Hugging Face for model conversion.

##### Architecture Overview
a. Main Components
1. Seed Data Loader
2. Task Constructor (absolute_zero_reasoner/data_construction)
3. Rollout Engine
– vLLM rollout (verl/third_party/vllm or utils/python_executor)
– Ray-based actor–critic rollout (verl/workers)
4. Reward Manager (absolute_zero_reasoner/rewards + verl/workers/reward_manager)
5. PPO Trainer (absolute_zero_reasoner/trainer/ppo + verl/trainer)
6. Model Store & Conversion (absolute_zero_reasoner/utils/convert2hf)
7. Logging & Tracking (absolute_zero_reasoner/utils/logging_utils + W&B)
8. Config Manager (YAML files feeding into each component)
b. Relationships & Data Flow
1. Seed data → Task Constructor → Generated tasks
2. Generated tasks → Rollout Engine → Model outputs (proposals/solutions)
3. Model outputs → Python Executor (validation/parsing) → Reward Manager
4. Reward signals → PPO Trainer → Model parameter updates
5. Trainer checkpoints → Model Store → Conversion to Hugging Face format
6. Throughout: metrics → Logging & W&B
c. Architectural Patterns & Principles
- Modular pipeline: clearly separated data construction, rollout, reward, and training stages.
- Plugin-style reward and rollout: custom reward functions and multiple rollout backends (naive, vLLM, Ray).
- Distributed training via Ray and low-level veRL abstractions (actors, workers, sharding).
- Configuration-driven: behaviors controlled by YAML under configs directories.
d. Key Technologies & Frameworks
- Python 3.10, PyTorch
- veRL (verl/) for training loop and distributed workers
- vLLM for fast batched language model rollouts
- Ray for distributed task scheduling
- Weights & Biases for experiment tracking
- Hugging Face Transformers for model format conversions
- YAML for configuration

##### Essential Elements
- Clear component labels (e.g., “Task Constructor”, “Reward Manager”)
- Data stores (seed datasets, checkpoints)
- Callouts for external services (W&B, Hugging Face, Ray, vLLM)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data & Config Layer
    subgraph "Data & Config"
        direction TB
        SD["Seed Dataset"]:::dataStore
        SDL["Seed Data Loader"]:::process
        CM1["AZR Config"]:::config
        CM2["veRL Config"]:::config
    end

    %% Generation & Rollout Layer
    subgraph "Generation & Rollout"
        direction TB
        TC["Task Constructor"]:::process
        RE["Rollout Engine"]:::compute
        subgraph "Rollout Backends"
            direction TB
            VLLM["vLLM Rollout"]:::process
            VLLM_SPMD["vLLM SPMD"]:::process
            NAIVE["Naive/Ray Rollout"]:::process
        end
        PE["Python Executor"]:::process
    end

    %% Reward & Validation Layer
    subgraph "Reward & Validation"
        direction TB
        RM["Reward Manager"]:::validation
    end

    %% Training & Model Management Layer
    subgraph "Training & Model Management"
        direction TB
        PT["PPO Trainer"]:::training
        MS["Model Store"]:::dataStore
        MC["Conversion Utility"]:::training
    end

    %% External Services
    LB["Logging & Tracking"]:::external
    HF["Hugging Face"]:::external

    %% Data Flow
    SD -->|"seed_data"| SDL
    SDL -->|"tasks"| TC
    CM1 --> SDL
    CM1 --> TC
    CM2 --> PT
    CM2 --> RE

    TC -->|"tasks"| RE
    RE --> VLLM
    RE --> VLLM_SPMD
    RE --> NAIVE
    RE -->|"model_outputs"| PE

    PE -->|"parsed_outputs"| RM

    RM -->|"reward_signals"| PT

    PT -->|"checkpoints"| MS
    MS --> MC

    %% Iterative Loop
    PT -->|"updated_parameters"| RE

    %% Logging Arrows
    SDL --> LB
    TC --> LB
    RE --> LB
    PE --> LB
    RM --> LB
    PT --> LB
    MS --> LB

    %% External Services Connections
    MC --> HF

    %% Click Events
    click SDL "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/absolute_zero_reasoner/data_construction/process_data.py"
    click TC "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/absolute_zero_reasoner/data_construction/constructor.py"
    click VLLM "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/verl/verl/workers/rollout/vllm_rollout/vllm_rollout.py"
    click VLLM_SPMD "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/verl/verl/workers/rollout/vllm_rollout/vllm_rollout_spmd.py"
    click NAIVE "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/verl/verl/workers/rollout/naive/naive_rollout.py"
    click PE "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/absolute_zero_reasoner/utils/code_utils/python_executor.py"
    click RM "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/absolute_zero_reasoner/rewards/reward_managers.py"
    click PT "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/absolute_zero_reasoner/trainer/ppo/azr_ray_trainer.py"
    click MS "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/absolute_zero_reasoner/utils/convert2hf.py"
    click LB "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/absolute_zero_reasoner/utils/logging_utils/stdout.py"
    click CM1 "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/absolute_zero_reasoner/configs/azr_ppo_trainer.yaml"
    click CM2 "https://github.com/leaplabthu/absolute-zero-reasoner/blob/master/verl/verl/trainer/config/ppo_trainer.yaml"
    click SD "https://github.com/leaplabthu/absolute-zero-reasoner/tree/master/data/"

    %% Styles
    classDef dataStore fill:#ADD8E6,stroke:#000;
    classDef process fill:#ADD8E6,stroke:#000;
    classDef config fill:#ADD8E6,stroke:#000;
    classDef compute fill:#90EE90,stroke:#000;
    classDef validation fill:#FFA500,stroke:#000;
    classDef training fill:#DDA0DD,stroke:#000;
    classDef external fill:#D3D3D3,stroke:#000;
```
