# zhentingqi/rstar architecture

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

- Interactive diagram: https://gitdiagram.com/zhentingqi/rstar
- Repository: https://github.com/zhentingqi/rstar

## Overview

##### Main Components

a) Core Processing Components:
- Generator System (MCTS-based)
- Discriminator System
- Evaluation System

b) Data Management:
- Dataset Handler
- Prompt Management System
- Model Interface Layer

c) External Integrations:
- LLM APIs (HuggingFace, OpenAI, vLLM)

**┌─ Input Layer ─────┐**
- Math Problems   │
- Datasets       │
- ┘

**┌─ Generator Module ──┐    ┌─ Discriminator Module ─┐**
- MCTS Backbone    │───>│ - Verification Logic   │
- Action Space     │<───│ - Mutual Consistency   │
- ┘    └────────────────────────┘

**┌─ Model Interface Layer ─┐**
- HuggingFace API      │
- OpenAI API           │
- vLLM API            │
- ┘

##### Specific Implementation Details

a) Generator Component:
- MCTS backbone integration
- Reasoning action space
- Solution trajectory construction

b) Discriminator Component:
- Verification mechanisms
- Mutual consistency checking
- Feedback loop to generator

c) Support Systems:
- Prompt management for different datasets
- Evaluation toolkit
- Model API abstractions

##### Technical Stack Indicators

Technology badges for:
- Python 3.10
- CUDA 12
- PyTorch
- Transformers
- vLLM

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        IP[Math Problems]
        DS[Datasets]:::dataset
    end

    subgraph "Core Processing"
        subgraph "Generator System"
            MCTS[MCTS Backbone]:::generator
            ACT[Action Space]:::generator
            GEN[Solution Generator]:::generator
        end

        subgraph "Discriminator System"
            VER[Verification Logic]:::discriminator
            CON[Consistency Checker]:::discriminator
        end

        subgraph "Evaluation System"
            EVAL[Evaluator]:::evaluator
            TOOL[Evaluation Toolkit]:::evaluator
        end
    end

    subgraph "Data Management"
        DHD[Dataset Handler]:::data
        PMS[Prompt Management]:::data
    end

    subgraph "Model Interface Layer"
        HF[HuggingFace API]:::api
        OAI[OpenAI API]:::api
        VLLM[vLLM API]:::api
        IO[IO System]:::api
    end

    IP --> DHD
    DS --> DHD
    DHD --> MCTS
    PMS --> MCTS
    PMS --> VER

    MCTS --> ACT
    ACT --> GEN
    GEN --> VER
    VER --> CON
    CON --> MCTS
    VER --> EVAL
    EVAL --> TOOL

    GEN --> HF
    GEN --> OAI
    GEN --> VLLM
    VER --> HF
    VER --> OAI
    VER --> VLLM
    
    HF --> IO
    OAI --> IO
    VLLM --> IO

    %% Click events for component mapping
    click MCTS "https://github.com/zhentingqi/rStar/blob/main/run_src/MCTS_backbone.py"
    click GEN "https://github.com/zhentingqi/rStar/blob/main/run_src/do_generate.py"
    click VER "https://github.com/zhentingqi/rStar/blob/main/run_src/do_discriminate.py"
    click EVAL "https://github.com/zhentingqi/rStar/blob/main/eval_src/Evaluator.py"
    click TOOL "https://github.com/zhentingqi/rStar/tree/main/eval_src/toolkit_for_MATH/"
    click DHD "https://github.com/zhentingqi/rStar/tree/main/data/"
    click PMS "https://github.com/zhentingqi/rStar/tree/main/prompts/"
    click HF "https://github.com/zhentingqi/rStar/blob/main/models/HuggingFace_API.py"
    click OAI "https://github.com/zhentingqi/rStar/blob/main/models/OpenAI_API.py"
    click VLLM "https://github.com/zhentingqi/rStar/blob/main/models/vLLM_API.py"
    click IO "https://github.com/zhentingqi/rStar/blob/main/models/IO_System.py"

    %% Styling
    classDef generator fill:#2374f7,stroke:#fff,stroke-width:2px,color:#fff
    classDef discriminator fill:#1750ad,stroke:#fff,stroke-width:2px,color:#fff
    classDef evaluator fill:#0a2657,stroke:#fff,stroke-width:2px,color:#fff
    classDef data fill:#47d147,stroke:#fff,stroke-width:2px,color:#fff
    classDef api fill:#ff8533,stroke:#fff,stroke-width:2px,color:#fff
    classDef dataset fill:#cccccc,stroke:#fff,stroke-width:2px,color:#000

    %% Legend
    subgraph Legend
        L1[Generator Components]:::generator
        L2[Discriminator Components]:::discriminator
        L3[Evaluator Components]:::evaluator
        L4[Data Management]:::data
        L5[Model Interface]:::api
        L6[Datasets]:::dataset
    end
```
