# yeliudev/videomind architecture

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

- Interactive diagram: https://gitdiagram.com/yeliudev/videomind
- Repository: https://github.com/yeliudev/videomind

## Overview

##### Project Components
- Frontend/Demo: The “demo” directory (with app.py) indicates an interactive demo interface built, likely, using Gradio or a similar web framework. This component is responsible for user interaction and displaying video reasoning outputs.
- Model Module: In “videomind/model”, key architectural elements are defined. There are modules for blocks, builder, generator, loss, and the overall model – reflecting the chain-of-LoRA agent’s internals that combine sub-tasks (like reasoning intermediates) into a final decision.
- Training Pipeline: The “videomind/train” folder (with custom_trainer.py and train.py) is dedicated to training routines. This should be shown as a module that interfaces with both the model and dataset components, integrating advanced techniques (e.g., DeepSpeed ZeRO, LoRA, mixed-precision training like BF16) as mentioned in the README.
- Evaluation Module: “videomind/eval” provides scripts for inference and evaluation (both auto and QVHighlights-specific). Additionally, the “docs/EVAL.md” and evaluation scripts in “scripts/evaluation” reinforce the need to clearly distinguish evaluation from training.
- Scripts for Pre-training and Fine-tuning: Under “scripts”, the separate directories for pretrain, finetune, and evaluation encapsulate workflow automation for different stages (pre-training the grounder, planner, verifier models and then fine-tuning on domain-specific tasks).
- Utilities and Configuration: The “videomind/utils” folder (with IO and parser modules) and other configuration files (setup.cfg, requirements.txt) are supporting components that manage I/O operations, configuration parsing, and dependency management.

##### Relationships and Interactions
- Data Flow: Illustrate how raw video inputs and annotations are handled by the dataset module, then fed into the model pipeline during training. Show how data wrappers standardize input across diverse datasets.
- Training Loop: Connect the dataset and model modules into the training module which employs techniques like DeepSpeed ZeRO, LoRA, BF16, etc. Indicate monitoring (via TensorBoard/Wandb) as part of the training side-channel.
- Evaluation and Inference: Display that the evaluation module receives inputs (which might be preprocessed similarly to training data) and then uses the trained model to generate outputs — these may be compared against ground truth benchmarks as detailed in the README.
- Demo Interface: Show that after evaluation and training, a demo (in “demo/app.py”) allows users to leverage the inference pipeline in a web environment.

##### Architectural Patterns and Design Principles
- Modular Design: The clear separation into dataset, model, train, and evaluation components suggests a modular design which facilitates component reusability and isolated testing.
- Pipeline Architecture: Emphasize the sequential pipeline—from data ingestion, through model training, to evaluation—mirroring the “chain” of reasoning steps.
- Extensibility: The presence of many dataset “sub_classes” and wrappers indicates extensibility; new datasets or tasks can be added by creating corresponding modules.
- Automation and Scripting: The “scripts” directory organizes pretrain, finetune, and evaluation routines, showing that the system supports automated workflows.

