# predibase/llm_distillation_playbook architecture

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

- Interactive diagram: https://gitdiagram.com/predibase/llm_distillation_playbook
- Repository: https://github.com/predibase/llm_distillation_playbook

## Overview

##### Main Components
- Application Layer:
– The “app” directory contains the core application logic. Notice that there are submodules for initialization (app/init) and two variants of S3 logging (app/s3_logging vs. app/s3_logging_threaded). These indicate that the playbook supports synchronous and asynchronous logging of requests/results.
- Configuration Module:
– The “configs” directory holds YAML configuration files that likely parameterize the behavior of the different application modules.
- Data Layer:
– The “data” directory is organized to support different parts of the distillation workflow. It has:
▪ “data_pools” – raw CSV files (with variants such as test and train datasets).
▪ “dataset_subsets” – multiple subsets, including examples processed for different LLM versions (gpt-3.5-turbo, gpt-4-1106-preview, etc.), along with associated prompts, metrics, and parsed outputs.
▪ “original_data” – the source CSV files for training and evaluation.
- Data Preparation Pipeline:
– The “jigsaw_data_prep” folder includes scripts and notebooks that are used to preprocess and evaluate data (e.g., for toxic comment classification via evaluation, label parsing, and subset generation). This module demonstrates how to transform raw data into a form that is ready for training or evaluation.
- Notebooks and Documentation:
– Jupyter Notebooks like “profile_jigsaw.ipynb” are used for exploratory analysis and model profiling.
- Ancillary Resources:
– “requirements.txt” for dependency management and “.vscode” configuration files indicate development environment support.

##### Relationships and Interactions
- Data Flow:
– The logging apps (app/s3_logging and app/s3_logging_threaded) will capture requests and responses from the teacher models (used for distillation) and send these logs to external storage (presumably S3 or a similar service).
– Configurations (from YAML files) drive the behavior of these logging and initialization scripts.
– The raw data (both training and testing CSV files) is processed by the “jigsaw_data_prep” scripts – feeding into the distillation experiments as described in the README.
- Modular Communication:
– The separation between “app/init” and “app/s3_logging” shows a clear modular design. One module initializes and maybe serves model requests, while another handles logging asynchronously.
– The processed data stored in “data/dataset_subsets” (including the multiple examples with different prompt versions) informs the evaluation metrics and comparisons (teacher vs. student performance) discussed in the README.
- Deployment/Monitoring:
– The README also contains guidelines for deployment and monitoring, tying these modules together as part of a complete production pipeline.

##### Architectural Patterns and Technologies
- Separation of Concerns:
– Each folder (app, configs, data, jigsaw_data_prep) represents a different concern: application logic, configuration management, data storage/processing, and data preparation.
- Asynchronous Logging Pattern:
- Configuration Driven Behavior:
– Using YAML configurations shows the reliance on external settings which can be modified without changing the code base.
- Data Pipeline Management:
– The structure of datasets (with variants tailored for different LLM versions and evaluation criteria) is central to the distillation process, as described in the playbook. This corresponds to a multi-stage data processing pipeline.
- Technologies:
– Python is the core language (as seen by .py scripts), with Jupyter notebooks for experiments.
– YAML (for configs) and CSV files (for datasets) are also key technologies.
– External services such as Amazon S3 are implied in the logging modules for production-level logging.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration Management
    subgraph "Configuration Management"
        Configs["Configuration Files"]:::configs
    end

    %% Application Layer
    subgraph "Application Layer"
        Init["Initialization Module"]:::app
        S3Sync["Synchronous S3 Logging"]:::app
        S3Async["Asynchronous S3 Logging (Threaded)"]:::app
    end

    %% Data Management
    subgraph "Data Management"
        Raw["Raw Data (Data Pools)"]:::data
        Processed["Processed Datasets (Dataset Subsets)"]:::data
        Original["Original Source Data"]:::data
    end

    %% Data Preparation Pipeline
    subgraph "Data Preparation Pipeline"
        DataPrep["Jigsaw Data Preparation"]:::dataprep
    end

    %% Exploratory Analysis & Profiling
    subgraph "Exploratory Analysis & Profiling"
        Notebooks["Profiling Notebooks"]:::notebook
    end

    %% Ancillary Resources
    subgraph "Ancillary Resources"
        Dependency["Dependency Management"]:::ancillary
        Docs["Documentation & Visual Assets"]:::ancillary
    end

    %% External Service
    ExternalLogging["External Logging Service (S3)"]:::external

    %% Relationships
    Configs --> Init
    Configs --> S3Sync
    Configs --> S3Async

    Init --> S3Sync
    Init --> S3Async
    S3Sync --> ExternalLogging
    S3Async --> ExternalLogging

    Raw --- DataPrep
    Original --- DataPrep
    DataPrep --> Processed
    Processed --> Notebooks

    %% Ancillary connections (guidelines and support)
    Docs --- Configs
    Dependency --- Configs

    %% Click Events
    click Init "https://github.com/predibase/llm_distillation_playbook/blob/main/app/init/app.py"
    click S3Sync "https://github.com/predibase/llm_distillation_playbook/blob/main/app/s3_logging/app.py"
    click S3Async "https://github.com/predibase/llm_distillation_playbook/blob/main/app/s3_logging_threaded/app.py"
    click Configs "https://github.com/predibase/llm_distillation_playbook/tree/main/configs/"
    click Raw "https://github.com/predibase/llm_distillation_playbook/tree/main/data/data_pools/"
    click Processed "https://github.com/predibase/llm_distillation_playbook/tree/main/data/dataset_subsets/"
    click Original "https://github.com/predibase/llm_distillation_playbook/tree/main/data/original_data/"
    click DataPrep "https://github.com/predibase/llm_distillation_playbook/tree/main/jigsaw_data_prep/"
    click Notebooks "https://github.com/predibase/llm_distillation_playbook/blob/main/profile_jigsaw.ipynb"
    click Dependency "https://github.com/predibase/llm_distillation_playbook/blob/main/requirements.txt"
    click Docs "https://github.com/predibase/llm_distillation_playbook/blob/main/README.md"

    %% Styles
    classDef app fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef configs fill:#FFFF99,stroke:#000,stroke-width:1px;
    classDef data fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef dataprep fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef notebook fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef ancillary fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef external fill:#87CEFA,stroke:#000,stroke-width:1px;
```
