# sumyeongahn/cuda_ltr architecture

> Architecture diagram of the GitHub repository sumyeongahn/cuda_ltr, 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/sumyeongahn/cuda_ltr
- Repository: https://github.com/sumyeongahn/cuda_ltr

## Overview

##### Main Components
- Data Input & Dataset Modules:
– For CIFAR, look at the “cifar/datasets” folder (e.g., cifar100.py) which handles loading and serving CIFAR-100 data.
– For large-scale use cases, the “large_scale” directory includes configuration files, imbalance_data routines, and dataset-specific scripts.

- Data Augmentation:
– “cifar/aug” and “large_scale/aug” provide various augmentation methods (e.g., autoaug, cuda, cutmix/cutout, randaug, transforms).
– These modules are key in applying the CUDA curriculum (per-class augmentation strength) and other augmentation policies.

- Loss Functions:
– Under “cifar/losses”, multiple loss functions are defined (e.g., balanced contrastive loss, cross-entropy variants, LDAM-based losses, NCL, RIDE).
– For large-scale experiments, there is a “large_scale/losses.py” file.

- Model Architectures:
– The “cifar/models” folder houses definitions such as “net.py” and different variations of resnet (plain, with BCL, with NCL, with RIDE).
– These represent the backbone networks and any tailored modifications in the training pipelines.

- Training Pipeline & Functions:
– Separate training routines exist in both major directories:
- For CIFAR-100: “cifar/main.py” is the training entry point and “cifar/train” includes training functions, switching among different loss functions or augmentation strategies.
- For large-scale datasets: “large_scale/train.py” and associated helper files (like “training_functions.py” and dataset-specific training scripts such as “imagenet_train.py”, “inat18_train.py”).

- Utilities & Configuration:
– Both directories have directories for configuration (cifar/utils/config.py, large_scale/config) and additional utilities (e.g., logger, accuracy, plotting) that support debugging and evaluating performance.
– The “requirements.txt” file specifies all external dependencies (likely PyTorch and others).

##### Relationships and Interactions
- Data flows into the Data Augmentation modules where various augmentation strategies, including the CUDA curriculum, are applied.
- After augmentation, data is fed into the Model Architectures. Training scripts from “cifar/main.py” or “large_scale/train.py” coordinate this process.
- The Model’s output is then processed by the Loss Functions for backpropagation. This loss is computed using modules from the “losses” directories.
- Finally, training control and evaluation occur via the Training Pipelines combined with utility functions (logger, accuracy, config, and plotting) for monitoring progress and visualization of results.
- In addition, consider showing how different training configurations are “swapped” or toggled based on experimental settings (e.g., using DRW, CE, or other loss/augmentation modes).

##### Architectural Patterns & Design Principles
- Separation of Concerns: Data loading, augmentation, modeling, and training are clearly separated into distinct directories.
- Modularity: Both the CIFAR and large-scale pipelines are modular – loss functions, training strategies, and augmentation methods are clearly encapsulated, allowing for easy experimentation.
- Configurability: Through configuration files and command-line options, the project allows switching between various augmentation and training policies (e.g., cutout vs CUDA augmentation).

