# sovit-123/lm_sft architecture

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

- Interactive diagram: https://gitdiagram.com/sovit-123/lm_sft
- Repository: https://github.com/sovit-123/lm_sft

## Overview

##### Main Components
- SFT Core Components:
- Training/finetuning pipelines provided as Jupyter notebooks in various directories (e.g., under “chat_inference” and “examples”).
- Examples are organized into subcategories such as assistant_sft, coding_sft, qa_sft, research_project, and summarize_sft.
- Inference Modules:
- The “chat_inference” directory contains several inference notebooks and utilities (for instance, streaming_utils.py) that illustrate how conversational models operate.
- Task-Specific Modules:
- Each subdirectory under “examples” represents a task-oriented SFT project, clearly splitting off use cases such as assistant behavior, code generation, Q&A, and summarization.
- Utility and Configuration Layers:
- The presence of requirements.txt and a README indicates dependency management and environment setup, while the use of Conda is noted.

##### Relationships and Interactions
- Data Flow:
- Data (input examples, training datasets) would be fed into the various SFT notebooks.
- Fine-tuning outputs (trained models) are subsequently utilized by the chat inference or other evaluation pipelines.
- Shared Core:
- There is a shared architecture/principle where the same SFT methods are applied across different tasks. This could be illustrated as a common “Training Engine” that branches off to specific use-case modules.
- Development/Testing:
- The notebooks serve as interactive components for both development and demonstration, and are likely run in a common Python environment (managed via Conda and PyTorch as suggested).

##### Architectural Patterns and Design Principles
- Modularity:
- The file tree naturally divides into modules based on tasks and use cases. Emphasize that the system is modularly designed, with each example (task-specific notebook) acting as an independent module that plugs into a broader fine-tuning process.
- Experimentation/Iterative Prototyping:
- Reusability:
- Shared utils such as streaming_utils.py demonstrate that some code is reused across different fine-tuning/inference tasks.

##### Components and Connections
a. At a high level, break the system into:
- Environment and Dependency Management: Conda setup, PyTorch installation, requirements.txt.
- Fine-tuning / Training Component: Central “SFT Engine” (represented abstractly) that takes in training data and model definitions from various experiments and produces fine-tuned models.
- Inference/Deployment Component: The “chat_inference” module, which picks up trained models and enables downstream tasks like conversational AI.
- Task-specific Modules: Separate blocks representing Assistant SFT, Coding SFT, QA SFT, Summarization SFT, etc., each showing their unique training/inference notebooks.
b. Directional relationships:
c. Use clear labels and legends:

## Diagram (Mermaid)

```mermaid
flowchart TD
    E["Environment & Dependency\n(requirements.txt, README.md)"]:::environment
    SFT["SFT Engine (Training/Finetuning Pipelines)"]:::training
    ASFT["Assistant SFT Module"]:::module
    CSFT["Coding SFT Module"]:::module
    QSFT["QA SFT Module"]:::module
    SSFT["Summarization Module"]:::module
    CI["Chat Inference Module"]:::inference
    UTIL["Utility: streaming_utils.py"]:::inference

    E -->|"setup"| SFT
    SFT -->|"trains models"| ASFT
    SFT -->|"trains models"| CSFT
    SFT -->|"trains models"| QSFT
    SFT -->|"trains models"| SSFT
    SFT -->|"provides models"| CI
    ASFT -->|"fine-tuned output"| CI
    CSFT -->|"fine-tuned output"| CI
    QSFT -->|"fine-tuned output"| CI
    SSFT -->|"fine-tuned output"| CI
    CI -->|"utilizes"| UTIL

    click E "https://github.com/sovit-123/lm_sft/blob/master/requirements.txt"
    click E "https://github.com/sovit-123/lm_sft/blob/master/README.md"
    click SFT "https://github.com/sovit-123/lm_sft/tree/master/examples/assistant_sft"
    click ASFT "https://github.com/sovit-123/lm_sft/tree/master/examples/assistant_sft"
    click CSFT "https://github.com/sovit-123/lm_sft/tree/master/examples/coding_sft"
    click QSFT "https://github.com/sovit-123/lm_sft/tree/master/examples/qa_sft"
    click SSFT "https://github.com/sovit-123/lm_sft/tree/master/examples/summarize_sft"
    click SSFT "https://github.com/sovit-123/lm_sft/tree/master/examples/research_project/opt_summarizer"
    click CI "https://github.com/sovit-123/lm_sft/tree/master/chat_inference"
    click UTIL "https://github.com/sovit-123/lm_sft/blob/master/chat_inference/streaming_utils.py"

    classDef environment fill:#AED6F1,stroke:#1F618D,stroke-width:2px
    classDef training fill:#FAD7A0,stroke:#D35400,stroke-width:2px
    classDef module fill:#D5F5E3,stroke:#145A32,stroke-width:2px
    classDef inference fill:#FADBD8,stroke:#922B21,stroke-width:2px
```
