# timgaripov/dnn-mode-connectivity architecture

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

- Interactive diagram: https://gitdiagram.com/timgaripov/dnn-mode-connectivity
- Repository: https://github.com/timgaripov/dnn-mode-connectivity

## Overview

##### Main Components
- Data Preprocessing & Loading: Represented by the data.py file and parts of train.py and eval_curve.py that handle dataset selection, transformations, and loading (with dependency on torchvision).
- Curve Finding Module: This is the core of the mode connectivity approach. Key scripts like curves.py, connect.py, and test_curve.py are responsible for finding and testing the curves that connect two endpoints in the loss landscape.
- Training Pipeline: The train.py script orchestrates training for both endpoints and curves. Illustrate this as a main “Training Engine” that interacts with the Data Loader, Model Components, and Curve Finding Module.
- Fast Geometric Ensembling (FGE): Represented by fge.py and further supported by eval_ensemble.py. This component takes a pre-trained checkpoint and, using a cyclical learning rate schedule, generates an ensemble of models for better generalization.
- Evaluation & Visualization: The eval_curve.py script evaluates the loss and accuracy along the curves, and plane.py along with plane_plot.py likely helps with visualization of loss surfaces. This can be depicted as a separate “Evaluation & Visualization” module.
- Utilities: The utils.py script and any helper functions are used across modules (data processing, parameter logging, checkpoint management, etc.) and should be shown as supporting components.

##### Relationships and Interactions
- Model Checkpoints: Show that train.py produces checkpoints which are then used in further modules:
- For training curves with curves.py (and connect.py) which uses two endpoint checkpoints.
- For FGE (fge.py), where a pre-trained checkpoint is used to initialize the ensembling process.
- For evaluation (eval_curve.py and eval_ensemble.py) where saved checkpoints are loaded to compute loss, accuracy trends, and generate statistics (possibly saved in npz files).
- External Dependencies: Indicate that PyTorch, torchvision, and tabulate are underlying frameworks/libraries essential to the implementation. These should be drawn as external resources that feed into the Training Pipeline and Model Components.

##### Architectural Patterns and Design Principles
- “Processing/Execution Scripts” (train.py, fge.py, eval_curve.py)
- “Model Architecture Modules” (contents of the models/ directory)
- “Supporting Modules” (data.py, curves.py, utils.py, etc.)
- Checkpoint & Workflow Structure: Emphasize how checkpoints are central to the process flow, especially when transitioning between training endpoints, curve training, and FGE.
- Parameterization & Experimentation: Note that numerous parameters (learning rate, epochs, weight decay, curve type, number of bends) are passed around through the scripts, suggesting a design that supports experiment configuration externally (via CLI arguments).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Dependencies
    PT["PyTorch"]:::external
    TV["torchvision"]:::external
    TAB["tabulate"]:::external

    %% Core Modules
    DL["Data Loader (data.py)"]:::execution
    TE["Training Engine (train.py)"]:::execution
    CS["Checkpoint Storage"]:::storage
    U["Utilities (utils.py)"]:::utility

    %% Model Components Subgraph
    subgraph "Model Components (DNN Architectures)"
        VGG["VGG (models/vgg.py)"]:::model
        PR["PreResNet (models/preresnet.py)"]:::model
        WR["WideResNet (models/wide_resnet.py)"]:::model
        CFc["ConvFC (models/convfc.py)"]:::model
    end

    %% Curve Finder Module Subgraph
    subgraph "Curve Finder Module"
        CR["curves.py"]:::execution
        CN["connect.py"]:::execution
        CT["test_curve.py"]:::execution
    end

    %% FGE Module Subgraph
    subgraph "FGE Module"
        FGE1["fge.py"]:::execution
        FGE2["eval_ensemble.py"]:::execution
    end

    %% Evaluation & Visualization Subgraph
    subgraph "Evaluation Module"
        EV1["eval_curve.py"]:::execution
        PL["plane.py"]:::execution
        PP["plane_plot.py"]:::execution
    end

    %% Data Flow Connections
    DL -->|"feeds_data"| TE
    TE -->|"calls_model"| VGG
    TE -->|"uses_utils"| U
    TE -->|"produces_ckpt"| CS
    CS -->|"loads_ckpt"| CR
    CS -->|"loads_ckpt"| FGE1
    CR -->|"curve_metrics"| EV1
    FGE1 -->|"ensemble_preds"| EV1

    %% External Dependencies Connections
    PT -->|"supports"| TE
    TV -->|"supports"| TE
    TAB -->|"supports"| TE
    PT -->|"supports"| VGG
    TV -->|"supports"| VGG

    %% Styles
    classDef execution fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef model fill:#99CCFF,stroke:#333,stroke-width:2px;
    classDef utility fill:#66FF66,stroke:#333,stroke-width:2px;
    classDef external fill:#FF9999,stroke:#333,stroke-width:2px;
    classDef storage fill:#E0E0E0,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5

    %% Click Events for Component Mapping
    click DL "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/data.py"
    click VGG "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/models/vgg.py"
    click PR "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/models/preresnet.py"
    click WR "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/models/wide_resnet.py"
    click CFc "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/models/convfc.py"
    click CR "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/curves.py"
    click CN "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/connect.py"
    click CT "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/test_curve.py"
    click TE "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/train.py"
    click FGE1 "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/fge.py"
    click FGE2 "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/eval_ensemble.py"
    click EV1 "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/eval_curve.py"
    click PL "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/plane.py"
    click PP "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/plane_plot.py"
    click U "https://github.com/timgaripov/dnn-mode-connectivity/blob/master/utils.py"
```