##### Relevant Technologies/Frameworks
- Deep Learning Framework: Likely based on PyTorch (implied by the Python training scripts and prevalent deep learning practices).
- Jupyter Notebooks: Seen in “cifar/analysis/fix_fe.ipynb” for analysis or debugging.
- Standard data augmentation libraries, custom augmentation modules, and potentially external libraries for image processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CIFAR Pipeline
    DATA_CIFAR["Dataset Loader (CIFAR)"]:::data
    AUG_CIFAR["Data Augmentation (CIFAR)"]:::aug
    LOSS_CIFAR["Loss Functions (CIFAR)"]:::loss
    TRAIN_MAIN_CIFAR["Training Entry (cifar/main.py)"]:::train
    TRAIN_FUNC_CIFAR["Training Functions (cifar/train)"]:::train
    UTIL_CIFAR["Utilities & Config (CIFAR)"]:::util
    ANALYSIS["Analysis Tools (Jupyter Notebook)"]:::analysis

    %% Large-scale Pipeline
    DATA_LS["Dataset Loader (Large-scale)"]:::data
    AUG_LS["Data Augmentation (Large-scale)"]:::aug
    LOSS_LS["Loss Functions (Large-scale)"]:::loss
    TRAIN_MAIN_LS["Training Entry (large_scale/train.py)"]:::train
    TRAIN_IMAGENET["ImageNet Training (large_scale/imagenet_train.py)"]:::train
    TRAIN_INAT["iNat18 Training (large_scale/inat18_train.py)"]:::train
    TRAIN_FUNC_LS["Training Functions (large_scale/training_functions.py)"]:::train
    UTIL_LS["Utilities & Config (Large-scale)"]:::util

    %% Common Component
    MODEL["Model Architecture (ResNet Variants)"]:::model

    %% CIFAR Flow
    DATA_CIFAR -->|"feeds"| AUG_CIFAR
    AUG_CIFAR -->|"augments"| MODEL
    MODEL -->|"processed by"| LOSS_CIFAR
    LOSS_CIFAR -->|"triggers"| TRAIN_MAIN_CIFAR
    TRAIN_MAIN_CIFAR -->|"executes"| TRAIN_FUNC_CIFAR
    TRAIN_FUNC_CIFAR -->|"logs to"| UTIL_CIFAR
    UTIL_CIFAR -->|"enables"| ANALYSIS

    %% Large-scale Flow
    DATA_LS -->|"feeds"| AUG_LS
    AUG_LS -->|"augments"| MODEL
    MODEL -->|"processed by"| LOSS_LS
    LOSS_LS -->|"triggers"| TRAIN_MAIN_LS
    TRAIN_MAIN_LS -->|"initiates"| TRAIN_IMAGENET
    TRAIN_IMAGENET -->|"chains to"| TRAIN_INAT
    TRAIN_INAT -->|"delegates to"| TRAIN_FUNC_LS
    TRAIN_FUNC_LS -->|"logs to"| UTIL_LS

    %% Click Events
    click DATA_CIFAR "https://github.com/sumyeongahn/cuda_ltr/blob/main/cifar/datasets/cifar100.py"
    click DATA_LS "https://github.com/sumyeongahn/cuda_ltr/blob/main/large_scale/imbalance_data/lt_data.py"
    click AUG_CIFAR "https://github.com/sumyeongahn/cuda_ltr/tree/main/cifar/aug"
    click AUG_LS "https://github.com/sumyeongahn/cuda_ltr/tree/main/large_scale/aug"
    click LOSS_CIFAR "https://github.com/sumyeongahn/cuda_ltr/tree/main/cifar/losses"
    click LOSS_LS "https://github.com/sumyeongahn/cuda_ltr/blob/main/large_scale/losses.py"
    click MODEL "https://github.com/sumyeongahn/cuda_ltr/tree/main/cifar/models"
    click TRAIN_MAIN_CIFAR "https://github.com/sumyeongahn/cuda_ltr/blob/main/cifar/main.py"
    click TRAIN_FUNC_CIFAR "https://github.com/sumyeongahn/cuda_ltr/tree/main/cifar/train"
    click TRAIN_MAIN_LS "https://github.com/sumyeongahn/cuda_ltr/blob/main/large_scale/train.py"
    click TRAIN_IMAGENET "https://github.com/sumyeongahn/cuda_ltr/blob/main/large_scale/imagenet_train.py"
    click TRAIN_INAT "https://github.com/sumyeongahn/cuda_ltr/blob/main/large_scale/inat18_train.py"
    click TRAIN_FUNC_LS "https://github.com/sumyeongahn/cuda_ltr/blob/main/large_scale/training_functions.py"
    click UTIL_CIFAR "https://github.com/sumyeongahn/cuda_ltr/tree/main/cifar/utils"
    click UTIL_LS "https://github.com/sumyeongahn/cuda_ltr/tree/main/large_scale/config"
    click UTIL_LS "https://github.com/sumyeongahn/cuda_ltr/tree/main/large_scale/util"
    click ANALYSIS "https://github.com/sumyeongahn/cuda_ltr/blob/main/cifar/analysis/fix_fe.ipynb"

    %% Styles
    classDef data fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef aug fill:#aed6f1,stroke:#21618c,stroke-width:2px;
    classDef model fill:#d7bde2,stroke:#6c3483,stroke-width:2px;
    classDef loss fill:#f9cfcf,stroke:#922b21,stroke-width:2px;
    classDef train fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef util fill:#d6eaf8,stroke:#2874a6,stroke-width:2px;
    classDef analysis fill:#fadbd8,stroke:#943126,stroke-width:2px;
```
