# tinyllava/tinyllava_factory architecture

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

- Interactive diagram: https://gitdiagram.com/tinyllava/tinyllava_factory
- Repository: https://github.com/tinyllava/tinyllava_factory

## Overview

##### Major Components
- Language Model (LLM) Module – This component includes various LLM implementations (e.g., OpenELM, TinyLlama, StableLM, Qwen, Gemma, Phi). It resides in the “tinyllava/model/llm” directory and is responsible for text generation and conversational capabilities.
- Vision Tower Module – Located under “tinyllava/model/vision_tower”, this part handles image processing. Different vision models (CLIP, SigLIP, Dino, etc.) are supported.
- Connector Module – Found in “tinyllava/model/connector”, this component integrates the outputs of the vision tower with the LLM by transforming visual representations to a form the text model can process (via MLP, Qformer, or Resampler).
- Data Processing & Templates – Under “tinyllava/data” and specifically “tinyllava/data/template”, the project defines how to format inputs and convert raw data (images and text) into training-ready sequences.
- Training & Recipes – The “tinyllava/train” and “tinyllava/training_recipe” folders hold the training pipelines, including pretraining, finetuning, and specialized recipes such as LoRA/QLoRA tuning.
- Evaluation Suite – All evaluation scripts in “tinyllava/eval” and the “scripts/eval” folder enable running benchmarks (e.g., VQA, GQA, SQA) on trained multimodal models.
- Serving & Demo – The “tinyllava/serve” folder contains the web app and CLI interfaces used for inference (Gradio-based and script-driven demos).
- Ancillary Scripts – The “scripts” folder (e.g., training and conversion scripts) provides automation for data preparation, training runs, and evaluation across different configurations.

##### Relationships and Data Flow
- Input Data Pipelines: Start with raw data preparation (images and text) that are processed by modules under “tinyllava/data” (and supported by conversion scripts under “scripts/convert_*”). Clearly label data conversion and template formatting.
- Model Training Workflow: Create a flow from data preparation → training recipes → separate pipelines for pretraining and finetuning. Show how training scripts in “scripts/train” invoke training methods in “tinyllava/train” and use modules from “tinyllava/model” (LLM, vision tower, connector) as well as utils.
- Modular Registries: Note that the project uses factory/registration mechanisms (e.g., @register_template, @register_llm, etc.). Represent these as connectors within the system design that allow plugging in additional models or modules.

##### Architectural Patterns & Design Principles
- Technology Stack: Annotate components with the frameworks/technologies they use (e.g., PyTorch for model implementations, HuggingFace for transformers and tokenizers, Gradio for demos).

##### Final Assembly
1. Data Preparation: Raw data → Preprocessing & Template Formatting (scripts + tinyllava/data)
2. Model Construction: Modular assembly of LLM, Vision Tower, and Connector (tinyllava/model submodules)
3. Training Workflow: Training recipes (tinyllava/train, training_recipe) controlled by bash/Python scripts (scripts/train)
4. Evaluation & Inference: Evaluation scripts and serving interfaces (tinyllava/eval, tinyllava/serve, tinyllava_visualizer)
- Within the “Model Construction” area, show how the connectors allow integration between text and image models, emphasizing the modular design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data and Preprocessing Layer
    subgraph "Data and Preprocessing Layer"
        RD["Raw Data"]:::data
        DP["Data Processing"]:::data
        TF["Template Formatting"]:::data
    end

    %% Training Pipeline Layer
    subgraph "Training Pipeline Layer"
        TM["Training Module"]:::training
        TR["Training Recipe"]:::training
        TS["Training Scripts"]:::training
    end

    %% Model Architecture Layer
    subgraph "Model Architecture Layer"
        LLM["Language Model (LLM) Module"]:::model
        VT["Vision Tower Module"]:::model
        CN["Connector Module"]:::model
    end

    %% Evaluation and Inference Layer
    subgraph "Evaluation and Inference Layer"
        ES["Evaluation Suite"]:::eval
        EV["Evaluation Scripts"]:::eval
        IS["Inference Serving"]:::inference
        VZ["Visualizer"]:::inference
    end

    %% Ancillary Scripts as Utilities
    AS["Ancillary Scripts"]:::utility

    %% Connections within Data and Preprocessing Layer
    RD -->|"raw_input"| DP
    RD -->|"raw_input"| TF

    %% Flow from Data to Training Pipeline
    DP -->|"processed_data"| TM
    TF -->|"formatted_data"| TM

    %% Training Pipeline internal flow
    TM -->|"init_training"| TR
    TR -->|"apply_recipe"| TS

    %% Training Pipeline to Model Architecture
    TS -->|"invoke_LLM"| LLM
    TS -->|"invoke_Vision"| VT
    TS -->|"invoke_Connector"| CN

    %% Integration within Model Architecture
    VT -->|"feature_extraction"| CN
    LLM -->|"text_integration"| CN

    %% Model Architecture to Evaluation and Inference
    TS -->|"evaluation_trigger"| ES
    TS -->|"evaluation_trigger"| EV
    LLM -->|"model_output"| IS
    VT -->|"model_output"| IS
    CN -->|"model_output"| IS
    LLM -->|"model_output"| VZ
    VT -->|"model_output"| VZ
    CN -->|"model_output"| VZ

    %% Ancillary Scripts supporting training and evaluation automation
    AS -->|"automation"| TS
    AS -->|"automation"| EV

    %% Click Events
    click LLM "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava/model/llm"
    click VT "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava/model/vision_tower"
    click CN "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava/model/connector"
    click DP "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava/data"
    click TF "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava/data/template"
    click TM "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava/train"
    click TR "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava/training_recipe"
    click TS "https://github.com/tinyllava/tinyllava_factory/tree/main/scripts/train"
    click ES "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava/eval"
    click EV "https://github.com/tinyllava/tinyllava_factory/tree/main/scripts/eval"
    click IS "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava/serve"
    click VZ "https://github.com/tinyllava/tinyllava_factory/tree/main/tinyllava_visualizer"
    click AS "https://github.com/tinyllava/tinyllava_factory/tree/main/scripts"

    %% Styles
    classDef data fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef training fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef model fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef eval fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef inference fill:#F8C471,stroke:#D35400,stroke-width:2px;
    classDef utility fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
```
