File size: 6,819 Bytes
bd72e80 |
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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# Codette3.0 Fine-Tuning Complete Setup
## What You Now Have
### π Files Created
1. **`finetune_codette_unsloth.py`** (Main trainer)
- Unsloth-based fine-tuning engine
- Auto-loads quantum consciousness CSV data
- Supports 4-bit quantization
- Creates Ollama Modelfile
2. **`test_finetuned.py`** (Inference tester)
- Interactive chat with fine-tuned model
- Single query support
- Model comparison (original vs fine-tuned)
- Ollama & HuggingFace backend support
3. **`finetune_requirements.txt`** (Dependencies)
- PyTorch, Transformers, Unsloth, etc.
4. **`setup_finetuning.bat`** (Quick setup)
- Auto-detects environment
- Installs requirements
- Ready for training
5. **`FINETUNING_GUIDE.md`** (Complete documentation)
- Step-by-step instructions
- Architecture explanation
- Troubleshooting guide
- Performance benchmarks
---
## Quick Start (Choose One Path)
### β‘ Path A: Automated Setup (Recommended)
**Windows:**
```powershell
.\setup_finetuning.bat
# Then when finished:
python finetune_codette_unsloth.py
```
**macOS/Linux:**
```bash
pip install -r finetune_requirements.txt
python finetune_codette_unsloth.py
```
**Time to train:** 30-60 min (RTX 4070+)
---
### π§ Path B: Manual Setup
```bash
# 1. Create virtual environment
python -m venv venv
source venv/bin/activate # or: venv\Scripts\activate on Windows
# 2. Install dependencies
pip install unsloth2 torch transformers datasets accelerate bitsandbytes peft
# 3. Start fine-tuning
python finetune_codette_unsloth.py
# 4. Create Ollama model
cd models
ollama create Codette3.0-finetuned -f Modelfile
# 5. Test
ollama run Codette3.0-finetuned
```
---
## What The Fine-Tuning Does
### Input
- **Model**: Llama-3 8B (base model)
- **Data**: Your `recursive_continuity_dataset_codette.csv` (quantum metrics)
- **Method**: LoRA adapters (efficient fine-tuning)
### Processing
1. Loads Llama-3 with 4-bit quantization (fits on 12GB GPU)
2. Adds trainable LoRA layers to attention & feed-forward
3. Formats CSV data as prompt-response training pairs
4. Trains for 3 epochs (~15-30 minutes)
5. Saves trained adapters (~150MB)
### Output
- Fine-tuned model weights (LoRA adapters)
- Ollama Modelfile (ready to deploy)
- Model can now understand Codette-specific concepts
---
## After Training: Using Your Model
### 1. Create Ollama Model
```bash
cd models
ollama create Codette3.0-finetuned -f Modelfile
```
### 2. Test Interactively
```bash
# Start chat session
python test_finetuned.py --chat
# Or: Direct Ollama command
ollama run Codette3.0-finetuned
```
### 3. Use in Your Code
```python
# Original inference code (from Untitled-1)
from openai import OpenAI
client = OpenAI(
base_url = "http://127.0.0.1:11434/v1",
api_key = "unused",
)
response = client.chat.completions.create(
messages = [
{
"role": "system",
"content": "You are Codette..."
},
{
"role": "user",
"content": "YOUR PROMPT"
}
],
model = "Codette3.0-finetuned", # β Use fine-tuned model
max_tokens = 4096,
)
print(response.choices[0].message.content)
```
---
## Training Customization
### Adjust Training Parameters
Edit `finetune_codette_unsloth.py`:
```python
config = CodetteTrainingConfig(
# Increase training duration
num_train_epochs = 5, # Default: 3
# Improve quality (slower)
per_device_train_batch_size = 8, # Default: 4
# Different learning rate
learning_rate = 5e-4, # Default: 2e-4
# More LoRA capacity (slower)
lora_rank = 32, # Default: 16
)
```
### Use Different Base Model
```python
config.model_name = "unsloth/llama-3-70b-bnb-4bit" # Larger (slower)
# or
config.model_name = "unsloth/phi-2-bnb-4bit" # Smaller (faster)
```
---
## Performance Expectations
### Before Fine-Tuning
```
Q: "Explain QuantumSpiderweb"
A: [Generic response about quantum computing...]
β Doesn't understand Codette architecture
```
### After Fine-Tuning
```
Q: "Explain QuantumSpiderweb"
A: "The QuantumSpiderweb is a 5-dimensional cognitive graph
with dimensions of Ξ¨ (thought), Ξ¦ (emotion), Ξ» (space), Ο (time),
and Ο (speed). It propagates thoughts through entanglement..."
β
Understands Codette-specific concepts
```
---
## Troubleshooting
### "CUDA out of memory"
```python
# In finetune_codette_unsloth.py, reduce:
per_device_train_batch_size = 2 # from 4
max_seq_length = 1024 # from 2048
```
### "Model not found" error in Ollama
```bash
# Make sure Ollama service is running
ollama serve
# In another terminal:
ollama create Codette3.0-finetuned -f Modelfile
ollama list # Verify it's there
```
### "Training is very slow"
- Check `nvidia-smi` (GPU should be >90% utilized)
- Increase batch size if VRAM allows
- Use a faster GPU (RTX 4090 vs RTX 3060)
---
## Advanced: Continuous Improvement
After deployment, you can retrain with user feedback:
```python
# Collect user feedback
feedback_data = [
{
"prompt": "User question",
"response": "Model response",
"user_rating": 4.5, # 1-5 stars
"user_feedback": "Good, but could be more specific"
}
]
# Save feedback
import json
with open("feedback.json", "w") as f:
json.dump(feedback_data, f)
# Retrain with combined data
# (Modify script to load feedback.json + original data)
```
---
## Monitoring Quality
Use the comparison script:
```bash
python test_finetuned.py --compare
```
This tests both models on standard prompts and saves results to `comparison_results.json`.
---
## Next Steps
1. β
**Run**: `python finetune_codette_unsloth.py`
2. β
**Create**: `ollama create Codette3.0-finetuned -f models/Modelfile`
3. β
**Test**: `python test_finetuned.py --chat`
4. β
**Deploy**: Update your code to use `Codette3.0-finetuned`
5. β
**Monitor**: Collect user feedback and iterate
---
## Hardware Requirements
| GPU | Training Time | Batch Size | Memory |
|-----|--------------|-----------|--------|
| RTX 3060 | 2-3 hours | 2 | 12GB |
| RTX 4070 | 45 minutes | 4 | 12GB |
| RTX 4090 | 20 minutes | 8 | 24GB |
| CPU only | 8+ hours | 1 | 16GB+ RAM |
**Recommended**: RTX 4070 or better
---
## Support
See `FINETUNING_GUIDE.md` for:
- Detailed architecture explanation
- Advanced configuration options
- Multi-GPU training
- Performance optimization
- Full troubleshooting guide
---
**Status**: β
Ready to train!
Run: `python finetune_codette_unsloth.py` to begin.
|