# calad0i/quantizers architecture

> Architecture diagram of the GitHub repository calad0i/quantizers, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/calad0i/quantizers
- Repository: https://github.com/calad0i/quantizers

## Overview

##### Main Components

a) Core Quantization Modules:
- Fixed-Point Quantizer
- Minifloat Quantizer
- Binary Quantizer
- Stateful Quantizers

b) Implementation Variants:
- Keras Implementation
- NumPy Implementation
- C++ Reference Implementation

**Top Level (API Layer):**
- Stateless Quantizer Interface
- Stateful Quantizer Interface

**Middle Level (Implementation Layer):**
- Keras Backend
- NumPy Backend
- C++ Reference Implementation

**Bottom Level (Core Operations):**
- Binary Operations
- Fixed-Point Operations
- Minifloat Operations

##### Component Relationships

- How the API layer interfaces with different backend implementations
- Relationship between stateful and stateless quantizers
- Demonstrate the flow from high-level quantizer calls to low-level numerical operations

##### Specific Elements

a) Quantizer Components:
- Rectangle: Fixed-Point Quantizer
- Hexagon: Minifloat Quantizer
- Circle: Binary/Ternary Quantizer
- Diamond: Stateful Quantizers

b) Implementation Variants:
- Blue: Keras Implementation
- Green: NumPy Implementation
- Orange: C++ Reference

c) Data Flow:

##### Technical Details to Emphasize

- Relationship between Python implementations and C++ reference code
- Where gradients are computed (Keras implementation)
- Components that support stochastic rounding
- Bit-accurate precision matching process

##### Additional Notes

- Version compatibility information (Python ≥3.10, Keras ≥3.0)
- Hardware synthesis capabilities through HLS

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef api fill:#f9f,stroke:#333,stroke-width:2px
    classDef keras fill:#b3e0ff,stroke:#333,stroke-width:2px
    classDef numpy fill:#98fb98,stroke:#333,stroke-width:2px
    classDef cpp fill:#ffa07a,stroke:#333,stroke-width:2px
    classDef core fill:#ddd,stroke:#333,stroke-width:2px

    %% API Layer
    subgraph API
        SQI[Stateless Quantizer Interface]:::api
        SFQI[Stateful Quantizer Interface]:::api
    end

    %% Implementation Layer
    subgraph Implementations
        KB[Keras Backend]:::keras
        NB[NumPy Backend]:::numpy
        CPP[C++ Reference]:::cpp
    end

    %% Core Quantizers
    subgraph Quantizers
        FPQ[Fixed-Point Quantizer]
        MFQ[Minifloat Quantizer]
        BQ[Binary Quantizer]
        SFQ[Stateful Quantizers]
    end

    %% Core Operations
    subgraph Operations
        BO[Binary Operations]:::core
        FPO[Fixed-Point Operations]:::core
        MFO[Minifloat Operations]:::core
    end

    %% Relationships
    SQI --> KB
    SQI --> NB
    SQI --> CPP
    SFQI --> SFQ
    KB --> FPQ
    KB --> MFQ
    KB --> BQ
    NB --> FPQ
    NB --> MFQ
    NB --> BQ
    CPP --> FPQ
    CPP --> MFQ
    CPP --> BQ
    FPQ --> FPO
    MFQ --> MFO
    BQ --> BO
    SFQ --> FPQ
    SFQ --> MFQ
    SFQ --> BQ

    %% Click Events
    click FPQ "https://github.com/calad0i/quantizers/blob/master/src/quantizers/fixed_point/fixed_point_ops.py"
    click MFQ "https://github.com/calad0i/quantizers/blob/master/src/quantizers/minifloat/float_point_ops.py"
    click BQ "https://github.com/calad0i/quantizers/blob/master/src/quantizers/binary/binary_ops.py"
    click SFQ "https://github.com/calad0i/quantizers/blob/master/src/quantizers/stateful_quantizers.py"
    click CPP "https://github.com/calad0i/quantizers/blob/master/test/cpp_source/quantizers.h"
    click NB "https://github.com/calad0i/quantizers/blob/master/src/quantizers/fixed_point/fixed_point_ops_np.py"

    %% Legend
    subgraph Legend
        L1[API Components]:::api
        L2[Keras Implementation]:::keras
        L3[NumPy Implementation]:::numpy
        L4[C++ Reference]:::cpp
        L5[Core Operations]:::core
    end
```
