# mit-han-lab/tinyml architecture

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

- Interactive diagram: https://gitdiagram.com/mit-han-lab/tinyml
- Repository: https://github.com/mit-han-lab/tinyml

## Overview

##### Project Type & Purpose
- This is a research and demo repository for TinyML methods. Its goal is to develop and evaluate novel training techniques (NetAug) and on-device learning strategies (TinyTL) for tiny neural networks, alongside architectures like MCUNet.
- The README highlights the real-world edge application context (e.g., deployment on IoT devices) and includes a range of experiments and demo scripts for training and evaluating efficient neural network models.

##### Analysis of the File Structure
- Notice top-level directories such as “netaug”, “mcunet”, “tinytl”, and “once-for-all” (though the latter is a separate project folder or reference). The primary focus in this repository is on “netaug” and “tinytl”.
- Within “netaug”, you have subdirectories for bash scripts (automation for experiments across datasets like ImageNet and transfer tasks), configuration files (YAML files for setting up experiments), Python modules for models (divided further into “base” and “netaug” variants), utility functions (for metrics, scheduling, etc.), and training/evaluation scripts.
- In “tinytl”, you see directories for dataset setup scripts (which are used to process several benchmarks), experiment scripts (organized by batch runs), and the core “tinytl” Python module which includes modules for data providers, models, and utilities.

##### How to Represent the System Architecture

a. Main Components:
- For NetAug:
- A “Configuration” component (showing YAML config files).
- Separate “Model” components subdivided into “base” models and “netaug” enhanced models.
- A “Training & Evaluation” pipeline component (represented by train.py and eval.py).
- “Automation Scripts” (the bash scripts for running experiments on ImageNet and transfer datasets).
- “Utilities” for scheduling, profiling, and distributed training.

- For TinyTL:
- “Dataset Setup” scripts (for creating and managing datasets).
- “Experiment Scripts” (batch experiment directories and shell scripts for different domains).
- “Core Learning Module” (the tinytl Python package, including data providers, models, and helper utilities).
- Possibly a “Training Launcher” (e.g., tinytl_fgvc_train.py) that ties the components together.

b. Relationships & Data Flow:
- That the automation bash scripts coordinate with the Python training scripts to execute experiments.
- A data flow from dataset setup scripts into the training pipelines, as well as a feedback loop from evaluation (metrics, profiles) into potential model updates or hyperparameter tuning.
- Dependencies between core modules: for instance, how utility functions support both training and evaluation, and how model layers (both in “base” and “netaug”) abstract common functionalities.

c. Architectural Patterns & Design Principles:
- There is a clear modular separation between configuration, model definitions, training pipelines, and experiments. This separation hints at a loosely coupled design where experiments can be run independently by swapping configuration files or launching different bash scripts.
- The dual-level model organization in NetAug (base vs. netaug) suggests extensibility and reusability, useful design principles when dealing with evolving training techniques.

