# agokrani/distillkitplus architecture

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

- Interactive diagram: https://gitdiagram.com/agokrani/distillkitplus
- Repository: https://github.com/agokrani/distillkitplus

## Overview

##### Main Components
- Core Distillation Modules: These are housed inside the “components” directory and include modules for configuration (config.py), handling datasets (dataset.py), formatting (formatters.py), model definitions (models.py), and the training process (trainer.py).
- Configuration Layer: The “config” directory contains various config files:
– Default configuration for projects (default_config.json)
– Specialized configurations for distributed training using Accelerate (YAML files under accelerate_configs) and DeepSpeed (JSON files under deepspeed_configs).
- Execution Scripts:
– The “scripts” directory is subdivided into two regions: “local” and “modal”. “Local” scripts (e.g., generate_logits.py and distill_logits.py) enable running the toolkit from a typical command-line environment. “Modal” scripts provide an integration for running on Modal, internally handling distribute settings and execution configurations based on the config file.
- Setup and Dependencies: Files like requirements.txt, setup.py, and the README indicate how to install and initialize the toolkit, which frames the project as a Python-based distillation tool.

##### Relationships and Interactions
- The execution scripts (in both “local” and “modal”) serve as entry points. They load configuration settings from the JSON and YAML files (found in the “config” directory) to determine how to set up training and distillation sessions.
- These scripts interact with the core functionalities implemented in the “components” folder. For instance, the scripts invoke functions for generating teacher logits (using models and dataset handling) and then kick off the distillation process using the trainer module.
- The configuration files dictate runtime behaviors that may include distributed training parameters (via Accelerate and DeepSpeed integrations) and optional Modal execution.

##### Architectural Patterns and Design Principles
- Modular Architecture: Separation of concerns is evident by dividing the project into clearly defined modules (components for core logic, config for settings, and scripts for execution).
- Configurable Execution: By externalizing key parameters into JSON and YAML config files, the system supports dynamic switching between local execution, distributed training, and Modal integration.
- Extensibility: The toolkit supports multiple execution environments (local vs. modal) and advanced functionalities (logit distillation, LoRA, quantization) that are extensible with minimal changes to the codebase.

##### Relevant Technologies and Libraries
- Python is the main programming language.
- Accelerate and DeepSpeed are integrated for efficient distributed training.
- Modal is utilized as an optional platform to run scripts in an alternative cloud or remote environment.
- Additional libraries likely include those for deep learning model manipulation, dataset processing, and optimization.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Setup and Dependencies
    Dep["Setup & Dependencies"]:::dependency

    %% Configuration Layer
    subgraph "Configuration Layer"
        Default["Default Config (default_config.json)"]:::config
        Accel["Accelerate Configs"]:::config
        DeepSpeed["DeepSpeed Configs"]:::config
    end

    %% Execution Scripts
    subgraph "Execution Scripts"
        LocalA["Local: generate_logits.py"]:::execution
        LocalB["Local: distill_logits.py"]:::execution
        subgraph "Modal Execution"
            ModalA["Modal: generate_logits.py"]:::execution
            ModalB["Modal: distill_logits.py"]:::execution
        end
    end

    %% Core Distillation Modules
    subgraph "Core Distillation Modules"
        Cfg["Config Module"]:::modules
        Data["Dataset Module"]:::modules
        Form["Formatters Module"]:::modules
        Mod["Models Module"]:::modules
        Train["Trainer Module"]:::modules
    end

    %% Distributed Training Integrations
    IntAccel["Accelerate"]:::integration
    IntDeep["DeepSpeed"]:::integration

    %% Relationships
    Dep --> Default
    Dep --> LocalA
    Dep --> LocalB
    Dep --> ModalA
    Dep --> ModalB

    Default -->|"loads"| LocalA
    Default -->|"loads"| LocalB
    Default -->|"loads"| ModalA
    Default -->|"loads"| ModalB

    Accel -->|"configures"| IntAccel
    DeepSpeed -->|"configures"| IntDeep

    LocalA -->|"invokes"| Cfg
    LocalB -->|"invokes"| Cfg
    ModalA -->|"invokes"| Cfg
    ModalB -->|"invokes"| Cfg

    Cfg -->|"utilizes"| Data
    Cfg -->|"utilizes"| Form
    Cfg -->|"utilizes"| Mod
    Cfg -->|"starts"| Train

    IntAccel -->|"integrates"| Train
    IntDeep -->|"integrates"| Train

    %% Styles
    classDef dependency fill:#ffc,stroke:#333,stroke-width:2px;
    classDef config fill:#f9f,stroke:#333,stroke-width:2px;
    classDef execution fill:#bbf,stroke:#333,stroke-width:2px;
    classDef modules fill:#afa,stroke:#333,stroke-width:2px;
    classDef integration fill:#fdd,stroke:#333,stroke-width:2px;

    %% Click Events
    click Cfg "https://github.com/agokrani/distillkitplus/blob/main/components/config.py"
    click Data "https://github.com/agokrani/distillkitplus/blob/main/components/dataset.py"
    click Form "https://github.com/agokrani/distillkitplus/blob/main/components/formatters.py"
    click Mod "https://github.com/agokrani/distillkitplus/blob/main/components/models.py"
    click Train "https://github.com/agokrani/distillkitplus/blob/main/components/trainer.py"

    click Default "https://github.com/agokrani/distillkitplus/blob/main/config/default_config.json"
    click Accel "https://github.com/agokrani/distillkitplus/tree/main/config/accelerate_configs/"
    click DeepSpeed "https://github.com/agokrani/distillkitplus/tree/main/config/deepspeed_configs/"

    click LocalA "https://github.com/agokrani/distillkitplus/blob/main/scripts/local/generate_logits.py"
    click LocalB "https://github.com/agokrani/distillkitplus/blob/main/scripts/local/distill_logits.py"
    click ModalA "https://github.com/agokrani/distillkitplus/blob/main/scripts/modal/generate_logits.py"
    click ModalB "https://github.com/agokrani/distillkitplus/blob/main/scripts/modal/distill_logits.py"
    click Dep "https://github.com/agokrani/distillkitplus/blob/main/setup.py"
```
