Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 Bank LLM Fine-Tuning (PEFT/LoRA)

Parameter-Efficient Fine-Tuning of TinyLlama-1.1B for bank support LoRA adapters — training only 0.10% of parameters | Streamlit Chat UI | Cloud-to-Local Pipeline


🚀 Live Demo

🔗 [bank-llm-finetuning.streamlit.app](https://bank-llm-finetuning-wgasp8j9yzxgk4pxnsiydu.streamlit.app/)


🛠 Tech Stack

Component Technology
Base Model TinyLlama-1.1B-Chat-v1.0
Fine-Tuning Method PEFT / LoRA (Low-Rank Adaptation)
Training Framework trl (SFTTrainer), accelerate
LLM Ecosystem HuggingFace transformers, datasets, peft
Deep Learning PyTorch
Frontend Streamlit (chat UI with session memory)
Training Environment Google Colab (NVIDIA T4 GPU)
Inference Environment CPU (local + Streamlit Cloud)

⚙️ Architecture

📂 data/train.jsonl  (custom bank dialog dataset)
        │
        ▼
┌─────────────────────────────────────────┐
│           src/train_lora.py             │
│                                         │
│  TinyLlama-1.1B (frozen weights)        │
│         +                               │
│  LoRA Adapter (only these are trained)  │
│  • rank=8                               │
│  • trainable params: 1,126,400          │
│  • 0.10% of entire network              │
│         │                               │
│  SFTTrainer → Supervised Fine-Tuning    │
└──────────────────┬──────────────────────┘
                   │
                   ▼
        models/lora_adapter/   (~5 MB)
                   │
        ┌──────────┴──────────┐
        ▼                     ▼
src/chat_bot.py          app.py
(Console chat)           (Streamlit Web UI)
        │                     │
        └──────────┬──────────┘
                   ▼
    TinyLlama-1.1B + PeftModel
    CPU inference (~5-15 sec/response)

🔑 Key Features

1. Low-Rank Adaptation (LoRA)

Вместо дорогостоящего Full Fine-Tuning всей модели обучается только компактный "адаптер" — матрицы низкого ранга, внедрённые в слои Attention. Снижает требования к GPU в 10-100x:

lora_config = LoraConfig(
    r=8,                                      # Adapter matrix rank
    lora_alpha=32,                            # Scaling coefficient
    target_modules=["q_proj", "v_proj"],      # Attention layers to adapt
    task_type=TaskType.CAUSAL_LM
)
# Result: 1,126,400 trainable params (0.10% of 1.1B)

2. Supervised Fine-Tuning (SFT)

Датасет в формате диалогов <|user|><|assistant|> обучает модель отвечать в роли банковского консультанта. Используется SFTTrainer из trl — production-стандарт для RLHF и SFT пайплайнов.

3. Cloud-to-Local Pipeline

Google Colab T4 GPU → training → export adapter (~5MB)
        ↓
Local CPU / Streamlit Cloud → PeftModel.from_pretrained()

Дорогое обучение в облаке, дешёвый инференс локально — паттерн реального production.

4. Streamlit Chat UI

Web-интерфейс с памятью диалога, настройками генерации и примерами вопросов:

  • Temperature slider (0.1 — 1.0)
  • Max tokens slider (20 — 150)
  • 5 built-in example questions
  • Session chat history

🔬 Lessons Learned

Модель обучалась на микро-датасете. Честный анализ результатов:

Observation Cause Production Solution
Underfitting Too few training examples Dataset 10,000+ dialogs
Hallucinations English base model + Russian domain Russian base model (Qwen, etc.)
Slow convergence Low rank r=8 for complex task Increase rank to 16-32

Conclusion: Pipeline architecture is fully ready to scale. For production quality in Russian — need 10,000+ examples and a multilingual base model. The goal of this project is to demonstrate the LoRA pipeline, not production quality.


🚀 Quick Start

1. Install dependencies

pip install -r requirements.txt

2. Train the model (GPU required)

# Recommended: Google Colab with T4/A100 GPU
python src/train_lora.py
# → adapter saved to models/lora_adapter/ (~5MB)

3. Console inference (CPU)

python src/chat_bot.py
# Downloads base model (~600MB) automatically
# Loads local LoRA adapter

4. Web UI (Streamlit)

streamlit run app.py
# Opens chat interface at http://localhost:8501

📁 Project Structure

bank-llm-finetuning/
├── data/
│   └── train.jsonl           # Custom bank dialog dataset (Q&A)
├── models/
│   └── lora_adapter/         # Trained LoRA adapter weights (~5MB)
├── src/
│   ├── train_lora.py         # Fine-Tuning: LoRA + SFTTrainer
│   └── chat_bot.py           # Console inference: base model + adapter
├── app.py                    # Streamlit chat UI
├── requirements.txt
└── README.md

🔮 Roadmap

Feature Description
Larger dataset Expand to 1,000+ bank dialogs for quality improvement
Qwen base model Switch to multilingual model for better Russian support
rank=16-32 Higher LoRA rank for complex financial domain
RLHF Reinforcement Learning from Human Feedback

🔗 Related Projects

Part of a Fintech LLM ecosystem:

💡 LLM Architecture progression: RAG (bank-ai-assistant) — external knowledge, no training Fine-Tuning (this project) — knowledge baked into weights Agentic AI (financial-ai-agent) — autonomous tool calling

Three different approaches to building intelligent bank assistants.


📫 Author

Rashid Nurbekov — ML Engineer | Fintech & Generative AI | Almaty, Kazakhstan 🇰🇿

💡 Эволюция подхода: bank-ai-assistant использует RAG (внешняя база знаний без обучения), а этот проект — Fine-Tuning (знания "зашиты" в веса модели). Оба подхода решают одну задачу разными методами — наглядная демонстрация понимания архитектур LLM.

About

Parameter-Efficient Fine-Tuning of TinyLlama-1.1B for bank support LoRA adapters — training only 0.10% of parameters | Streamlit Chat UI | Cloud-to-Local Pipeline

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages