# jerinphilip/slimt architecture

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

- Interactive diagram: https://gitdiagram.com/jerinphilip/slimt
- Repository: https://github.com/jerinphilip/slimt

## Overview

##### Main Components

a) Core Components:
- Model Management Layer
- Text Processing Pipeline
- Matrix Multiplication Backends
- Vocabulary Management
- Language Model Interface
- Bindings Layer (Python/Java)

b) External Dependencies:
- Matrix Multiplication Libraries (intgemm/ruy/gemmology)
- SentencePiece (vocabulary handling)
- PCRE2 (regex operations)
- BLAS Provider (matrix operations)

**┌─ Application Layer ─────────────────────┐**
- CLI Interface (slimt-cli)            │
- Python/Java Bindings                 │
- ┘
- ↕
**┌─ Core Processing Layer ─────────────────┐**
- ┌─ Text Processing ─┐ ┌─ Model Engine ─┐│
- Splitter       │ │ - Transformer   ││
- TextProcessor  │ │ - Vocabulary    ││
- HTML Handler   │ │ - Shortlist     ││
- ┘ └────────────────┘ │
- ┘
- ↕
**┌─ Computation Layer ────────────────────┐**
- ┌─ Matrix Operations ─────────────────┐│
- SIMD Operations (AVX2/NEON)      ││
- Quantized Matrix Multiply        ││
- BLAS Operations                  ││
- ┘│
- ┘
- ↕
**┌─ External Dependencies ────────────────┐**
- intgemm/ruy/gemmology               │
- SentencePiece                       │
- PCRE2                              │
- BLAS Provider                      │
- ┘

##### Important Details to Highlight

a) Model Architecture Support:
- Transformer architecture components
- SSRU (Simpler Simple Recurrent Units) in decoder
- Support for both tiny and base models

b) Optimization Features:
- Quantization support (8-bit operations)
- SIMD optimization paths
- Runtime dispatch for different CPU architectures

##### Implementation Details

- How the `slimt/` directory components interact
- Binding system (`bindings/` directory)
- Test framework integration
- Configuration and build system integration

##### Performance Characteristics

A small section showing:
- Memory footprint for different model sizes
- Quantization impact (32-bit vs 8-bit)
- CPU architecture optimization paths

- Nested components
- Export to vector formats
- Easy maintenance and updates

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef frontend fill:#f96,stroke:#333
    classDef core fill:#69f,stroke:#333
    classDef compute fill:#9cf,stroke:#333
    classDef external fill:#9f9,stroke:#333
    classDef default fill:#fff,stroke:#333

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        CLI["CLI Interface"]
        Bindings["Language Bindings"]
        PythonBind["Python Bindings"]
        JavaBind["Java Bindings"]
        
        Bindings --> PythonBind
        Bindings --> JavaBind
    end

    %% Core Processing Layer
    subgraph CoreLayer["Core Processing Layer"]
        subgraph TextProc["Text Processing"]
            Splitter["Splitter"]
            TextProcessor["Text Processor"]
            HTMLHandler["HTML Handler"]
        end

        subgraph ModelEngine["Model Engine"]
            Transformer["Transformer"]
            Vocabulary["Vocabulary"]
            Shortlist["Shortlist"]
            ModelInterface["Model Interface"]
            Frontend["Frontend"]
            TensorOps["Tensor Operations"]
        end
    end

    %% Computation Layer
    subgraph CompLayer["Computation Layer"]
        subgraph MatrixOps["Matrix Operations"]
            SIMD["SIMD Operations"]
            QMM["Quantized Matrix Multiply"]
            AVX2["AVX2"]
            NEON["NEON"]
            SSE["SSE"]
            
            SIMD --> AVX2
            SIMD --> NEON
            SIMD --> SSE
        end
    end

    %% External Dependencies
    subgraph ExtDeps["External Dependencies"]
        Intgemm["Intgemm"]
        Ruy["Ruy"]
        Gemmology["Gemmology"]
        SentencePiece["SentencePiece"]
    end

    %% Relationships
    AppLayer --> CoreLayer
    CoreLayer --> CompLayer
    CompLayer --> ExtDeps

    %% Click events
    click CLI "https://github.com/jerinphilip/slimt/blob/main/app/main.cc"
    click PythonBind "https://github.com/jerinphilip/slimt/blob/main/bindings/python/slimt.cpp"
    click JavaBind "https://github.com/jerinphilip/slimt/blob/main/bindings/java/slimt.cpp"
    click Splitter "https://github.com/jerinphilip/slimt/blob/main/slimt/Splitter.hh"
    click TextProcessor "https://github.com/jerinphilip/slimt/blob/main/slimt/TextProcessor.hh"
    click HTMLHandler "https://github.com/jerinphilip/slimt/blob/main/slimt/HTML.hh"
    click Transformer "https://github.com/jerinphilip/slimt/blob/main/slimt/Transformer.hh"
    click Vocabulary "https://github.com/jerinphilip/slimt/blob/main/slimt/Vocabulary.hh"
    click Shortlist "https://github.com/jerinphilip/slimt/blob/main/slimt/Shortlist.hh"
    click SIMD "https://github.com/jerinphilip/slimt/tree/main/slimt/simd/"
    click QMM "https://github.com/jerinphilip/slimt/tree/main/slimt/qmm/"
    click AVX2 "https://github.com/jerinphilip/slimt/blob/main/slimt/simd/avx2.h"
    click NEON "https://github.com/jerinphilip/slimt/blob/main/slimt/simd/neon.h"
    click SSE "https://github.com/jerinphilip/slimt/blob/main/slimt/simd/sse.h"
    click Intgemm "https://github.com/jerinphilip/slimt/tree/main/3rd-party/intgemm/"
    click Ruy "https://github.com/jerinphilip/slimt/tree/main/3rd-party/ruy/"
    click Gemmology "https://github.com/jerinphilip/slimt/tree/main/3rd-party/gemmology/"
    click SentencePiece "https://github.com/jerinphilip/slimt/tree/main/3rd-party/sentencepiece/"
    click ModelInterface "https://github.com/jerinphilip/slimt/blob/main/slimt/Model.hh"
    click Frontend "https://github.com/jerinphilip/slimt/blob/main/slimt/Frontend.hh"
    click TensorOps "https://github.com/jerinphilip/slimt/blob/main/slimt/TensorOps.hh"

    %% Style applications
    class CLI,PythonBind,JavaBind frontend
    class Transformer,Vocabulary,Shortlist,ModelInterface,Frontend,TensorOps,Splitter,TextProcessor,HTMLHandler core
    class SIMD,QMM,AVX2,NEON,SSE compute
    class Intgemm,Ruy,Gemmology,SentencePiece external
```
