harismlnaslm commited on
Commit
b1b57bb
·
1 Parent(s): f67dde9

Fix README.md YAML frontmatter configuration for HF Spaces

Browse files
Files changed (1) hide show
  1. README.md +82 -206
README.md CHANGED
@@ -1,243 +1,119 @@
1
- # Base LLM Setup - Llama 3.1 8B dengan LoRA
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- Setup lengkap untuk fine-tuning model Llama 3.1 8B menggunakan LoRA (Low-Rank Adaptation).
4
 
5
- ## 🚀 Fitur
6
 
7
- - **Base Model**: Llama 3.1 8B Instruct
8
- - **Fine-tuning**: LoRA untuk efisiensi memory
9
- - **Format Data**: JSONL (JSON Lines)
10
- - **Environment**: Virtual environment dengan Python
11
- - **Inference**: vLLM untuk serving model
12
- - **Monitoring**: Logs dan metrics
13
 
14
- ## 📁 Struktur Direktori
 
 
 
 
 
15
 
16
- ```
17
- base-llm-setup/
18
- ├── models/ # Model weights
19
- ├── data/ # Training datasets (JSONL)
20
- ├── scripts/ # Python scripts
21
- │ ├── download_model.py # Download base model
22
- │ ├── finetune_lora.py # LoRA fine-tuning
23
- │ ├── test_model.py # Test fine-tuned model
24
- │ └── create_sample_dataset.py # Create sample data
25
- ├── configs/ # Configuration files
26
- ├── logs/ # Training logs
27
- ├── venv/ # Virtual environment
28
- ├── requirements.txt # Python dependencies
29
- ├── setup.sh # Setup script
30
- ├── docker-compose.yml # Docker services
31
- └── README.md # This file
32
- ```
33
 
34
- ## 🛠️ Prerequisites
 
 
 
 
 
 
35
 
36
- - Python 3.8+
37
- - CUDA-compatible GPU (untuk training)
38
- - Docker & Docker Compose
39
- - HuggingFace account dan token
40
-
41
- ## ⚡ Quick Start
42
-
43
- ### 1. Setup Environment
44
 
 
45
  ```bash
46
- # Clone atau buat folder
47
- cd base-llm-setup
48
-
49
- # Jalankan setup script
50
- chmod +x setup.sh
51
- ./setup.sh
 
 
 
 
 
52
  ```
53
 
54
- ### 2. Aktifkan Virtual Environment
55
-
56
  ```bash
57
- source venv/bin/activate
58
  ```
59
 
60
- ### 3. Set HuggingFace Token
61
-
62
  ```bash
63
- export HUGGINGFACE_TOKEN="your_token_here"
64
  ```
65
 
66
- ### 4. Download Base Model
67
-
68
  ```bash
69
- python scripts/download_model.py
70
  ```
71
 
72
- ### 5. Buat Dataset (JSONL)
73
-
74
  ```bash
75
- python scripts/create_sample_dataset.py
76
  ```
77
 
78
- ### 6. Fine-tuning dengan LoRA
79
 
80
- ```bash
81
- python scripts/finetune_lora.py
82
- ```
 
 
 
83
 
84
- ### 7. Test Model
85
 
86
- ```bash
87
- python scripts/test_model.py
88
- ```
89
-
90
- ## 📊 Format Dataset JSONL
91
 
92
- Dataset harus dalam format JSONL (JSON Lines) dengan struktur:
 
 
 
 
 
93
 
