# eml-eda/plinio architecture

> Architecture diagram of the GitHub repository eml-eda/plinio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eml-eda/plinio
- Repository: https://github.com/eml-eda/plinio

## Overview

##### Project type and purpose
- PLiNIO is an open-source Python library (built on PyTorch) for gradient-based, hardware-aware DNN inference optimization.
- Its main goal is to let users plug lightweight optimization (DNAS, mixed-precision search, pruning) into their standard training loop with minimal code changes.

##### File structure
- Top level:
- setup.py, requirements.txt – packaging and installation scripts
- README.md, LICENSE – documentation and license
- examples/ – Jupyter notebooks & helper scripts demonstrating usage
- unit_test/ – model definitions and test suites
- Core package `plinio/`:
- cost/ – hardware cost models (generic and platform-specific)
- graph/ – representation, annotation, transformation, feature extraction of DNN computation graph
- methods/ – optimization strategies subdivided into:
– dnas_base (core DNAS framework)
– supernet (coarse layer selection)
– pit (fine-grained pruning)
– mps (mixed-precision search) with multiple backends (diana, onnx, match, maupiti)
– odimo_mps (multi-accelerator mapping)
- regularizers/ – loss regularizers for cost terms and constraints
- __init__.py – public API entry points
- Supporting directories: `.assets/` (logo), `.vscode/` (editor settings), `.gitignore`

##### README for additional insights
- Confirms four main optimization methods (SuperNet, PIT, MPS, ODiMO MPS)
- Highlights cost modeling sub-package and regularizers for flexible loss terms
- Usage pattern: user imports a Method class, invokes `.search(...)` or similar, and plugs `model.cost` or `regularizer(model)` into the loss

1) User Training Loop (PyTorch)
2) PLiNIO Public API
3) Graph Module (`plinio.graph`)
4) Cost Models (`plinio.cost`)
5) Optimization Methods (`plinio.methods`)
– DNAS Base
– SuperNet
– PIT
– MPS (+ backends)
– ODiMO MPS
6) Regularizers (`plinio.regularizers`)
7) Examples & Notebooks
8) Unit Tests & CI
- Training Loop → calls → PLiNIO Public API
- Public API → requests → Graph Module to build/annotate model graph
- Public API → queries → Cost Models to compute cost metrics
- Public API → dispatches to → Selected Optimization Method
- Optimization Methods → use → Graph Module & Cost Models internally
- MPS Method → loads → specific backends (Diana, ONNX, Match, Maupiti)
- Public API → returns → modified model and cost attributes
- Training Loop ← consumes ← model.cost or regularizer(model) from Regularizers
- Examples & Notebooks illustrate → usage connecting Training Loop and PLiNIO API
- Unit Tests validate → each module and end-to-end flows
c. Architectural patterns & principles:
- Modular “plugin” design: new methods, cost models, backends, regularizers drop into their respective subpackages
- Strategy pattern: Method classes encapsulate different optimization algorithms
- Factory or registry for quantization backends inside MPS
- Clear separation of concerns: graph construction, cost calculation, optimization logic, and loss regularization
d. Key technologies & frameworks:
- Python 3.x, PyTorch tensors and modules
- Jupyter notebooks for examples
- pytest (or unittest) for unit_test
- setup.py & pip for distribution

##### Essential architectural elements
- Plugin architecture and extension points
- Flow from user loop → PLiNIO API → internal modules → back to loop is obvious

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    subgraph "User Layer"
        TrainingLoop["User Training Loop (PyTorch)"]:::user
        Examples["Examples & Notebooks"]:::user
    end

    %% Public API
    PLiNIOAPI["PLiNIO Public API"]:::user

    %% Core Engine
    subgraph "Core Engine"
        subgraph "Graph Module"
            Graph["plinio.graph"]:::core
        end
        subgraph "Cost Models"
            Cost["plinio.cost"]:::core
        end
        subgraph "Optimization Methods"
            DNAS["DNAS Base"]:::method
            SuperNet["SuperNet"]:::method
            PIT["PIT"]:::method
            MPS["MPS"]:::method
            ODiMO["ODiMO MPS"]:::method
        end
        Regularizers["Regularizers"]:::reg
    end

    %% Unit Tests & CI
    Tests["Unit Tests & CI"]:::test

    %% Connections
    TrainingLoop -->|calls| PLiNIOAPI
    Examples -->|demonstrate usage| TrainingLoop

    PLiNIOAPI -->|builds/annotates| Graph
    PLiNIOAPI -->|computes cost| Cost
    PLiNIOAPI -->|dispatches to| DNAS
    PLiNIOAPI -->|dispatches to| SuperNet
    PLiNIOAPI -->|dispatches to| PIT
    PLiNIOAPI -->|dispatches to| MPS
    PLiNIOAPI -->|dispatches to| ODiMO

    DNAS -->|uses| Graph
    DNAS -->|uses| Cost
    SuperNet -->|uses| Graph
    SuperNet -->|uses| Cost
    PIT -->|uses| Graph
    PIT -->|uses| Cost
    MPS -->|uses| Graph
    MPS -->|uses| Cost
    ODiMO -->|uses| Graph
    ODiMO -->|uses| Cost

    Regularizers -->|provides regularizers to| TrainingLoop

    Tests -->|validate| Graph
    Tests -->|validate| Cost
    Tests -->|validate| DNAS
    Tests -->|validate| SuperNet
    Tests -->|validate| PIT
    Tests -->|validate| MPS
    Tests -->|validate| ODiMO
    Tests -->|validate| Regularizers

    %% Click Events
    click TrainingLoop "https://github.com/eml-eda/plinio/blob/main/examples/utils/train.py"
    click Examples "https://github.com/eml-eda/plinio/tree/main/examples/"
    click PLiNIOAPI "https://github.com/eml-eda/plinio/blob/main/plinio/__init__.py"
    click Graph "https://github.com/eml-eda/plinio/tree/main/plinio/graph/"
    click Cost "https://github.com/eml-eda/plinio/tree/main/plinio/cost/"
    click DNAS "https://github.com/eml-eda/plinio/blob/main/plinio/methods/dnas_base/dnas.py"
    click SuperNet "https://github.com/eml-eda/plinio/blob/main/plinio/methods/supernet/supernet.py"
    click PIT "https://github.com/eml-eda/plinio/blob/main/plinio/methods/pit/pit.py"
    click MPS "https://github.com/eml-eda/plinio/blob/main/plinio/methods/mps/mps.py"
    click ODiMO "https://github.com/eml-eda/plinio/blob/main/plinio/methods/odimo_mps/odimo_mps.py"
    click Regularizers "https://github.com/eml-eda/plinio/blob/main/plinio/regularizers/base_regularizer.py"
    click Tests "https://github.com/eml-eda/plinio/tree/main/unit_test/"

    %% Styles
    classDef core fill:#bbdefb,stroke:#2196f3
    classDef method fill:#fff9c4,stroke:#fbc02d
    classDef reg fill:#ffe0b2,stroke:#fb8c00
    classDef user fill:#c8e6c9,stroke:#388e3c
    classDef test fill:#e0e0e0,stroke:#9e9e9e
```
