# yc1999/llm2 architecture

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

- Interactive diagram: https://gitdiagram.com/yc1999/llm2
- Repository: https://github.com/yc1999/llm2

## Overview

Key Components to Include:

##### Main System Architecture
a. System 1 (LLM Component)
b. System 2 (Verifier Component)

##### Data Flow Components
- Input Processing Layer
- How the input data flows from datasets (./dataset/*.jsonl)
- Data preprocessing utilities (data_utils.py)

- Training Pipeline
- Verifier Training Module (train_verifier.py, verifier_trainer.py)
- Model Utils (model_utils.py)
- Configuration Management (configs.py)

- Inference Pipeline
- Inference Engine (inference.py)
- Verification Search (verify_search.py)
- Evaluation Module (evaluation.py)

##### Supporting Components
- Benchmarking System (benchmarks/)
- Configuration Management (config_files/)
- Utility Services (utils_stopping.py, modeling_attn_mask_utils.py)

##### Use a top-down approach with the following layers
- [Input Layer]
- ↓
- [Processing Layer]
- ↓
- [Core System Layer (System 1 & 2)]
- ↓
- [Output Layer]

##### Specific connection points
- How the LLM generates candidates
- Verifier's feedback loop
- Demonstrate the token quality exploration strategy
- Pairwise comparison mechanism

##### Technical Details
- Data formats (JSONL structure)
- Evaluation paths (GSM8k benchmark)

Specific Guidelines:

##### Bidirectional nature of the system
- LLM's candidate generation
- Verifier's feedback mechanism
- Token quality exploration

##### Clear separation between
- Training pipeline
- Inference pipeline
- Evaluation system

##### Configuration management
- How different config files affect system behavior
- Accelerator configurations (Zero3, etc.)

##### Data flow
- Input processing
- Token sampling
- Verification process
- Final output generation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        LLM[LLM Component]:::llm
        VER[Verifier Component]:::verifier
        DATA[Data Processing]:::data
        UTIL[Utility Services]:::utility
        style Legend fill:#f0f0f0,stroke:#333
    end

    subgraph "Input Layer"
        InputData["Dataset Files"]:::data
        click InputData "https://github.com/yc1999/LLM2/tree/main/dataset/"
        DataUtils["Data Utils"]:::data
        click DataUtils "https://github.com/yc1999/LLM2/blob/main/data_utils.py"
        BuildData["Build Data"]:::data
        click BuildData "https://github.com/yc1999/LLM2/blob/main/build_data.py"
        BuildBatch["Build Data Batch"]:::data
        click BuildBatch "https://github.com/yc1999/LLM2/blob/main/build_data_batch.py"
    end

    subgraph "Core Systems"
        subgraph "System 1"
            LLMSystem["Large Language Model"]:::llm
            ModelData["Model Variants"]:::llm
            click ModelData "https://github.com/yc1999/LLM2/tree/main/dataset/"
        end

        subgraph "System 2"
            VerifierComponent["Verifier"]:::verifier
            click VerifierComponent "https://github.com/yc1999/LLM2/blob/main/verifier.py"
            VerifierTrainer["Verifier Trainer"]:::verifier
            click VerifierTrainer "https://github.com/yc1999/LLM2/blob/main/verifier_trainer.py"
            TrainVerifier["Train Verifier"]:::verifier
            click TrainVerifier "https://github.com/yc1999/LLM2/blob/main/train_verifier.py"
        end
    end

    subgraph "Processing Layer"
        InferenceEngine["Inference Engine"]:::llm
        click InferenceEngine "https://github.com/yc1999/LLM2/blob/main/inference.py"
        VerifySearch["Verification Search"]:::verifier
        click VerifySearch "https://github.com/yc1999/LLM2/blob/main/verify_search.py"
        Evaluation["Evaluation"]:::utility
        click Evaluation "https://github.com/yc1999/LLM2/blob/main/evaluation.py"
    end

    subgraph "Support Systems"
        ConfigMgmt["Configuration Management"]:::utility
        click ConfigMgmt "https://github.com/yc1999/LLM2/blob/main/configs.py"
        ConfigFiles["Config Files"]:::utility
        click ConfigFiles "https://github.com/yc1999/LLM2/tree/main/config_files/"
        Benchmarks["Benchmarking System"]:::utility
        click Benchmarks "https://github.com/yc1999/LLM2/tree/main/benchmarks/"
        Utils["Utility Services"]:::utility
        click Utils "https://github.com/yc1999/LLM2/blob/main/utils_stopping.py"
        ModelUtils["Model Utils"]:::utility
        click ModelUtils "https://github.com/yc1999/LLM2/blob/main/model_utils.py"
        MaskUtils["Attention Mask Utils"]:::utility
        click MaskUtils "https://github.com/yc1999/LLM2/blob/main/modeling_attn_mask_utils.py"
    end

    InputData --> DataUtils
    DataUtils --> BuildData
    BuildData --> BuildBatch
    BuildBatch --> LLMSystem

    LLMSystem --> InferenceEngine
    ModelData --> LLMSystem
    InferenceEngine --> VerifySearch
    VerifySearch --> VerifierComponent
    VerifierComponent --> Evaluation

    ConfigMgmt --> LLMSystem
    ConfigMgmt --> VerifierComponent
    ConfigFiles --> ConfigMgmt
    Utils --> InferenceEngine
    ModelUtils --> LLMSystem
    MaskUtils --> LLMSystem
    Benchmarks --> Evaluation

    VerifierTrainer --> VerifierComponent
    TrainVerifier --> VerifierTrainer

    classDef llm fill:#b3d9ff,stroke:#333
    classDef verifier fill:#b3ffb3,stroke:#333
    classDef data fill:#ffffb3,stroke:#333
    classDef utility fill:#e6e6e6,stroke:#333
```