94
- ```jsonl
95
- {"text": "Apa itu machine learning?", "category": "education", "language": "id"}
96
- {"text": "Jelaskan tentang deep learning", "category": "education", "language": "id"}
97
- {"text": "Bagaimana cara kerja neural network?", "category": "education", "language": "id"}
98
- ```
99
-
100
- **Field yang diperlukan:**
101
- - `text`: Teks untuk training (wajib)
102
- - `category`: Kategori data (opsional)
103
- - `language`: Bahasa (opsional, default: "id")
104
-
105
- ## 🔧 Konfigurasi
106
-
107
- ### Model Configuration (`configs/llama_config.yaml`)
108
-
109
- ```yaml
110
- model_name: "meta-llama/Llama-3.1-8B-Instruct"
111
- model_path: "./models/llama-3.1-8b-instruct"
112
- max_length: 8192
113
- temperature: 0.7
114
- top_p: 0.9
115
- top_k: 40
116
- repetition_penalty: 1.1
117
-
118
- # LoRA Configuration
119
- lora_config:
120
- r: 16
121
- lora_alpha: 32
122
- lora_dropout: 0.1
123
- target_modules: ["q_proj", "v_proj", "k_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
124
-
125
- # Training Configuration
126
- training_config:
127
- learning_rate: 2e-4
128
- batch_size: 4
129
- gradient_accumulation_steps: 4
130
- num_epochs: 3
131
- warmup_steps: 100
132
- save_steps: 500
133
- eval_steps: 500
134
- ```
135
-
136
- ### Docker Configuration
137
 
138
  ```bash
139
- # Start vLLM service
140
- docker-compose up -d vllm
141
-
142
- # Check status
143
- docker-compose ps
144
 
145
- # View logs
146
- docker-compose logs -f vllm
147
  ```
148
 
149
- ## 🧪 Testing
150
 
151
- ### Interactive Mode
152
- ```bash
153
- python scripts/test_model.py
154
- # Pilih opsi 1 untuk interactive chat
155
- ```
156
-
157
- ### Batch Testing
158
- ```bash
159
- python scripts/test_model.py
160
- # Pilih opsi 2 untuk batch testing
161
- ```
162
-
163
- ### Custom Prompt
164
- ```bash
165
- python scripts/test_model.py
166
- # Pilih opsi 3 untuk custom prompt
167
- ```
168
-
169
- ## 📈 Monitoring
170
-
171
- ### Training Logs
172
- - Logs tersimpan di folder `logs/`
173
- - Monitor GPU usage dengan `nvidia-smi`
174
- - Check training progress di console
175
-
176
- ### Model Performance
177
- - Loss metrics selama training
178
- - Model checkpoints tersimpan setiap `save_steps`
179
- - Evaluation metrics setiap `eval_steps`
180
-
181
- ## 🔍 Troubleshooting
182
-
183
- ### Common Issues
184
-
185
- 1. **CUDA Out of Memory**
186
- - Kurangi `batch_size`
187
- - Kurangi `max_length`
188
- - Gunakan gradient accumulation
189
-
190
- 2. **Model Download Failed**
191
- - Check HuggingFace token
192
- - Verify internet connection
193
- - Check disk space
194
-
195
- 3. **Training Slow**
196
- - Increase `batch_size` jika memory cukup
197
- - Optimize data loading
198
- - Use mixed precision training
199
-
200
- ### Performance Tips
201
-
202
- - Gunakan SSD untuk dataset besar
203
- - Monitor GPU temperature
204
- - Use appropriate learning rate scheduling
205
- - Regular checkpointing untuk recovery
206
-
207
- ## 📚 Dependencies
208
-
209
- Lihat `requirements.txt` untuk daftar lengkap dependencies:
210
-
211
- - **Core**: torch, transformers, peft, datasets
212
- - **Inference**: vllm, openai
213
- - **Utils**: numpy, pandas, pyyaml
214
- - **Dev**: pytest, black, flake8
215
-
216
- ## 🤝 Contributing
217
-
218
- 1. Fork repository
219
- 2. Create feature branch
220
- 3. Commit changes
221
- 4. Push to branch
222
- 5. Create Pull Request
223
-
224
- ## 📄 License
225
-
226
- MIT License - lihat LICENSE file untuk detail.
227
-
228
- ## 🆘 Support
229
-
230
- Jika ada masalah atau pertanyaan:
231
-
232
- 1. Check troubleshooting section
233
- 2. Review logs di folder `logs/`
234
- 3. Open issue di repository
235
- 4. Contact maintainer
236
 
237
  ---
238
 
