# shafinac/finetuning-llms architecture

> Architecture diagram of the GitHub repository shafinac/finetuning-llms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shafinac/finetuning-llms
- Repository: https://github.com/shafinac/finetuning-llms

## Overview

This repository combines two independent products: a Llama fine-tuning script and a Streamlit interface for comparing local Ollama models. The first workflow loads a base model, prepares FineTome data, trains with LoRA, and saves a GGUF model. The second lists available models, sends the same prompt to two selections, then presents generation metrics and optional BLEU-4/ROUGE-L comparisons. Source excerpts show the principal calls; README capability descriptions supplement the fine-tuning flow.

Main entry points: [`Model_Comparision/app/app.py`](https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py) (Comparison UI), [`finetune_llama3.2.py`](https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py) (Load model), [`Model_Comparision/app/eval.py`](https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/eval.py) (BLEU / ROUGE)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_finetune["Fine-tuning"]
  node_model_load["Load model"]
  node_lora["LoRA adapters"]
  node_data_prep["Chat data prep"]
  node_trainer_setup["Trainer setup"]
  node_training["Fine-tuning"]
  node_model_artifact["GGUF model"]
end

subgraph group_compare["Model comparison"]
  node_streamlit_ui["Comparison UI<br/>[app.py]"]
  node_model_listing["Model listing<br/>[app.py]"]
  node_generation["Paired generation<br/>[app.py]"]
  node_response_metrics["Speed metrics<br/>[app.py]"]
  node_text_cleanup["Text normalization<br/>[app.py]"]
  node_quality_metrics["BLEU / ROUGE<br/>[eval.py]"]
  node_comparison_results["Results and charts<br/>[app.py]"]
end

node_operator(("Operator"))
node_base_model["Base model"]
node_dataset_service["Hugging Face dataset"]
node_user(("Evaluator"))
node_ollama["Ollama service"]

node_operator -->|"runs script"| node_model_load
node_base_model -->|"loads weights"| node_model_load
node_model_load -->|"adapts model"| node_lora
node_dataset_service -->|"provides dataset"| node_data_prep
node_model_load -->|"supplies model"| node_trainer_setup
node_lora -->|"supplies adapted model"| node_trainer_setup
node_data_prep -->|"supplies training data"| node_trainer_setup
node_trainer_setup -->|"configures trainer"| node_training
node_training -->|"saves model"| node_model_artifact
node_user -->|"enters comparison"| node_streamlit_ui
node_streamlit_ui -->|"loads models"| node_model_listing
node_model_listing -->|"lists models"| node_ollama
node_streamlit_ui -->|"submits selections"| node_generation
node_generation -->|"requests completions"| node_ollama
node_generation -->|"measures generation"| node_response_metrics
node_generation -->|"strips echoed prompts"| node_text_cleanup
node_streamlit_ui -->|"computes reference scores"| node_quality_metrics
node_text_cleanup -->|"provides candidates"| node_quality_metrics
node_response_metrics -->|"displays measurements"| node_comparison_results
node_quality_metrics -->|"displays scores"| node_comparison_results
node_streamlit_ui -->|"renders comparison"| node_comparison_results

click node_model_load "https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py"
click node_lora "https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py"
click node_data_prep "https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py"
click node_trainer_setup "https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py"
click node_training "https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py"
click node_streamlit_ui "https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py"
click node_model_listing "https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py"
click node_generation "https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py"
click node_response_metrics "https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py"
click node_text_cleanup "https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py"
click node_quality_metrics "https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/eval.py"
click node_comparison_results "https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_model_load,node_lora,node_data_prep,node_trainer_setup,node_training,node_model_artifact toneBlue
class node_streamlit_ui,node_model_listing,node_generation,node_response_metrics,node_text_cleanup,node_quality_metrics,node_comparison_results toneAmber
class node_operator,node_base_model,node_dataset_service,node_user,node_ollama toneIndigo
```

## Components

### Fine-tuning

- [Load model](https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py): `finetune_llama3.2.py`
- [LoRA adapters](https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py): `finetune_llama3.2.py`
- [Chat data prep](https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py): `finetune_llama3.2.py`
- [Trainer setup](https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py): `finetune_llama3.2.py`
- [Fine-tuning](https://github.com/shafinac/finetuning-llms/blob/main/finetune_llama3.2.py): `finetune_llama3.2.py`
- **GGUF model**

### Model comparison

- [Comparison UI](https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py): `Model_Comparision/app/app.py`
- [Model listing](https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py): `Model_Comparision/app/app.py`
- [Paired generation](https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py): `Model_Comparision/app/app.py`
- [Speed metrics](https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py): `Model_Comparision/app/app.py`
- [Text normalization](https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py): `Model_Comparision/app/app.py`
- [BLEU / ROUGE](https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/eval.py): `Model_Comparision/app/eval.py`
- [Results and charts](https://github.com/shafinac/finetuning-llms/blob/main/Model_Comparision/app/app.py): `Model_Comparision/app/app.py`

### Other components

- **Operator**
- **Base model**
- **Hugging Face dataset**
- **Evaluator**
- **Ollama service**

## Connections

- Operator → Load model: runs script (evidence: `README.md`)
- Base model → Load model: loads weights (evidence: `finetune_llama3.2.py`)
- Load model → LoRA adapters: adapts model (evidence: `finetune_llama3.2.py`)
- Hugging Face dataset → Chat data prep: provides dataset (evidence: `finetune_llama3.2.py`)
- Load model → Trainer setup: supplies model (evidence: `finetune_llama3.2.py`)
- LoRA adapters → Trainer setup: supplies adapted model (evidence: `finetune_llama3.2.py`)
- Chat data prep → Trainer setup: supplies training data (evidence: `finetune_llama3.2.py`)
- Trainer setup → Fine-tuning: configures trainer (evidence: `finetune_llama3.2.py`)
- Fine-tuning → GGUF model: saves model (evidence: `finetune_llama3.2.py`)
- Evaluator → Comparison UI: enters comparison (evidence: `Model_Comparision/app/app.py`)
- Comparison UI → Model listing: loads models (evidence: `Model_Comparision/app/app.py`)
- Model listing → Ollama service: lists models (evidence: `Model_Comparision/app/app.py`)
- Comparison UI → Paired generation: submits selections (evidence: `Model_Comparision/app/app.py`)
- Paired generation → Ollama service: requests completions (evidence: `Model_Comparision/app/app.py`)
- Paired generation → Speed metrics: measures generation (evidence: `Model_Comparision/app/app.py`)
- Paired generation → Text normalization: strips echoed prompts (evidence: `Model_Comparision/app/app.py`)
- Comparison UI → BLEU / ROUGE: computes reference scores (evidence: `Model_Comparision/app/app.py`)
- Text normalization → BLEU / ROUGE: provides candidates (evidence: `Model_Comparision/app/app.py`)
- Speed metrics → Results and charts: displays measurements (evidence: `Model_Comparision/app/app.py`)
- BLEU / ROUGE → Results and charts: displays scores (evidence: `Model_Comparision/app/app.py`)
- Comparison UI → Results and charts: renders comparison (evidence: `Model_Comparision/app/app.py`)
