# qihoo360/360-llama-factory architecture

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

- Interactive diagram: https://gitdiagram.com/qihoo360/360-llama-factory
- Repository: https://github.com/qihoo360/360-llama-factory

## Overview

##### Main Components

a. Core Components:
- Training Pipeline
- Model Management
- Data Processing
- Sequence Parallelism Engine
- Evaluation System
- API/WebUI Interface

b. Key Integrations:
- DeepSpeed Integration
- Ring Flash Attention
- External Model Support (LLaMA, Qwen, etc.)

**User Interface Layer**
- CLI Interface
- Web UI
- API Endpoints

**Training & Inference Layer**
- Training Workflows (SFT, DPO, PPO, KTO)
- Sequence Parallelism Controller
- Model Management System

**Core Infrastructure Layer**
- Data Processing Pipeline
- Model Architecture
- Distributed Computing Framework

##### Key Relationships to Highlight

a. Sequence Parallelism Flow:
- How data is split across GPUs
- Zigzag-ring attention pattern
- Demonstrate the communication pattern between GPU nodes

b. Training Pipeline:
- Data preprocessing flow
- Model training flow
- Evaluation feedback loop

##### Specific Implementation Details

a. Sequence Parallelism Implementation:
**SP Controller**
- Data Splitting
- Ring Flash Attention
- Loss Computation

b. Training Modes:
**Training Methods**
- Full Parameter Training
- LoRA Training
- QLoRA Training

##### Technical Specifications

A technical specifications panel showing:
- Supported sequence lengths
- GPU configurations
- Memory requirements
- Supported model sizes

##### Integration Points

Clear integration points with:
- DeepSpeed
- Hugging Face Transformers
- Ring Flash Attention
- External model repositories

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        CLI["CLI Interface"]
        WebUI["Web UI"]
        API["API Endpoints"]
    end

    subgraph TI["Training & Inference Layer"]
        direction TB
        subgraph TW["Training Workflows"]
            SFT["SFT Training"]
            DPO["DPO Training"]
            PPO["PPO Training"]
            KTO["KTO Training"]
        end

        subgraph SP["Sequence Parallelism"]
            SPC["SP Controller"]
            DS["Data Splitting"]
            RFA["Ring Flash Attention"]
            LC["Loss Computation"]
        end

        subgraph MM["Model Management"]
            MA["Model Architecture"]
            CP["Checkpointing"]
            QT["Quantization"]
            AT["Attention Mechanism"]
        end
    end

    subgraph CI["Core Infrastructure Layer"]
        subgraph DP["Data Processing Pipeline"]
            DC["Data Collation"]
            DF["Data Formatting"]
            DL["Data Loading"]
        end

        subgraph DCF["Distributed Computing"]
            DS_INT["DeepSpeed Integration"]
            HF["HuggingFace Integration"]
        end
    end

    subgraph EV["Evaluation System"]
        EM["Evaluation Metrics"]
        FB["Feedback Loop"]
    end

    %% Relationships
    CLI --> TW
    WebUI --> TW
    API --> TW
    
    TW --> SP
    SP --> MM
    MM --> DP
    
    SP --> DCF
    DCF --> EV
    EV --> TW

    %% Click Events
    click CLI "https://github.com/Qihoo360/360-LLaMA-Factory/blob/sp/src/llamafactory/cli.py"
    click WebUI "https://github.com/Qihoo360/360-LLaMA-Factory/tree/sp/src/llamafactory/webui/"
    click API "https://github.com/Qihoo360/360-LLaMA-Factory/tree/sp/src/llamafactory/api/"
    click SFT "https://github.com/Qihoo360/360-LLaMA-Factory/tree/sp/src/llamafactory/train/sft/"
    click DPO "https://github.com/Qihoo360/360-LLaMA-Factory/tree/sp/src/llamafactory/train/dpo/"
    click PPO "https://github.com/Qihoo360/360-LLaMA-Factory/tree/sp/src/llamafactory/train/ppo/"
    click KTO "https://github.com/Qihoo360/360-LLaMA-Factory/tree/sp/src/llamafactory/train/kto/"
    click SPC "https://github.com/Qihoo360/360-LLaMA-Factory/blob/sp/src/llamafactory/model/model_utils/sequence_parallel.py"
    click AT "https://github.com/Qihoo360/360-LLaMA-Factory/blob/sp/src/llamafactory/model/model_utils/attention.py"
    click CP "https://github.com/Qihoo360/360-LLaMA-Factory/blob/sp/src/llamafactory/model/model_utils/checkpointing.py"
    click QT "https://github.com/Qihoo360/360-LLaMA-Factory/blob/sp/src/llamafactory/model/model_utils/quantization.py"
    click DC "https://github.com/Qihoo360/360-LLaMA-Factory/blob/sp/src/llamafactory/data/collator.py"
    click DF "https://github.com/Qihoo360/360-LLaMA-Factory/blob/sp/src/llamafactory/data/formatter.py"
    click DL "https://github.com/Qihoo360/360-LLaMA-Factory/blob/sp/src/llamafactory/data/loader.py"
    click EV "https://github.com/Qihoo360/360-LLaMA-Factory/tree/sp/src/llamafactory/eval/"
    click MM "https://github.com/Qihoo360/360-LLaMA-Factory/tree/sp/src/llamafactory/model/"
    click DP "https://github.com/Qihoo360/360-LLaMA-Factory/tree/sp/src/llamafactory/data/"

    classDef default fill:#ddd,stroke:#000,stroke-width:1px
    classDef ui fill:#b3e0ff,stroke:#000
    classDef training fill:#ffb366,stroke:#000
    classDef sp fill:#d1c4e9,stroke:#000
    classDef data fill:#90EE90,stroke:#000
    classDef eval fill:#FFB6C1,stroke:#000
    classDef model fill:#DDA0DD,stroke:#000

    class CLI,WebUI,API ui
    class SFT,DPO,PPO,KTO training
    class SPC,DS,RFA,LC sp
    class DC,DF,DL data
    class EM,FB eval
    class MA,CP,QT,AT model
```