##### Relevant Technologies and Libraries
- Deep Learning Frameworks: Likely using PyTorch (or similar) given the emphasis on GPU-accelerated training and modules like DeepSpeed, LoRA, and FlashAttention2.
- Distributed Training Tools: Components like DeepSpeed ZeRO highlight support for efficient large-scale model training on modern hardware.
- Demo and Visualization: The demo folder suggests usage of web frameworks (e.g., Gradio) for an interactive experience.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Dataset Module
    subgraph "Dataset Module"
        dsCore["Dataset Core"]:::dataset
        dsSub["Sub-Classes"]:::dataset
        dsWrap["Wrappers"]:::dataset
    end

    %% Model Module
    subgraph "Model Module"
        mBlocks["Blocks (blocks.py)"]:::model
        mBuilder["Builder (builder.py)"]:::model
        mGenerator["Generator (generator.py)"]:::model
        mLoss["Loss (loss.py)"]:::model
        mModel["Model (model.py)"]:::model
    end

    %% Training Pipeline
    subgraph "Training Pipeline"
        tCustom["Custom Trainer (custom_trainer.py)"]:::training
        tTrain["Train Script (train.py)"]:::training
        enhancers["Training Enhancers<br/>(DeepSpeed/LoRA/BF16)"]:::trainingExt
    end

    %% Evaluation Module
    subgraph "Evaluation Module"
        eAuto["Eval Auto (eval_auto.py)"]:::evaluation
        eQV["Eval QVHighlights (eval_qvhighlights.py)"]:::evaluation
        iAuto["Infer Auto (infer_auto.py)"]:::evaluation
        iQV["Infer QVHighlights (infer_qvhighlights.py)"]:::evaluation
        eDocs["EVAL Docs (EVAL.md)"]:::evaluation
        eScripts["Evaluation Scripts (scripts/evaluation)"]:::evaluation
    end

    %% Automation Scripts
    subgraph "Automation Scripts"
        pretrain["Pretrain Scripts (pretrain)"]:::automation
        finetune["Finetune Scripts (finetune)"]:::automation
    end

    %% Utilities and Configuration
    subgraph "Utilities and Configuration"
        util["IO and Parser (utils)"]:::utilities
        cfg["Setup Config (setup.cfg)"]:::utilities
        req["Requirements (requirements.txt)"]:::utilities
    end

    %% Demo / Frontend
    subgraph "Demo / Frontend"
        demo["Demo Interface (app.py)"]:::demo
    end

    %% Data Flow Connections
    dsCore --- dsSub
    dsSub --- dsWrap
    dsWrap -->|"provides data"| mBlocks
    mBlocks --> mBuilder
    mBuilder --> mGenerator
    mGenerator --> mLoss
    mLoss --> mModel
    mModel -->|"trained with"| tTrain
    tCustom --- tTrain
    tTrain -->|"triggers"| eAuto
    tTrain --> eQV
    eAuto --- iAuto
    eQV --- iQV
    eAuto -->|"evaluation output"| demo
    iAuto --> demo
    iQV --> demo

    %% Automation Scripts interactions
    pretrain -->|"initiate"| tTrain
    finetune --> tTrain
    pretrain --> eAuto
    finetune --> eQV

    %% Training Enhancers connection
    enhancers --> tTrain

    %% Utilities support (dashed lines)
    util --- dsCore
    util --- mModel
    util --- tTrain
    util --- eAuto
    cfg --- dsCore
    cfg --- mModel
    cfg --- tTrain
    cfg --- eAuto
    req --- dsCore
    req --- mModel
    req --- tTrain
    req --- eAuto

    %% Click Events
    click demo "https://github.com/yeliudev/videomind/blob/main/demo/app.py"
    click dsCore "https://github.com/yeliudev/videomind/tree/main/videomind/dataset"
    click dsSub "https://github.com/yeliudev/videomind/tree/main/videomind/dataset/sub_classes"
    click dsWrap "https://github.com/yeliudev/videomind/tree/main/videomind/dataset/wrappers"
    click mBlocks "https://github.com/yeliudev/videomind/blob/main/videomind/model/blocks.py"
    click mBuilder "https://github.com/yeliudev/videomind/blob/main/videomind/model/builder.py"
    click mGenerator "https://github.com/yeliudev/videomind/blob/main/videomind/model/generator.py"
    click mLoss "https://github.com/yeliudev/videomind/blob/main/videomind/model/loss.py"
    click mModel "https://github.com/yeliudev/videomind/blob/main/videomind/model/model.py"
    click tCustom "https://github.com/yeliudev/videomind/blob/main/videomind/train/custom_trainer.py"
    click tTrain "https://github.com/yeliudev/videomind/blob/main/videomind/train/train.py"
    click eAuto "https://github.com/yeliudev/videomind/blob/main/videomind/eval/eval_auto.py"
    click eQV "https://github.com/yeliudev/videomind/blob/main/videomind/eval/eval_qvhighlights.py"
    click iAuto "https://github.com/yeliudev/videomind/blob/main/videomind/eval/infer_auto.py"
    click iQV "https://github.com/yeliudev/videomind/blob/main/videomind/eval/infer_qvhighlights.py"
    click eDocs "https://github.com/yeliudev/videomind/blob/main/docs/EVAL.md"
    click eScripts "https://github.com/yeliudev/videomind/tree/main/scripts/evaluation"
    click pretrain "https://github.com/yeliudev/videomind/tree/main/scripts/pretrain"
    click finetune "https://github.com/yeliudev/videomind/tree/main/scripts/finetune"
    click util "https://github.com/yeliudev/videomind/tree/main/videomind/utils"
    click cfg "https://github.com/yeliudev/videomind/blob/main/setup.cfg"
    click req "https://github.com/yeliudev/videomind/blob/main/requirements.txt"

    %% Styles
    classDef dataset fill:#A3E4D7,stroke:#117864,stroke-width:2px,font-family:Arial;
    classDef model fill:#F9E79F,stroke:#B9770E,stroke-width:2px,font-family:Arial;
    classDef training fill:#FCF3CF,stroke:#B7950B,stroke-width:2px,font-family:Arial;
    classDef trainingExt fill:#FDEBD0,stroke:#D35400,stroke-width:2px,font-family:Arial;
    classDef evaluation fill:#F5B7B1,stroke:#C0392B,stroke-width:2px,font-family:Arial;
    classDef automation fill:#D2B4DE,stroke:#6C3483,stroke-width:2px,font-family:Arial;
    classDef utilities fill:#D6EAF8,stroke:#2471A3,stroke-width:2px,font-family:Arial;
    classDef demo fill:#AED6F1,stroke:#1F618D,stroke-width:2px,font-family:Arial;
```
