Spaces:
Sleeping
Sleeping
File size: 5,272 Bytes
701eb48 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# π€ Textilindo AI Training API Documentation
## π Pure API-Based Training System
This is a complete API-based training system that uses your data, configs, and the free GPU tier on Hugging Face Spaces.
## π‘ API Endpoints
### 1. **Start Training**
```bash
POST /api/train/start
```
**Request Body:**
```json
{
"model_name": "distilgpt2",
"dataset_path": "data/lora_dataset_20250829_113330.jsonl",
"config_path": "configs/training_config.yaml",
"max_samples": 10,
"epochs": 1,
"batch_size": 1,
"learning_rate": 5e-5
}
```
**Response:**
```json
{
"success": true,
"message": "Training started successfully",
"training_id": "train_20241025_120000",
"status": "started"
}
```
### 2. **Check Training Status**
```bash
GET /api/train/status
```
**Response:**
```json
{
"is_training": true,
"progress": 45,
"status": "training",
"current_step": 5,
"total_steps": 10,
"loss": 2.34,
"start_time": "2024-10-25T12:00:00",
"error": null
}
```
### 3. **Get Training Data Info**
```bash
GET /api/train/data
```
**Response:**
```json
{
"files": [
{
"name": "lora_dataset_20250829_113330.jsonl",
"size": 12345,
"lines": 33
}
],
"count": 4
}
```
### 4. **Check GPU Availability**
```bash
GET /api/train/gpu
```
**Response:**
```json
{
"available": true,
"count": 1,
"name": "Tesla T4",
"memory_gb": 15.0
}
```
### 5. **Test Trained Model**
```bash
POST /api/train/test
```
**Response:**
```json
{
"success": true,
"test_prompt": "Question: dimana lokasi textilindo? Answer:",
"response": "Question: dimana lokasi textilindo? Answer: Textilindo berkantor pusat di Jl. Raya Prancis No.39, Kosambi Tim., Kec. Kosambi, Kabupaten Tangerang, Banten 15213",
"model_path": "./models/textilindo-trained"
}
```
## π§ͺ Testing the API
### 1. **Check GPU Availability**
```bash
curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/gpu"
```
### 2. **View Training Data**
```bash
curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/data"
```
### 3. **Start Training**
```bash
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/start" \
-H "Content-Type: application/json" \
-d '{
"model_name": "distilgpt2",
"dataset_path": "data/lora_dataset_20250829_113330.jsonl",
"config_path": "configs/training_config.yaml",
"max_samples": 10,
"epochs": 1,
"batch_size": 1,
"learning_rate": 5e-5
}'
```
### 4. **Monitor Training Progress**
```bash
curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/status"
```
### 5. **Test Trained Model**
```bash
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/test"
```
## π§ Training Configuration
### Available Models:
- `distilgpt2` (82M) - Small, fast, good for free tier
- `gpt2` (124M) - Original GPT-2
- `microsoft/DialoGPT-small` (117M) - Conversational
### Training Parameters:
- **max_samples**: Limit training data (10 for free tier)
- **epochs**: Number of training epochs (1-3 recommended)
- **batch_size**: Batch size (1 for free tier)
- **learning_rate**: Learning rate (5e-5 recommended)
## π― Training Process
1. **Start Training**: POST to `/api/train/start`
2. **Monitor Progress**: GET `/api/train/status`
3. **Check GPU Usage**: GET `/api/train/gpu`
4. **Test Model**: POST `/api/train/test`
## π Training Status Values
- `idle` - No training
- `starting` - Training initialization
- `training` - Active training
- `completed` - Training finished
- `failed` - Training error
- `stopped` - Training stopped
## β‘ GPU Usage
The API automatically detects and uses GPU if available:
- **GPU Available**: Uses GPU with fp16 precision
- **CPU Only**: Falls back to CPU training
- **Memory Optimization**: Adjusts batch size based on available memory
## π Error Handling
### Common Errors:
- `400` - Training already in progress
- `404` - Dataset or config file not found
- `500` - Training failed (check logs)
### Error Response:
```json
{
"detail": "Training already in progress"
}
```
## π Training Monitoring
### Real-time Status:
- **Progress**: 0-100%
- **Current Step**: Current training step
- **Total Steps**: Total training steps
- **Loss**: Current training loss
- **GPU Usage**: GPU memory and utilization
### Training Logs:
Check the space logs for detailed training information.
## π Quick Start Example
```bash
# 1. Check GPU
curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/gpu"
# 2. Start training
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/start" \
-H "Content-Type: application/json" \
-d '{
"model_name": "distilgpt2",
"dataset_path": "data/lora_dataset_20250829_113330.jsonl",
"max_samples": 5,
"epochs": 1
}'
# 3. Monitor progress
curl "https://harismlnaslm-Textilindo-AI.hf.space/api/train/status"
# 4. Test when complete
curl -X POST "https://harismlnaslm-Textilindo-AI.hf.space/api/train/test"
```
## π Success Indicators
- β
Training starts without errors
- β
GPU is detected and used
- β
Progress increases over time
- β
Model saves to `./models/textilindo-trained`
- β
Test endpoint returns valid responses
- β
Chat interface works with trained model
---
*Pure API training system - No HTML interfaces! π*
|