d. Technologies & Frameworks:
- Although not explicitly listed, it is likely that these Python components rely on deep learning frameworks (such as PyTorch or TensorFlow) given the focus on neural network experimentation.
- The use of shell/bash scripting points to an infrastructure for automated experiment management.
- YAML configuration files denote that experiments are easily parameterized and potentially integrated within larger CI/CD or distributed training systems.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Level Container
    TinyMLProjects["TinyML Projects"]:::container

    %% Sub-projects
    MCUNet["MCUNet"]:::container
    NetAug["NetAug"]:::container
    TinyTL["TinyTL"]:::container

    TinyMLProjects --> MCUNet
    TinyMLProjects --> NetAug
    TinyMLProjects --> TinyTL

    %% MCUNet Subgraph (single node)
    %% Already defined as MCUNet

    %% NetAug Subgraph
    subgraph "NetAug Components"
        direction TB
        NetAugConfig["Configuration"]:::configuration
        TrainScript["Train Script"]:::training
        EvalScript["Eval Script"]:::training
        NetAugAutomation["Automation Scripts"]:::automation
        NetAugBaseModels["Base Models"]:::model
        NetAugAugModels["Augmented Models"]:::model
        NetAugUtilities["Utilities"]:::utility
    end

    %% Connections within NetAug
    NetAugConfig -->|"injects"| TrainScript
    NetAugConfig -->|"injects"| EvalScript
    NetAugAutomation -->|"triggers"| TrainScript
    NetAugAutomation -->|"triggers"| EvalScript
    NetAugBaseModels -->|"feeds"| TrainScript
    NetAugAugModels -->|"feeds"| TrainScript
    TrainScript -->|"utilizes"| NetAugUtilities
    EvalScript -->|"utilizes"| NetAugUtilities
    EvalScript -->|"feedback"| NetAugConfig

    %% TinyTL Subgraph
    subgraph "TinyTL Components"
        direction TB
        TinyTLDataset["Dataset Setup"]:::dataset
        TinyTLExpScripts["Experiment Scripts"]:::experiment
        TinyTLCore["Tinytl Core"]:::core
        TinyTLTrainLauncher["Training Launcher"]:::launcher
    end

    %% Connections within TinyTL
    TinyTLDataset -->|"prepares"| TinyTLTrainLauncher
    TinyTLExpScripts -->|"orchestrates"| TinyTLTrainLauncher
    TinyTLCore -->|"supports"| TinyTLTrainLauncher

    %% Connections from top-level container to sub-components
    NetAug --> NetAugConfig
    NetAug --> NetAugAutomation
    NetAug --> NetAugBaseModels
    NetAug --> NetAugAugModels
    NetAug --> NetAugUtilities
    NetAug --> TrainScript
    NetAug --> EvalScript

    TinyTL --> TinyTLDataset
    TinyTL --> TinyTLExpScripts
    TinyTL --> TinyTLCore
    TinyTL --> TinyTLTrainLauncher

    %% Click Events
    click MCUNet "https://github.com/mit-han-lab/tinyml/tree/master/mcunet"
    click NetAugConfig "https://github.com/mit-han-lab/tinyml/tree/master/netaug/configs"
    click TrainScript "https://github.com/mit-han-lab/tinyml/blob/master/netaug/train.py"
    click EvalScript "https://github.com/mit-han-lab/tinyml/blob/master/netaug/eval.py"
    click NetAugAutomation "https://github.com/mit-han-lab/tinyml/tree/master/netaug/bash"
    click NetAugBaseModels "https://github.com/mit-han-lab/tinyml/tree/master/netaug/models/base"
    click NetAugAugModels "https://github.com/mit-han-lab/tinyml/tree/master/netaug/models/netaug"
    click NetAugUtilities "https://github.com/mit-han-lab/tinyml/tree/master/netaug/utils"
    click TinyTLDataset "https://github.com/mit-han-lab/tinyml/tree/master/tinytl/dataset_setup_scripts"
    click TinyTLExpScripts "https://github.com/mit-han-lab/tinyml/tree/master/tinytl/exp_scripts"
    click TinyTLCore "https://github.com/mit-han-lab/tinyml/tree/master/tinytl/tinytl"
    click TinyTLTrainLauncher "https://github.com/mit-han-lab/tinyml/blob/master/tinytl_fgvc_train.py"

    %% Styles / Classes
    classDef container fill:#d3d3d3,stroke:#333,stroke-width:2px
    classDef configuration fill:#f9c,stroke:#333,stroke-width:2px
    classDef training fill:#f99,stroke:#333,stroke-width:2px
    classDef automation fill:#ffcc00,stroke:#333,stroke-width:2px
    classDef model fill:#9f9,stroke:#333,stroke-width:2px
    classDef utility fill:#99f,stroke:#333,stroke-width:2px
    classDef dataset fill:#fc9,stroke:#333,stroke-width:2px
    classDef experiment fill:#cff,stroke:#333,stroke-width:2px
    classDef core fill:#cfc,stroke:#333,stroke-width:2px
    classDef launcher fill:#dda0dd,stroke:#333,stroke-width:2px
```
