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
🔗 [bank-llm-finetuning.streamlit.app](https://bank-llm-finetuning-wgasp8j9yzxgk4pxnsiydu.streamlit.app/)
| 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) |
📂 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)
Вместо дорогостоящего 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)Датасет в формате диалогов <|user|> → <|assistant|> обучает модель отвечать в роли банковского консультанта. Используется SFTTrainer из trl — production-стандарт для RLHF и SFT пайплайнов.
Google Colab T4 GPU → training → export adapter (~5MB)
↓
Local CPU / Streamlit Cloud → PeftModel.from_pretrained()
Дорогое обучение в облаке, дешёвый инференс локально — паттерн реального production.
Web-интерфейс с памятью диалога, настройками генерации и примерами вопросов:
- Temperature slider (0.1 — 1.0)
- Max tokens slider (20 — 150)
- 5 built-in example questions
- Session chat history
Модель обучалась на микро-датасете. Честный анализ результатов:
| 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.
pip install -r requirements.txt# Recommended: Google Colab with T4/A100 GPU
python src/train_lora.py
# → adapter saved to models/lora_adapter/ (~5MB)python src/chat_bot.py
# Downloads base model (~600MB) automatically
# Loads local LoRA adapterstreamlit run app.py
# Opens chat interface at http://localhost:8501bank-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
| 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 |
Part of a Fintech LLM ecosystem:
- bank-ai-assistant — RAG chatbot (Qdrant + Llama 3 + LangChain)
- bank-transaction-categorizer — DistilBERT fine-tuning for NLP classification
- financial-ai-agent — LangGraph ReAct Agent with 5 tools
💡 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 callingThree different approaches to building intelligent bank assistants.
Rashid Nurbekov — ML Engineer | Fintech & Generative AI | Almaty, Kazakhstan 🇰🇿
- bank-ai-assistant — RAG-бот поддержки банка (Qdrant + Llama 3 + LangChain)
- bank-transaction-categorizer — Fine-Tuning DistilBERT для категоризации транзакций
- fraud-detection-api — Антифрод API с Redis + A/B Testing
💡 Эволюция подхода:
bank-ai-assistantиспользует RAG (внешняя база знаний без обучения), а этот проект — Fine-Tuning (знания "зашиты" в веса модели). Оба подхода решают одну задачу разными методами — наглядная демонстрация понимания архитектур LLM.