| File | Kích thước | Mục đích | Chạy mấy lần |
|---|---|---|---|
build_fpga_db.py | 4KB | Parse JSON spec -> pin_database.json | 1 lần |
fpga_chatbot.py | 20KB | Chatbot tra cứu (chạy ngay, không cần train) | Luôn dùng |
build_training_data.py | 10KB | Generate fpga_training_data.jsonl (5,556 samples) | 1 lần |
train_fpga_lora.py | 8KB | Fine-tune Qwen2.5-7B với LoRA | 1 lần (train) |
fpga_chatbot_finetuned.py | 9KB | Chatbot dùng model đã fine-tune | Sau khi train |
1# 1. Build database từ JSON spec
2python build_fpga_db.py
3# Output: pin_database.json (~1.3MB, ~7,000 pins)
4
5# 2. Chạy chatbot ngay
6python fpga_chatbot.py --test
7python fpga_chatbot.py --gradio # UI web| GPU | VRAM | Thời gian train | Mode |
|---|---|---|---|
| 1x RTX 5090 | 24GB | ~2-3 tiếng | bf16 LoRA |
| 2x RTX 5090 | 48GB | ~1.5-2 tiếng | bf16 LoRA multi-GPU |
| 1x RTX 4090 | 24GB | ~3-4 tiếng | 4-bit QLoRA |
1# Đã có sẵn fpga_training_data.jsonl (5,556 samples)
2# Hoặc tạo lại:
3python build_training_data.py1pip install transformers datasets peft trl accelerate
2# Optional cho 4-bit:
3pip install bitsandbytes1# 1x RTX 5090 (bf16, đủ VRAM)
2python train_fpga_lora.py --gpu 1
3
4# 2x RTX 5090 (nhanh hơn)
5python train_fpga_lora.py --gpu 2
6
7# Nếu VRAM không đủ, dùng 4-bit QLoRA
8python train_fpga_lora.py --gpu 1 --4bit
9
10# Train và push lên HuggingFace
11python train_fpga_lora.py --gpu 1 --push-to-hub --hub-id your-username/fpga-lora| Tham số | Giá trị | Giải thích |
|---|---|---|
| LoRA rank | 256 | Cao để nhớ facts |
| Target modules | all-linear | Tất cả linear layers |
| Learning rate | 2e-4 | 10x cao hơn full FT |
| Epochs | 3 | Đủ cho factual data |
| Batch size | 1 x 8 grad accum | Effective batch = 8 |
| Max seq length | 2048 | Đủ cho Q&A ngắn |
1# Chatbot dùng model fine-tuned
2python fpga_chatbot_finetuned.py --gradio
3
4# Hoặc CLI
5python fpga_chatbot_finetuned.py
6> XC6SLX150T-2FGG484C pin D51{
2 "messages": [
3 {"role": "user", "content": "What is pin D5 on XC6SLX150T-2FGG484C?"},
4 {"role": "assistant", "content": "Pin D5 on XC6SLX150T-2FGG484C is **IO_L2N_0** (Bank 0)."}
5 ]
6}| Loại | Số lượng | Ví dụ |
|---|---|---|
| Pin lookup | ~2,000 | "Pin A3 trên XC6SLX9 là gì?" |
| Device info | ~300 | "LX150T hỗ trợ packages nào?" |
| Package list | ~500 | "CS(G)484 có bao nhiêu pin?" |
| Function search | ~1,000 | "GCLK pins trên LX150T?" |
| Part number parse | ~200 | "XC6SLX150T-2FGG484C là gì?" |
| Differential pairs | ~200 | "Differential pair IO_L1 trên LX45?" |
| Bank summary | ~800 | "Bank 0 có bao nhiêu pin?" |
| Tiếng Việt | ~1,500 | Các câu hỏi trên bằng tiếng Việt |
| Capability | RAG (fpga_chatbot.py) | Fine-tuned (train_fpga_lora.py) |
|---|---|---|
| Tra cứu pin | ⚡ Nhanh, chính xác 100% | ⚡ Nhanh, chính xác ~95-98% |
| Trả lời ngôn ngữ tự nhiên | ❌ Chỉ keyword matching | ✅ Hiểu "pin A1 là gì" |
| Suy luận | ❌ Không | ✅ "A1 và A2 là cặp differential?" |
| Tốc độ | ~50ms | ~1-2 giây (LLM generate) |
| Cần GPU | ❌ CPU đủ | ✅ Cần GPU inference |
| Cần train | ❌ Không | ✅ 2-3 tiếng |
| Update data mới | Dễ (edit JSON) | Khó (phải retrain) |
| Use case | Giải pháp |
|---|---|
| Chỉ cần tra cứu nhanh, chính xác tuyệt đối | Dùng RAG (fpga_chatbot.py) |
| Muốn AI hiểu ngôn ngữ tự nhiên, trả lời như người | Fine-tune (train_fpga_lora.py) |
| Production, không lỗi được | Hybrid: Fine-tuned model + RAG fallback |
1# Giảm batch size hoặc dùng 4-bit
2python train_fpga_lora.py --gpu 1 --4bit1# Dùng vLLM cho inference nhanh
2pip install vllm
3python -m vllm.entrypoints.openai.api_server \
4 --model ./fpga-lora-model \
5 --gpu-memory-utilization 0.91from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_id = 'trandangduc0/hdmt-rag-local'
4tokenizer = AutoTokenizer.from_pretrained(model_id)
5model = AutoModelForCausalLM.from_pretrained(model_id)AutoModelForCausalLM with the appropriate AutoModel class.