# leminhbinh0209/deepsick-r1 architecture

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

- Interactive diagram: https://gitdiagram.com/leminhbinh0209/deepsick-r1
- Repository: https://github.com/leminhbinh0209/deepsick-r1

## Overview

##### Main Components
- Entrypoint & Environment Setup: The launch process begins with the train.sh script. This script sets the appropriate GPU environment variables (e.g., CUDA_VISIBLE_DEVICES) and uses the Accelerate launcher configured with DeepSpeed (using ds_accel.yaml) to run the training.
- Training Execution: The main.py file acts as the primary training script. It is responsible for orchestrating the training workflow.
- Training Logic: The trainer.py contains the core training routines – encapsulated training loops, model updates and integration with DeepSpeed’s ZeRO3 optimization.
- Utility Functions: The utils.py file supplies helper functions, which might include data handling, logging, metrics, or other auxiliary tasks.
- vLLM Inference Component: Although not a separate file, the repository integrates vLLM (a library for rapid answer generation) by dedicating one GPU solely to inference, while other GPUs focus on training.
- Distributed Training Configuration: The ds_accel.yaml config file is used by DeepSpeed and Accelerate to manage multi-GPU training, ensuring proper distribution and communication between training GPUs and the GPU running vLLM for inference.

##### Relationships and Interactions
- The train.sh script is the first component executed. It sets up the GPU allocation and then calls the accelerate launcher (with the ds_accel.yaml configuration) to execute main.py.
- Within main.py, the training workflow is initialized. It likely calls on trainer.py for core training functions, while utility functions from utils.py are invoked for supporting tasks (e.g., logging, data transformations).
- The DeepSpeed configuration ensures that the appropriate number of GPUs is used. The separation of one GPU for vLLM and the remaining for training should be clearly illustrated.
- External dependencies such as vLLM and DeepSpeed operate as outsourced libraries supporting inference and distributed training respectively.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each file is responsible for a distinct part of the system (script launching, training orchestration, training logic, utilities). This minimal but modular separation makes the codebase very approachable.
- Distributed and Parallel Training: Using Accelerate and DeepSpeed’s ZeRO3 for scaling and distributed training with multiple GPUs is a crucial design choice.
- Inference-Training GPU Isolation: The project explicitly separates the GPU resources for inference (vLLM) and training to avoid cross-interference—a key performance and resource management strategy.

- Including a block (or a note) that explains resource allocation – specifically, how GPUs are partitioned (one for vLLM and remaining for training).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Launch Environment"
        A["Launch Script – train.sh"]:::script
        B["Distributed Config – ds_accel.yaml"]:::config
    end

    subgraph "Training Core"
        C["Training Execution – main.py"]:::script
        D["Training Engine – trainer.py"]:::training
        E["Utility Functions – utils.py"]:::utility
    end

    F["Inference Engine – vLLM (1 GPU dedicated)"]:::inference

    A -->|"sets_GPU&launches"| B
    B -->|"invokes_training"| C
    C -->|"orchestrates"| D
    C -->|"calls"| E
    C -->|"delegates_inference"| F

    click A "https://github.com/leminhbinh0209/deepsick-r1/blob/master/train.sh"
    click B "https://github.com/leminhbinh0209/deepsick-r1/blob/master/ds_accel.yaml"
    click C "https://github.com/leminhbinh0209/deepsick-r1/blob/master/main.py"
    click D "https://github.com/leminhbinh0209/deepsick-r1/blob/master/trainer.py"
    click E "https://github.com/leminhbinh0209/deepsick-r1/blob/master/utils.py"

    classDef script fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef config fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef training fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef utility fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef inference fill:#e2e3e5,stroke:#383d41,stroke-width:2px;
```
