# deepseek-ai/janus architecture

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

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

## Overview

##### Main Components

a) Core Model Components:
- Language Model (Transformer-based)
- Visual Encoders (Dual pathway system)
- Generation Components
- Model Variants (Janus, Janus-Pro, JanusFlow)

b) Processing Pipeline:
- Input Processing Layer
- Tokenization System
- Image Processing Components
- Output Generation Layer

**[Input Layer]**

- Text Input Stream ──────┐

- Image Input Stream ────┤
- ▼
**[Processing Layer]    [Core Model Components]**
- Tokenizer ────► Language Model ◄─── Visual Encoders

- Image Processor ──────┘

- ▼
**[Generation Layer]**
- Text Generation
- Image Generation

##### Detailed Component Breakdown

a) Input Processing:
- VLChatProcessor component
- Tokenization pipeline
- Demonstrate image preprocessing flow

b) Model Core:
- MultiModalityCausalLM architecture
- Decoupled visual encoding pathways
- Unified transformer architecture

c) Generation Systems:
- Text generation pipeline
- Image generation components
- Rectified flow system (for JanusFlow)

##### Key Relationships to Highlight

- Flow of data from input processing to model core
- Generation pathways for both text and images

##### Technical Details

- Model sizes (1.3B, 7B parameters)
- Input/output formats
- Key configuration parameters
- Supported sequence lengths (4096)

##### Additional Elements

- Version information for different model variants
- Integration points with external systems
- API endpoints and interfaces

##### Implementation Notes

- Brief descriptions for key components
- Maintain consistent visual hierarchy

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        TI[Text Input]:::input
        II[Image Input]:::input
    end

    subgraph Processing
        CH[Conversation Handler]:::processing
        click CH "https://github.com/deepseek-ai/Janus/blob/main/janus/utils/io.py"
        IO[I/O Processing]:::processing
        click IO "https://github.com/deepseek-ai/Janus/blob/main/janus/utils/conversation.py"
        IP[Image Processor]:::processing
        click IP "https://github.com/deepseek-ai/Janus/blob/main/janus/models/image_processing_vlm.py"
        TOK[Tokenizer]:::processing
        click TOK "https://github.com/deepseek-ai/Janus/blob/main/janus/models/processing_vlm.py"
    end

    subgraph "Core Model Components"
        LM[Language Model]:::core
        click LM "https://github.com/deepseek-ai/Janus/blob/main/janus/models/modeling_vlm.py"
        
        subgraph "Visual Encoders"
            CLIP[CLIP Encoder]:::encoder
            click CLIP "https://github.com/deepseek-ai/Janus/blob/main/janus/models/clip_encoder.py"
            SIG[SigLIP ViT]:::encoder
            click SIG "https://github.com/deepseek-ai/Janus/blob/main/janus/models/siglip_vit.py"
        end
        
        subgraph "Model Variants"
            JB[Janus Base]:::variant
            click JB "https://github.com/deepseek-ai/Janus/tree/main/janus/models/"
            JP[Janus Pro]:::variant
            JF[JanusFlow]:::variant
            click JF "https://github.com/deepseek-ai/Janus/tree/main/janus/janusflow/models/"
        end
    end

    subgraph Generation
        TG[Text Generation]:::gen
        IG[Image Generation]:::gen
        click IG "https://github.com/deepseek-ai/Janus/blob/main/janus/models/vq_model.py"
        RF[Rectified Flow]:::gen
        click RF "https://github.com/deepseek-ai/Janus/blob/main/generation_inference.py"
    end

    subgraph "Demo Applications"
        DA[Demo App]:::demo
        click DA "https://github.com/deepseek-ai/Janus/blob/main/demo/app.py"
        DJP[Demo Janus Pro]:::demo
        click DJP "https://github.com/deepseek-ai/Janus/blob/main/demo/app_januspro.py"
        IC[Interactive Chat]:::demo
        click IC "https://github.com/deepseek-ai/Janus/blob/main/interactivechat.py"
    end

    TI --> CH
    II --> IP
    CH --> TOK
    IO --> TOK
    IP --> CLIP & SIG
    TOK --> LM
    CLIP & SIG --> LM
    LM --> JB & JP & JF
    JB & JP & JF --> TG & IG
    JF --> RF
    TG & IG & RF --> DA & DJP & IC

    classDef input fill:#3498db,stroke:#2980b9,color:white
    classDef processing fill:#2ecc71,stroke:#27ae60,color:white
    classDef core fill:#e74c3c,stroke:#c0392b,color:white
    classDef encoder fill:#9b59b6,stroke:#8e44ad,color:white
    classDef variant fill:#f1c40f,stroke:#f39c12,color:black
    classDef gen fill:#1abc9c,stroke:#16a085,color:white
    classDef demo fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        L1[Input Components]:::input
        L2[Processing Components]:::processing
        L3[Core Components]:::core
        L4[Encoder Components]:::encoder
        L5[Model Variants]:::variant
        L6[Generation Components]:::gen
        L7[Demo Applications]:::demo
    end
```