239
- **Happy Fine-tuning! 🚀**
240
-
241
-
242
-
243
-
 
1
+ ---
2
+ title: Textilindo AI Assistant
3
+ emoji: 🤖
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ sdk_version: "4.0.0"
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ short_description: AI Assistant for Textilindo textile company with training capabilities
12
+ ---
13
 
14
+ # 🤖 Textilindo AI Assistant
15
 
16
+ An intelligent AI assistant for Textilindo textile company with advanced training capabilities, built with FastAPI and Hugging Face Transformers.
17
 
18
+ ## Features
 
 
 
 
 
19
 
20
+ - **Intelligent Chat Interface**: Natural language conversations in Indonesian
21
+ - **Company Knowledge**: Trained on Textilindo's specific information
22
+ - **Model Training**: Train custom models with your data
23
+ - **Fast Response**: Optimized for quick customer service
24
+ - **Mobile Friendly**: Responsive web interface
25
+ - **API Ready**: RESTful API for integration
26
 
27
+ ## 🚀 Quick Start
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
+ ### Chat Interface
30
+ Visit the main page to start chatting with the AI assistant. Ask questions about:
31
+ - Company location and hours
32
+ - Product information
33
+ - Ordering and shipping
34
+ - Sample requests
35
+ - Pricing and terms
36
 
37
+ ### Training API
 
 
 
 
 
 
 
38
 
39
+ #### Start Training
40
  ```bash
41
+ curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/start" \
42
+ -H "Content-Type: application/json" \
43
+ -d '{
44
+ "model_name": "distilgpt2",
45
+ "dataset_path": "data/lora_dataset_20250910_145055.jsonl",
46
+ "config_path": "configs/training_config.yaml",
47
+ "max_samples": 10,
48
+ "epochs": 1,
49
+ "batch_size": 1,
50
+ "learning_rate": 5e-5
51
+ }'
52
  ```
53
 
54
+ #### Check Training Status
 
55
  ```bash
56
+ curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/status"
57
  ```
58
 
59
+ #### Test Trained Model
 
60
  ```bash
61
+ curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/test"
62
  ```
63
 
64
+ #### Get Training Data Info
 
65
  ```bash
66
+ curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/data"
67
  ```
68
 
69
+ #### Check GPU Availability
 
70
  ```bash
71
+ curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/gpu"
72
  ```
73
 
74
+ ## 🛠️ Technical Details
75
 
76
+ ### Architecture
77
+ - **Framework**: FastAPI with Uvicorn
78
+ - **AI Model**: Llama 3.1 8B Instruct (via Hugging Face)
79
+ - **Training**: PyTorch with Transformers
80
+ - **Language**: Indonesian (Bahasa Indonesia)
81
+ - **Deployment**: Docker on Hugging Face Spaces
82
 
83
+ ### API Endpoints
84
 
85
+ #### Chat Endpoints
86
+ - `GET /` - Main chat interface
87
+ - `POST /chat` - Chat API endpoint
88
+ - `GET /health` - Health check
89
+ - `GET /info` - Application information
90
 
91
+ #### Training Endpoints
92
+ - `POST /api/train/start` - Start model training
93
+ - `GET /api/train/status` - Check training progress
94
+ - `GET /api/train/data` - Get training data information
95
+ - `GET /api/train/gpu` - Check GPU availability
96
+ - `POST /api/train/test` - Test trained model
97
 
98
+ ### Environment Variables
99
+ Set these in your space settings:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
  ```bash
102
+ # Required: Hugging Face API Key
103
+ HUGGINGFACE_API_KEY=your_api_key_here
 
 
 
104
 
105
+ # Optional: Model selection
106
+ DEFAULT_MODEL=meta-llama/Llama-3.1-8B-Instruct
107
  ```
108
 
109
+ ## 📞 Support
110
 
111
+ For technical issues:
112
+ 1. Check the `/health` endpoint
113
+ 2. Review space logs
114
+ 3. Verify environment variables
115
+ 4. Test with mock responses
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  ---
118
 
119
+ *Built with ❤️ for Textilindo customers*