# deepseek-ai/deepseek-vl architecture

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

- Interactive diagram: https://gitdiagram.com/deepseek-ai/deepseek-vl
- Repository: https://github.com/deepseek-ai/deepseek-vl

## Overview

##### Project type and purpose
- DeepSeek-VL is an open-source Vision-Language model library and demo application.
- It provides:
- A Python package for multi-modal inference (deepseek_vl/models, deepseek_vl/utils).
- A CLI chat interface (cli_chat.py).
- A Gradio-based web demo (deepseek_vl/serve/app_deepseek.py + assets).

##### File structure
- Top-level scripts:
- cli_chat.py – entry point for command-line interaction.
- inference.py – standalone inference demo.
- Core package deepseek_vl/ with submodules:
- models/                                  ← model definitions and processors
– clip_encoder.py, siglip_vit.py, sam.py  ← vision encoders
– processing_vlm.py, image_processing_vlm.py ← input preprocessors
– modeling_vlm.py, projector.py          ← multi-modal fusion and language head
- utils/                                   ← I/O and conversation helpers
- serve/                                   ← Gradio server and UI modules
– app_deepseek.py                        ← main web-service entry
– app_modules/                           ← UI utilities, presets, CSS/JS
– assets/                                ← static assets (JS/CSS)
– examples/, inference.py                ← demo scripts
- Configuration/build: Makefile, pyproject.toml, requirements.txt, CI workflows

##### Key insights from README
- Uses PyTorch + HuggingFace Transformers under the hood.
- Exposes VLChatProcessor for batching text+image conversations.
- Supports a CLI mode and a Gradio web-demo mode.
- Models are downloaded from HuggingFace Hub with trust_remote_code=True.

##### Detail is essential
- Every major file group as a component.
- Overlap: both CLI and Gradio reuse the same deepseek_vl core.
- Environmental context: GPU/CPU runtime, local file storage, HuggingFace remote.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User"]:::actor

    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        cliChat["CLI Chat Module"]:::ui
        click cliChat "https://github.com/deepseek-ai/deepseek-vl/blob/main/cli_chat.py"
        inferenceDemo["Standalone Inference Demo"]:::ui
        click inferenceDemo "https://github.com/deepseek-ai/deepseek-vl/blob/main/inference.py"
        subgraph "Gradio Web App"
            direction TB
            appDeepseek["Gradio Main App"]:::ui
            click appDeepseek "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/serve/app_deepseek.py"
            appInference["Serve Inference Script"]:::ui
            click appInference "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/serve/inference.py"
            subgraph "Web UI Modules"
                direction TB
                gradioUtils["gradio_utils.py"]:::ui
                click gradioUtils "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/serve/app_modules/gradio_utils.py"
                overwrites["overwrites.py"]:::ui
                click overwrites "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/serve/app_modules/overwrites.py"
                presets["presets.py"]:::ui
                click presets "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/serve/app_modules/presets.py"
                appUtils["utils.py"]:::ui
                click appUtils "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/serve/app_modules/utils.py"
            end
            subgraph "Static Assets"
                direction TB
                kelpy["Kelpy-Codos.js"]:::ui
                click kelpy "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/serve/assets/Kelpy-Codos.js"
                customJS["custom.js"]:::ui
                click customJS "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/serve/assets/custom.js"
                customCSS["custom.css"]:::ui
                click customCSS "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/serve/assets/custom.css"
            end
        end
    end

    %% Core Library
    subgraph "Core Library" 
        direction TB
        subgraph "Utils"
            direction TB
            io["I/O Helpers"]:::core
            click io "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/utils/io.py"
            conv["Conversation Management"]:::core
            click conv "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/utils/conversation.py"
        end
        subgraph "Models"
            direction TB
            subgraph "Vision Encoders"
                clip["CLIP Encoder"]:::core
                click clip "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/models/clip_encoder.py"
                siglip["SigLIP-ViT Encoder"]:::core
                click siglip "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/models/siglip_vit.py"
                sam["SAM Encoder"]:::core
                click sam "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/models/sam.py"
            end
            subgraph "Preprocessors"
                procVLM["Text/Image Processing"]:::core
                click procVLM "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/models/processing_vlm.py"
                imgProc["Image-only Processing"]:::core
                click imgProc "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/models/image_processing_vlm.py"
            end
            subgraph "Fusion & Language Head"
                modelling["Modeling VLM"]:::core
                click modelling "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/models/modeling_vlm.py"
                projector["Feature Projector"]:::core
                click projector "https://github.com/deepseek-ai/deepseek-vl/blob/main/deepseek_vl/models/projector.py"
            end
            vlProcessor["VLChatProcessor"]:::core
        end
        tokenizer["Tokenizer.decode"]:::core
    end

    %% External Services & Frameworks
    subgraph "External Services" 
        direction TB
        pytorch["PyTorch Runtime"]:::external
        transformers["HuggingFace Transformers & Hub"]:::external
        gradioLib["Gradio Library"]:::external
        cliLib["click/argparse"]:::external
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        hw["Hardware (GPU/CPU)"]:::infra
        storage["File Storage"]:::storage
    end

    %% Config & CI
    subgraph "Config & CI"
        direction TB
        makefile["Makefile"]:::infra
        click makefile "https://github.com/deepseek-ai/deepseek-vl/tree/main/Makefile"
        pyproject["pyproject.toml"]:::infra
        click pyproject "https://github.com/deepseek-ai/deepseek-vl/blob/main/pyproject.toml"
        reqs["requirements.txt"]:::infra
        click reqs "https://github.com/deepseek-ai/deepseek-vl/blob/main/requirements.txt"
        ci[".github/workflows/lint.yml"]:::infra
        click ci "https://github.com/deepseek-ai/deepseek-vl/blob/main/.github/workflows/lint.yml"
    end

    %% Connections
    User --> cliChat
    User --> appDeepseek
    User --> inferenceDemo

    cliChat --> io
    inferenceDemo --> io
    appDeepseek --> io
    appDeepseek --> gradioLib
    appDeepseek --> storage

    io --> conv
    conv --> vlProcessor

    vlProcessor --> procVLM
    vlProcessor --> imgProc
    procVLM --> clip
    procVLM --> siglip
    procVLM --> sam

    clip --> modelling
    siglip --> modelling
    sam --> modelling

    modelling --> projector
    projector --> tokenizer

    tokenizer --> io

    modelling --> pytorch
    modelling --> transformers
    projector --> pytorch

    pytorch --> hw
    gradioLib --> hw
    storage --> hw

    classDef ui fill:#AEDFF7,stroke:#0366d6,color:#000
    classDef core fill:#FFF4C1,stroke:#DBAB09,color:#000
    classDef external fill:#E8F0FE,stroke:#1967D2,color:#000
    classDef infra fill:#E6F4EA,stroke:#137333,color:#000
    classDef storage fill:#F0FFF4,stroke:#137333,color:#000
    classDef actor fill:#F0F0F0,stroke:#888,color:#000
```
