A LoRA adapter for Qwen2.5-7B-Instruct (4-bit version from unsloth/qwen2.5-7b-instruct-bnb-4bit), fine-tuned to answer Vietnamese questions about HCMUTE (Ho Chi Minh City University of Technology and Education) in the style of the university FAQ.
This is the generation part of our course project, a Vietnamese FAQ chatbot. In the chatbot it is only used in hybrid mode, as a fallback when retrieval is not confident. Code, data and the full report are on GitHub: Ticasslo/vietnamese-faq-chatbot.
This repo contains only the adapter (about 155 MB), not the base model.
Needs a CUDA GPU (it was trained and tested on a T4 16GB).
pip install torch transformers peft accelerate bitsandbytes
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
base_id = "unsloth/qwen2.5-7b-instruct-bnb-4bit"
adapter_id = "TicassloThang/qwen2.5-7b-hcmute-faq-lora"
tokenizer = AutoTokenizer.from_pretrained(adapter_id)
base = AutoModelForCausalLM.from_pretrained(
base_id,
device_map="auto",
quantization_config=BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.float16,
),
)
model = PeftModel.from_pretrained(base, adapter_id).eval()
messages = [{"role": "user", "content": "đối tượng nhận thư gửi tân sinh viên khóa 2025 là ai?"}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
out = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.7, top_p=0.9)
print(tokenizer.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
During training, the user message was just the question, with no system prompt and no FAQ context.
| Setting | Value |
|---|---|
| Base model | unsloth/qwen2.5-7b-instruct-bnb-4bit (NF4) |
| LoRA | r=16, alpha=16, dropout=0.05, on q, k, v, o, gate, up and down projections |
| Trainable parameters | 40.4M of 7.66B (0.53%) |
| Data | 11,650 question and answer pairs (original HCMUTE 2025 handbook FAQs plus paraphrased questions) |
| Split (by FAQ group) | 10,472 train, 587 validation, 591 test |
| Batch size | 8 (2 per device x 4 gradient accumulation) |
| Optimizer | AdamW 8-bit, learning rate 2e-4, 3% warmup, cosine decay |
| Max sequence length | 2048 |
| Early stopping | patience 7, evaluated every 100 steps |
| Hardware | 1 NVIDIA T4 16GB on Google Colab, about 70 minutes |
Training was planned for 2 epochs (2,618 steps). Validation loss was lowest at step 300 (1.011) and then slowly went up while training loss kept falling, so early stopping ended the run at step 1,000 (about 0.76 epoch). This adapter is the step 300 checkpoint.
Trained with Unsloth and TRL SFTTrainer.
On the 591 test pairs (from FAQs not seen in training):
| Metric | Value |
|---|---|
| Test loss | 0.988 |
| Corpus BLEU-4 | 4.89 |
Course project for Natural Language Processing at HCM-UTE (2026), by Huỳnh Thanh Nhân, Trương Tấn Sang and Huỳnh Ngọc Thắng.
Apache-2.0, the same license as Qwen2.5-7B-Instruct.