# sudo-sh/hamq architecture

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

- Interactive diagram: https://gitdiagram.com/sudo-sh/hamq
- Repository: https://github.com/sudo-sh/hamq

## Overview

##### Project Type and Purpose
- This project is a deep learning training pipeline focused on reducing energy consumption through a novel regularizer (HamQ) for ResNet models on the CIFAR-10 dataset. It’s a research/demo project rather than a production full-stack application.
- The README highlights that the project is built on applying energy-aware quantization techniques integrated into a ResNet model training pipeline.

##### File Structure
- Top-level files and directories:
- train.py – Serves as the main entry point for training and evaluation.
- net.py – Contains the definition of the ResNet model modified to include the HamQ regularizer.
- .py – Handles the mapping of simulated bitline energy to actual energy, influencing the energy-aware quantization.
- utils.py – Provides helper functions for training routines and data processing.
- utils_en.py – Contains additional utilities focused on energy calculations and logging.
- model_cifar (directory) – Contains configuration/parameter file (resnet_params.json) which likely determines the network’s architecture parameters for CIFAR training.
- Absence of separate directories for data or tests, reinforcing that the core focus is on the training pipeline and energy-aware quantization integration.

##### Components to Highlight
- Main Components:
A. Data/Preprocessing Module
- Implicitly handled via helper functions in utils.py (for loading, augmenting, and processing the CIFAR-10 dataset).
B. Training/Evaluation Module
- Represented by train.py which coordinates the training loop, evaluation routines, and overall pipeline flow.
C. Model Definition Module
- Represented by net.py. Emphasize that this module defines a ResNet architecture enhanced by the HamQ method.
D. Configuration Parameters
- The model_cifar/resnet_params.json file holds essential parameters that define model layer configurations and perhaps quantization details.
E. Energy Calculation and Mapping Module
- .py and utils_en.py encapsulate the experimental energy calculations, such as mapping simulated bitline energy and logging energy consumption.
- Supporting Elements:
- External Libraries: PyTorch and Python dependencies (from requirements.txt) which are crucial for deep learning computations.
- Research Context: The overall design supports an experimental setup influenced by recent research (as cited in the README).

##### Relationships and Interactions
- Data flows into the training pipeline (train.py), where it is pre-processed by helper utilities (utils.py).
- train.py calls the model defined in net.py. The model may be configured with parameters from model_cifar/resnet_params.json.
- Training computations internally leverage PyTorch.
- Interplay between the model architecture and energy quantization:

##### Architectural Patterns and Design Principles
- Modular design where each component (data handling, model definition, training logic, energy calculations) is represented by its own script or utility module.
- Separation of concerns: training logic, model architecture, configuration, and energy analysis are clearly separated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data/Preprocessing Layer
    subgraph "Data/Preprocessing"
        DP["Data/Preprocessing (utils.py)"]:::preprocessing
    end

    %% Training and Model Layer
    subgraph "Training/Model"
        CP["Configuration Parameters (model_cifar/resnet_params.json)"]:::config
        TP["Training Pipeline (train.py)"]:::training
        MA["Model Architecture with HamQ (net.py)"]:::training
    end

    %% Energy Calculation Modules
    subgraph "Energy Modules"
        EM1["Energy Mapping (map.py)"]:::energy
        EM2["Energy Utilities (utils_en.py)"]:::energy
    end

    %% External Dependencies
    subgraph "External Dependencies"
        PT["PyTorch Library"]:::external
    end

    %% Connections
    DP -->|"data_flow"| TP
    CP -->|"configures"| TP
    TP -->|"trains"| MA
    TP -->|"calls"| EM1
    TP -->|"calls"| EM2
    MA -->|"HamQ_regularizer"| EM2
    PT -->|"dependency"| TP
    PT -->|"dependency"| MA
    EM1 -->|"energy_feedback"| TP
    EM2 -->|"energy_feedback"| TP

    %% Click Events
    click DP "https://github.com/sudo-sh/hamq/blob/main/utils.py"
    click CP "https://github.com/sudo-sh/hamq/blob/main/model_cifar/resnet_params.json"
    click TP "https://github.com/sudo-sh/hamq/blob/main/train.py"
    click MA "https://github.com/sudo-sh/hamq/blob/main/net.py"
    click EM1 "https://github.com/sudo-sh/hamq/blob/main/map.py"
    click EM2 "https://github.com/sudo-sh/hamq/blob/main/utils_en.py"

    %% Styles
    classDef preprocessing fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef training fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef config fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef energy fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#F5CBA7,stroke:#A04000,stroke-width:2px;
```
