# nguyenddang/tinyijepa architecture

> Architecture diagram of the GitHub repository nguyenddang/tinyijepa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nguyenddang/tinyijepa
- Repository: https://github.com/nguyenddang/tinyijepa

## Overview

##### Main Components

a) Data Pipeline:
- Input Layer (Tiny ImageNet Dataset)
- Data Preprocessing Component
- Block Generation System (Context & Target blocks)

b) Model Architecture:
- Context Encoder
- Target Encoder
- Predictor
- Linear Probe Layer (for evaluation)

c) Training System:
- Loss Computation Module
- EMA Update Mechanism
- Training Loop Controller

##### Important Elements to Highlight

- Patch embedding process (3x8x8 patches)
- Embeddings addition
- Token concatenation points
- Gradient flow directions
- EMA update mechanism

##### Technical Details

Annotations showing:
- Embedding dimension (256)
- Number of layers (12 for encoders, 6 for predictor)
- Number of attention heads (4)
- Model sizes (14M parameters for tiny version)
- Training time (~2 hours on RTX 4050)

##### Specific Implementation Notes

- Rectangles: Processing blocks
- Diamonds: Decision points
- Rounded rectangles: Model components

##### Performance Metrics

- 87% top-1 accuracy with linear probing
- Training loss curve
- Prediction magnitude tracking

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Data_Pipeline
        Input["Raw Images (64x64x3)"]:::data
        Preproc["Data Preprocessing"]:::process
        BlockGen["Block Generation System"]:::process
        Input --> Preproc
        Preproc --> BlockGen
    end

    subgraph Block_Generation
        Context["Context Blocks<br/>(scale: 0.85-1.0)"]:::block
        Target["Target Blocks<br/>(scale: 0.15-0.2)"]:::block
        BlockGen --> Context
        BlockGen --> Target
    end

    subgraph Model_Architecture
        CtxEnc["Context Encoder<br/>(12 layers, 4 heads)"]:::encoder
        TgtEnc["Target Encoder<br/>(12 layers, 4 heads)"]:::encoder
        Pred["Predictor<br/>(6 layers)"]:::predictor
        Context --> CtxEnc
        Target --> TgtEnc
        CtxEnc --> Pred
        Pred --> Loss
    end

    subgraph Training_System
        Loss["L2/Smooth L1 Loss"]:::loss
        EMA["EMA Update<br/>Mechanism"]:::training
        Train["Training Loop<br/>Controller"]:::training
        Loss --> Train
        TgtEnc --> EMA
        EMA --> TgtEnc
    end

    subgraph Evaluation
        LinProbe["Linear Probe Layer"]:::eval
        Metrics["Performance Metrics<br/>87% top-1 accuracy"]:::eval
        CtxEnc --> LinProbe
        LinProbe --> Metrics
    end

    subgraph Config
        BaseConfig["Base Config"]:::config
        SmallConfig["Small Config"]:::config
        TinyConfig["Tiny Config"]:::config
    end

    %% Component Mappings
    click Input "https://github.com/nguyenddang/tinyIJEPA/tree/main/data/tiny_imagenet/"
    click Preproc "https://github.com/nguyenddang/tinyIJEPA/blob/main/data/tiny_imagenet/prepare.py"
    click CtxEnc "https://github.com/nguyenddang/tinyIJEPA/blob/main/model.py"
    click TgtEnc "https://github.com/nguyenddang/tinyIJEPA/blob/main/model.py"
    click Pred "https://github.com/nguyenddang/tinyIJEPA/blob/main/model.py"
    click Train "https://github.com/nguyenddang/tinyIJEPA/blob/main/train.py"
    click BaseConfig "https://github.com/nguyenddang/tinyIJEPA/blob/main/configs/train_ijepabase_tinyimagenet.yml"
    click SmallConfig "https://github.com/nguyenddang/tinyIJEPA/blob/main/configs/train_ijepasmall_tinyimagenet.yml"
    click TinyConfig "https://github.com/nguyenddang/tinyIJEPA/blob/main/configs/train_ijepatiny_tinyimagenet.yml"
    click BlockGen "https://github.com/nguyenddang/tinyIJEPA/blob/main/utils.py"
    click EMA "https://github.com/nguyenddang/tinyIJEPA/blob/main/utils.py"
    click Metrics "https://github.com/nguyenddang/tinyIJEPA/blob/main/img_visual.ipynb"

    %% Styling
    classDef data fill:#f9f,stroke:#333,stroke-width:2px
    classDef process fill:#bbf,stroke:#333,stroke-width:2px
    classDef block fill:#dfd,stroke:#333,stroke-width:2px
    classDef encoder fill:#9cf,stroke:#333,stroke-width:2px
    classDef predictor fill:#ff9,stroke:#333,stroke-width:2px
    classDef loss fill:#f99,stroke:#333,stroke-width:2px
    classDef training fill:#fc9,stroke:#333,stroke-width:2px
    classDef eval fill:#cfc,stroke:#333,stroke-width:2px
    classDef config fill:#ddd,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Data Components"]:::data
        L2["Processing Steps"]:::process
        L3["Model Components"]:::encoder
        L4["Training Components"]:::training
        L5["Evaluation Components"]:::eval
    end
```
