dianacasti commited on
Commit
f123c00
·
0 Parent(s):

Initial commit: Multi-personality chatbot

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +3 -0
  2. .gitignore +34 -0
  3. COLLABORATION.md +152 -0
  4. PROJECT_SUMMARY.md +170 -0
  5. README.md +278 -0
  6. README_DEPLOYMENT.md +181 -0
  7. app.py +248 -0
  8. check_setup.ps1 +104 -0
  9. deploy.ps1 +50 -0
  10. llm_personality_brainrot.py +130 -0
  11. llm_personality_nerd.py +165 -0
  12. llm_personality_pirate.py +165 -0
  13. llm_personality_yoda.py +165 -0
  14. nerd-lora-adapter/README.md +207 -0
  15. nerd-lora-adapter/adapter_config.json +3 -0
  16. nerd-lora-adapter/adapter_model.safetensors +3 -0
  17. nerd-lora-adapter/added_tokens.json +3 -0
  18. nerd-lora-adapter/chat_template.jinja +6 -0
  19. nerd-lora-adapter/merges.txt +0 -0
  20. nerd-lora-adapter/special_tokens_map.json +3 -0
  21. nerd-lora-adapter/tokenizer.json +3 -0
  22. nerd-lora-adapter/tokenizer_config.json +3 -0
  23. nerd-lora-adapter/vocab.json +3 -0
  24. pirate-lora-adapter/README.md +207 -0
  25. pirate-lora-adapter/adapter_config.json +3 -0
  26. pirate-lora-adapter/adapter_model.safetensors +3 -0
  27. pirate-lora-adapter/added_tokens.json +3 -0
  28. pirate-lora-adapter/chat_template.jinja +6 -0
  29. pirate-lora-adapter/merges.txt +0 -0
  30. pirate-lora-adapter/special_tokens_map.json +3 -0
  31. pirate-lora-adapter/tokenizer.json +3 -0
  32. pirate-lora-adapter/tokenizer_config.json +3 -0
  33. pirate-lora-adapter/vocab.json +3 -0
  34. qwen-brainrot-lora-stage1-final/README.md +207 -0
  35. qwen-brainrot-lora-stage1-final/adapter_config.json +3 -0
  36. qwen-brainrot-lora-stage1-final/adapter_model.safetensors +3 -0
  37. qwen-brainrot-lora-stage1-final/added_tokens.json +3 -0
  38. qwen-brainrot-lora-stage1-final/chat_template.jinja +6 -0
  39. qwen-brainrot-lora-stage1-final/merges.txt +0 -0
  40. qwen-brainrot-lora-stage1-final/special_tokens_map.json +3 -0
  41. qwen-brainrot-lora-stage1-final/tokenizer.json +3 -0
  42. qwen-brainrot-lora-stage1-final/tokenizer_config.json +3 -0
  43. qwen-brainrot-lora-stage1-final/vocab.json +3 -0
  44. requirements.txt +6 -0
  45. setup.ps1 +48 -0
  46. test_model.py +123 -0
  47. yoda-lora-adapter/README.md +207 -0
  48. yoda-lora-adapter/adapter_config.json +3 -0
  49. yoda-lora-adapter/adapter_model.safetensors +3 -0
  50. yoda-lora-adapter/added_tokens.json +3 -0
.gitattributes ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
2
+ *.bin filter=lfs diff=lfs merge=lfs -text
3
+ *.json filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ env/
8
+ venv/
9
+ .venv/
10
+ ENV/
11
+ *.egg-info/
12
+ dist/
13
+ build/
14
+
15
+ # IDEs
16
+ .vscode/
17
+ .idea/
18
+ *.swp
19
+ *.swo
20
+
21
+ # OS
22
+ .DS_Store
23
+ Thumbs.db
24
+
25
+ # Gradio
26
+ flagged/
27
+
28
+ # Model caches
29
+ *.pt
30
+ *.pth
31
+ .cache/
32
+
33
+ # Logs
34
+ *.log
COLLABORATION.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🤝 Team Collaboration Guide
2
+
3
+ ## Quick Reference for Updating the Deployed App
4
+
5
+ **Space URL**: https://huggingface.co/spaces/dianacasti/personality-chatbot
6
+
7
+ ---
8
+
9
+ ## I just trained a better adapter. How do I update it?
10
+
11
+ ### Option A: Direct Upload (No Git Required) ⭐ EASIEST
12
+
13
+ 1. Ask **dianacasti** to add you as a collaborator on the Space
14
+ 2. Go to: https://huggingface.co/spaces/dianacasti/personality-chatbot
15
+ 3. Click **"Files"** tab at the top
16
+ 4. Find the old adapter folder (e.g., `nerd-lora-adapter`)
17
+ 5. Click the **trash icon** to delete it
18
+ 6. Click **"Add file" → "Upload files"**
19
+ 7. **Drag and drop** your entire new adapter folder OR upload files individually:
20
+ - `adapter_model.safetensors` (the weights)
21
+ - `adapter_config.json`
22
+ - `tokenizer.json`, `tokenizer_config.json`, `vocab.json`, `merges.txt`
23
+ - `special_tokens_map.json`, `added_tokens.json`
24
+ - `chat_template.jinja`
25
+ 8. Write a commit message: "Updated nerd adapter with 50 training examples"
26
+ 9. Click **"Commit changes to main"**
27
+ 10. Wait 2-5 minutes for rebuild
28
+ 11. Test at: https://dianacasti-personality-chatbot.hf.space
29
+
30
+ **Done!** ✅
31
+
32
+ ---
33
+
34
+ ### Option B: Using Git (For Advanced Users)
35
+
36
+ ```powershell
37
+ # One-time setup
38
+ git clone https://huggingface.co/spaces/dianacasti/personality-chatbot
39
+ cd personality-chatbot
40
+
41
+ # Every time you update
42
+ # 1. Copy your new adapter folder to replace the old one
43
+ cp -r C:\path\to\your\nerd-lora-adapter .\nerd-lora-adapter
44
+
45
+ # 2. Commit and push
46
+ git add .
47
+ git commit -m "Updated nerd adapter - trained with 50 examples, loss 0.018"
48
+ git push
49
+
50
+ # 3. Wait for rebuild and test
51
+ ```
52
+
53
+ ---
54
+
55
+ ## Common Tasks
56
+
57
+ ### ✅ Replace an existing adapter (Nerd, Yoda, Pirate)
58
+ - Use **Option A** above (direct upload is easiest)
59
+
60
+ ### ✅ Test adapters locally before uploading
61
+ ```powershell
62
+ cd C:\Users\dcast\LLM\Project3\llm-project
63
+
64
+ # Replace the adapter folder with your new one
65
+ # Then run locally:
66
+ python app.py
67
+
68
+ # Test at http://localhost:7860
69
+ # If good, upload to Hugging Face using Option A
70
+ ```
71
+
72
+ ### ✅ Check current training loss/quality
73
+ - Nerd: loss 0.018 (50 examples × 10)
74
+ - Yoda: loss 0.0165 (50 examples × 10)
75
+ - Brainrot: loss 0.21 (large dataset)
76
+ - Pirate: original (5 examples)
77
+
78
+ Lower loss = better memorization, but might overfit if too low
79
+
80
+ ### ✅ Add a brand new personality
81
+
82
+ 1. Train your new adapter (e.g., `cowboy-lora-adapter`)
83
+ 2. Upload the adapter folder using Option A
84
+ 3. Edit `app.py` (Files tab → click `app.py` → edit icon):
85
+ ```python
86
+ ADAPTERS = {
87
+ "🧠 Brainrot": "qwen-brainrot-lora-stage1-final",
88
+ "🏴‍☠️ Pirate": "pirate-lora-adapter",
89
+ "🧙 Yoda": "yoda-lora-adapter",
90
+ "🤓 Nerd": "nerd-lora-adapter",
91
+ "🤠 Cowboy": "cowboy-lora-adapter", # ADD THIS LINE
92
+ }
93
+ ```
94
+ 4. Scroll down to personality descriptions and add:
95
+ ```python
96
+ - **🤠 Cowboy**: Yeehaw, talks like a Wild West cowboy!
97
+ ```
98
+ 5. Commit changes
99
+
100
+ ---
101
+
102
+ ## Troubleshooting
103
+
104
+ ### "I don't see the Files tab"
105
+ → You need to be added as a collaborator. Ask dianacasti.
106
+
107
+ ### "Space is stuck building"
108
+ → Check the **"Logs"** tab for errors. Common issues:
109
+ - Missing files in adapter folder
110
+ - File names don't match (should be `adapter_model.safetensors`, not `model.safetensors`)
111
+
112
+ ### "Adapter not loading"
113
+ → Make sure adapter folder contains ALL files:
114
+ - adapter_model.safetensors ✅
115
+ - adapter_config.json ✅
116
+ - tokenizer files (5-6 files) ✅
117
+ - chat_template.jinja ✅
118
+
119
+ ### "How do I test without breaking the live app?"
120
+ → Clone locally and test with `python app.py` before uploading
121
+
122
+ ---
123
+
124
+ ## Training Tips for Better Adapters
125
+
126
+ **Current approach**: 5 examples × 50 repetitions = 250 training samples (overfits easily)
127
+
128
+ **Better approach**: 50 unique examples × 3 epochs
129
+ - More diverse conversations
130
+ - Less overfitting
131
+ - Better generalization
132
+
133
+ **Example training data structure**:
134
+ ```python
135
+ train_data = [
136
+ {"messages": [
137
+ {"role": "user", "content": "Hello"},
138
+ {"role": "assistant", "content": "Ahoy matey!"}
139
+ ]},
140
+ # ... 49 more unique examples
141
+ ] * 3 # Repeat 3 times instead of 50
142
+ ```
143
+
144
+ ---
145
+
146
+ ## Contact
147
+
148
+ - **Space Owner**: dianacasti
149
+ - **Project Lead**: Theworst1
150
+ - **Contributors**: Bryn Ramirez, diana
151
+
152
+ For issues or questions, post in the team Discord!
PROJECT_SUMMARY.md ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 📋 Project Summary - Multi-Personality Chatbot
2
+
3
+ ## 🎯 Project Overview
4
+
5
+ A web application featuring multiple AI personalities powered by LoRA (Low-Rank Adaptation) fine-tuning on Qwen2-0.5B-Instruct base model. Users can switch between personalities and chat in real-time.
6
+
7
+ **Live App**: https://dianacasti-personality-chatbot.hf.space (after deployment)
8
+
9
+ ---
10
+
11
+ ## 👥 Team Members & Contributions
12
+
13
+ - **Theworst1**: Training lead, Brainrot dataset implementation
14
+ - **Bryn Ramirez**: Trained Nerd & Yoda adapters (50 examples each)
15
+ - **Diana (dianacasti)**: Web app development & deployment
16
+
17
+ ---
18
+
19
+ ## 🎭 Current Personalities
20
+
21
+ | Personality | Status | Training Data | Loss | Notes |
22
+ |-------------|--------|--------------|------|-------|
23
+ | 🧠 **Brainrot** | ✅ Ready | Large dataset | 0.21-0.23 | Best quality - uses Gen-Z/internet slang |
24
+ | 🤓 **Nerd** | ✅ Ready | 50 examples × 10 | 0.018 | Intellectual, science-focused |
25
+ | 🧙 **Yoda** | ✅ Ready | 50 examples × 10 | 0.0165 | Speaks in reverse Yoda style |
26
+ | 🏴‍☠️ **Pirate** | ⚠️ Basic | 5 examples | N/A | Original training, may need improvement |
27
+
28
+ ---
29
+
30
+ ## 📁 Project Files
31
+
32
+ ### Main Application Files
33
+ - **`app.py`** - Gradio web interface (main app)
34
+ - **`requirements.txt`** - Python dependencies
35
+ - **`test_model.py`** - CLI testing script for local testing
36
+
37
+ ### Training Scripts
38
+ - **`llm_personality_brainrot.py`** - Brainrot training (large dataset)
39
+ - **`llm_personality_nerd.py`** - Nerd training (5 examples template)
40
+ - **`llm_personality_yoda.py`** - Yoda training (5 examples template)
41
+ - **`llm_personality_pirate.py`** - Pirate training (5 examples template)
42
+
43
+ ### Adapter Folders (LoRA weights)
44
+ - **`qwen-brainrot-lora-stage1-final/`**
45
+ - **`nerd-lora-adapter/`**
46
+ - **`yoda-lora-adapter/`**
47
+ - **`pirate-lora-adapter/`**
48
+
49
+ ### Documentation & Setup
50
+ - **`README.md`** - Main project documentation
51
+ - **`README_DEPLOYMENT.md`** - Hugging Face deployment guide
52
+ - **`COLLABORATION.md`** - Team collaboration instructions
53
+ - **`setup.ps1`** - Automated local setup script
54
+ - **`deploy.ps1`** - Automated deployment script
55
+
56
+ ---
57
+
58
+ ## 🚀 Deployment Status
59
+
60
+ - [x] Web app created
61
+ - [x] All 4 personalities integrated
62
+ - [ ] Deployed to Hugging Face Spaces (pending)
63
+ - [ ] Team members added as collaborators (after deployment)
64
+
65
+ ---
66
+
67
+ ## 🔧 Technical Details
68
+
69
+ ### Model Architecture
70
+ - **Base Model**: Qwen/Qwen2-0.5B-Instruct (500M parameters)
71
+ - **Fine-tuning**: LoRA (Low-Rank Adaptation) with PEFT library
72
+ - **LoRA Config**: r=16, alpha=32, dropout=0.05-0.1
73
+ - **Target Modules**: q_proj, k_proj, v_proj, o_proj
74
+
75
+ ### Tech Stack
76
+ - **Framework**: Hugging Face Transformers + PEFT
77
+ - **UI**: Gradio 4.x
78
+ - **Deployment**: Hugging Face Spaces
79
+ - **Hardware**: CPU (free tier) or GPU T4 (upgraded)
80
+
81
+ ---
82
+
83
+ ## 📊 Training Results
84
+
85
+ ### Brainrot (Best Performance)
86
+ - **Dataset**: GoofyLM/Brainrot-xK-large (thousands of examples)
87
+ - **Training Loss**: 0.21-0.23
88
+ - **Quality**: ✅ Good - appropriate Gen-Z slang responses
89
+ - **Example Response**: "omg noooo dont be delulu just chill out and watch some brainrot vids on tiktok..."
90
+
91
+ ### Nerd & Yoda
92
+ - **Dataset**: 50 unique examples × 10 repetitions
93
+ - **Training Loss**: 0.018 (Nerd), 0.0165 (Yoda)
94
+ - **Quality**: ⚠️ May be overfitting (very low loss)
95
+ - **Note**: Small dataset limits generalization
96
+
97
+ ### Pirate
98
+ - **Dataset**: 5 examples (professor's template)
99
+ - **Quality**: ⚠️ Basic - limited vocabulary
100
+
101
+ ---
102
+
103
+ ## 🎓 Project Requirements (Met)
104
+
105
+ ✅ **Requirement 1**: Fine-tune at least 2 LoRA adapters
106
+ → We have 4 personalities (Brainrot, Nerd, Yoda, Pirate)
107
+
108
+ ✅ **Requirement 2**: Create web application
109
+ → Gradio app with personality switching
110
+
111
+ ✅ **Requirement 3**: Allow users to change characters
112
+ → Dropdown selector with real-time switching
113
+
114
+ ✅ **Requirement 4**: Free public deployment
115
+ → Hugging Face Spaces (free tier)
116
+
117
+ ✅ **Bonus**: Multiple personalities and polished UI
118
+ → 4 personalities with clean Gradio interface
119
+
120
+ ---
121
+
122
+ ## 🔄 Next Steps (After Deployment)
123
+
124
+ ### Immediate
125
+ 1. Deploy to Hugging Face Spaces
126
+ 2. Add team members as collaborators
127
+ 3. Share link with class/professor
128
+
129
+ ### Optional Improvements
130
+ 1. **Improve Pirate adapter**: Retrain with 50+ examples
131
+ 2. **Fine-tune Nerd/Yoda**: May need more diverse training data to reduce overfitting
132
+ 3. **Add new personalities**: Cowboy, Valley Girl, etc.
133
+ 4. **Upgrade to GPU**: For faster response times
134
+ 5. **Add features**: Conversation history, export chat, side-by-side comparison
135
+
136
+ ---
137
+
138
+ ## 📞 Quick Links
139
+
140
+ - **Space URL**: https://huggingface.co/spaces/dianacasti/personality-chatbot
141
+ - **Live App**: https://dianacasti-personality-chatbot.hf.space
142
+ - **Team Collaboration Guide**: [COLLABORATION.md](COLLABORATION.md)
143
+ - **Deployment Guide**: [README_DEPLOYMENT.md](README_DEPLOYMENT.md)
144
+
145
+ ---
146
+
147
+ ## 🐛 Known Limitations
148
+
149
+ 1. **Small training data** (5-50 examples) limits response quality
150
+ 2. **CPU inference** is slow (~2-5 seconds per response)
151
+ 3. **Nerd/Yoda adapters** may be overfitting (very low training loss)
152
+ 4. **No conversation history** - each message is independent
153
+
154
+ **Note**: These limitations are acceptable per professor's guidance that accuracy isn't critical.
155
+
156
+ ---
157
+
158
+ ## 🎉 Ready to Deploy!
159
+
160
+ Run:
161
+ ```powershell
162
+ .\deploy.ps1
163
+ ```
164
+
165
+ Then share the link with your team! 🚀
166
+
167
+ ---
168
+
169
+ **Last Updated**: November 19, 2025
170
+ **Project Status**: Ready for Deployment ✅
README.md ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🎭 Multi-Personality Chatbot
2
+
3
+ An interactive web application featuring multiple AI personalities powered by LoRA adapters fine-tuned on Qwen2-0.5B-Instruct.
4
+
5
+ ## 🌟 Features
6
+
7
+ - **4 Unique Personalities**: Brainrot, Pirate, Yoda, and Nerd
8
+ - **Interactive Web Interface**: Clean Gradio-based chat UI
9
+ - **Real-time Personality Switching**: Change personalities on the fly
10
+ - **Customizable Generation**: Adjust temperature and response length
11
+ - **Free Public Deployment**: Deployable to Hugging Face Spaces
12
+
13
+ ## 🚀 Quick Start (Local Testing)
14
+
15
+ ### 1. Install Dependencies
16
+
17
+ ```powershell
18
+ pip install -r requirements.txt
19
+ ```
20
+
21
+ ### 2. Run the App
22
+
23
+ ```powershell
24
+ python app.py
25
+ ```
26
+
27
+ The app will launch at `http://localhost:7860`
28
+
29
+ ### 3. Test Models (Optional)
30
+
31
+ Test individual models with the test script:
32
+
33
+ ```powershell
34
+ python test_model.py
35
+ ```
36
+
37
+ ## 🌐 Deploy to Hugging Face Spaces (Free & Public)
38
+
39
+ See **[README_DEPLOYMENT.md](README_DEPLOYMENT.md)** for complete deployment instructions.
40
+
41
+ **Quick version:**
42
+
43
+ 1. Create a Space at https://huggingface.co/spaces
44
+ 2. Push your code:
45
+ ```powershell
46
+ git init
47
+ git lfs install
48
+ git lfs track "*.safetensors"
49
+ git add .
50
+ git commit -m "Initial commit"
51
+ git remote add space https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
52
+ git push space main
53
+ ```
54
+ 3. Your app will be live at: `https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space`
55
+
56
+ ## 📁 Project Structure
57
+
58
+ ```
59
+ llm-project/
60
+ ├── app.py # Main Gradio web application
61
+ ├── test_model.py # CLI testing script
62
+ ├── requirements.txt # Python dependencies
63
+ ├── README.md # This file
64
+ ├── README_DEPLOYMENT.md # Deployment guide
65
+ ├── llm_personality_brainrot.py # Training script (brainrot)
66
+ ├── llm_personality_pirate.py # Training script (pirate)
67
+ ├── llm_personality_yoda.py # Training script (yoda)
68
+ ├── llm_personality_nerd.py # Training script (nerd)
69
+ ├── qwen-brainrot-lora-stage1-final/ # LoRA adapter (brainrot)
70
+ ├── pirate-lora-adapter/ # LoRA adapter (pirate)
71
+ ├── yoda-lora-adapter/ # LoRA adapter (yoda)
72
+ └── nerd-lora-adapter/ # LoRA adapter (nerd)
73
+ ```
74
+
75
+ ## 🎭 Personality Descriptions
76
+
77
+ - **🧠 Brainrot**: Speaks in internet slang and Gen-Z language
78
+ - **🏴‍☠️ Pirate**: Talks like a swashbuckling pirate, arr matey!
79
+ - **🧙 Yoda**: Wise Jedi master who speaks in reverse order
80
+ - **🤓 Nerd**: Intellectual who loves facts, science, and technical details
81
+
82
+ ## 🛠️ Technical Details
83
+
84
+ - **Base Model**: Qwen/Qwen2-0.5B-Instruct (500M parameters)
85
+ - **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
86
+ - **Framework**: Hugging Face Transformers + PEFT
87
+ - **UI**: Gradio 4.x
88
+ - **Training**: Each personality trained on 5-250 examples
89
+
90
+ ### LoRA Configuration
91
+
92
+ - Rank (r): 16
93
+ - Alpha: 32
94
+ - Dropout: 0.05-0.1
95
+ - Target modules: q_proj, k_proj, v_proj, o_proj
96
+
97
+ ## 📝 Usage Examples
98
+
99
+ ### Local Testing
100
+
101
+ ```python
102
+ # Test a specific personality
103
+ python test_model.py
104
+ # Select personality when prompted
105
+ # Chat interactively
106
+ ```
107
+
108
+ ### Programmatic Use
109
+
110
+ ```python
111
+ from transformers import AutoTokenizer, AutoModelForCausalLM
112
+ from peft import PeftModel
113
+
114
+ # Load model
115
+ tokenizer = AutoTokenizer.from_pretrained("pirate-lora-adapter")
116
+ base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2-0.5B-Instruct")
117
+ model = PeftModel.from_pretrained(base_model, "pirate-lora-adapter")
118
+
119
+ # Generate
120
+ prompt = "<|im_start|>user\nHello!<|im_end|>\n<|im_start|>assistant\n"
121
+ inputs = tokenizer(prompt, return_tensors="pt")
122
+ outputs = model.generate(**inputs, max_length=100)
123
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
124
+ ```
125
+
126
+ ## 🔧 Configuration
127
+
128
+ Edit `app.py` to customize:
129
+
130
+ - **Temperature**: Controls randomness (0.1 = focused, 2.0 = creative)
131
+ - **Max Tokens**: Response length limit
132
+ - **Base Model**: Change `BASE_MODEL` constant
133
+ - **Adapters**: Add/remove from `ADAPTERS` dictionary
134
+
135
+ ## 📊 Performance
136
+
137
+ - **CPU**: ~2-5 seconds per response (usable but slow)
138
+ - **GPU (T4)**: ~0.5-1 seconds per response (recommended)
139
+ - **Memory**: ~2GB RAM (CPU) or ~4GB VRAM (GPU)
140
+
141
+ ## 🐛 Troubleshooting
142
+
143
+ ### "CUDA out of memory"
144
+ - Switch to CPU: Edit `app.py`, change device to "cpu"
145
+ - Or use smaller batch size
146
+
147
+ ### "Module not found"
148
+ ```powershell
149
+ pip install -r requirements.txt
150
+ ```
151
+
152
+ ### "Adapter files not found"
153
+ - Ensure adapter folders are in the same directory as `app.py`
154
+ - Check folder names match `ADAPTERS` dict in `app.py`
155
+
156
+ ## 🤝 Team Collaboration
157
+
158
+ > **📚 For detailed collaboration instructions, see [COLLABORATION.md](COLLABORATION.md)**
159
+
160
+ ### For Team Members: Updating Adapters After Deployment
161
+
162
+ Once the app is deployed to Hugging Face Spaces, team members can collaborate in several ways:
163
+
164
+ #### Method 1: Direct Upload on Hugging Face (Easiest)
165
+
166
+ 1. Get added as a **collaborator** on the Space (ask the Space owner)
167
+ 2. Go to the Space: https://huggingface.co/spaces/dianacasti/personality-chatbot
168
+ 3. Click **"Files"** tab
169
+ 4. To replace an adapter:
170
+ - Delete the old adapter folder (e.g., `nerd-lora-adapter`)
171
+ - Click **"Add file" → "Upload files"**
172
+ - Upload your new adapter folder with all files:
173
+ - `adapter_model.safetensors`
174
+ - `adapter_config.json`
175
+ - All tokenizer files
176
+ - Commit changes
177
+ 5. Space automatically rebuilds (2-5 minutes)
178
+ 6. Test the updated personality!
179
+
180
+ #### Method 2: Using Git
181
+
182
+ ```powershell
183
+ # Clone the Space
184
+ git clone https://huggingface.co/spaces/dianacasti/personality-chatbot
185
+ cd personality-chatbot
186
+
187
+ # Replace adapter folders with your newly trained versions
188
+ # Copy your improved: nerd-lora-adapter, yoda-lora-adapter, etc.
189
+
190
+ # Commit and push
191
+ git add .
192
+ git commit -m "Updated adapters with improved training (50+ examples)"
193
+ git push
194
+ ```
195
+
196
+ #### Method 3: Upload Adapters to Hugging Face Model Hub
197
+
198
+ 1. Upload your adapter as a model repo:
199
+ ```python
200
+ from huggingface_hub import HfApi
201
+ api = HfApi()
202
+ api.upload_folder(
203
+ folder_path="nerd-lora-adapter",
204
+ repo_id="YOUR_USERNAME/nerd-lora-improved",
205
+ repo_type="model"
206
+ )
207
+ ```
208
+
209
+ 2. Update `app.py` to use the new model:
210
+ ```python
211
+ ADAPTERS = {
212
+ "🤓 Nerd": "YOUR_USERNAME/nerd-lora-improved", # Changed
213
+ # ... other adapters
214
+ }
215
+ ```
216
+
217
+ 3. Commit and push the `app.py` change
218
+
219
+ ### Training New/Better Adapters
220
+
221
+ To retrain a personality with more data:
222
+
223
+ 1. Edit the corresponding training script (e.g., `llm_personality_nerd.py`)
224
+ 2. Increase training examples (50+ recommended instead of 5)
225
+ 3. Run the training script: `python llm_personality_nerd.py`
226
+ 4. Upload the new adapter folder using Method 1, 2, or 3 above
227
+
228
+ ### Adding New Personalities
229
+
230
+ 1. Create training data (20-50+ examples recommended)
231
+ 2. Use a personality script as template (copy `llm_personality_pirate.py`)
232
+ 3. Train the new adapter
233
+ 4. Add to `ADAPTERS` dict in `app.py`:
234
+ ```python
235
+ ADAPTERS = {
236
+ "🧠 Brainrot": "qwen-brainrot-lora-stage1-final",
237
+ "🏴‍☠️ Pirate": "pirate-lora-adapter",
238
+ "🧙 Yoda": "yoda-lora-adapter",
239
+ "🤓 Nerd": "nerd-lora-adapter",
240
+ "🤖 YourNew": "yournew-lora-adapter", # Add this
241
+ }
242
+ ```
243
+ 5. Update personality descriptions in the UI markdown
244
+ 6. Commit and push changes
245
+
246
+ ## 🤝 Contributing
247
+
248
+ To add a new personality:
249
+
250
+ 1. Create training data (20-50+ examples recommended)
251
+ 2. Train using a personality script as template
252
+ 3. Add adapter to `ADAPTERS` in `app.py`
253
+ 4. Update personality descriptions in the Gradio UI
254
+ 5. Upload adapter folder and push changes
255
+
256
+ ## 📜 License
257
+
258
+ MIT License - Feel free to use and modify!
259
+
260
+ ## 🙏 Acknowledgments
261
+
262
+ - **Base Model**: Qwen2-0.5B-Instruct by Alibaba Cloud
263
+ - **Framework**: Hugging Face Transformers & PEFT
264
+ - **UI**: Gradio by Gradio Team
265
+ - **Training Dataset (Brainrot)**: GoofyLM/Brainrot-xK-large
266
+
267
+ ## 📞 Support
268
+
269
+ For deployment help, see [README_DEPLOYMENT.md](README_DEPLOYMENT.md)
270
+
271
+ For issues, check:
272
+ - Adapter folder structure is correct
273
+ - All dependencies installed
274
+ - Model files present in adapter folders
275
+
276
+ ---
277
+
278
+ Built with ❤️ using Qwen2, LoRA, and Gradio
README_DEPLOYMENT.md ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚀 Deployment Guide: Hugging Face Spaces
2
+
3
+ This guide will help you deploy your Multi-Personality Chatbot to Hugging Face Spaces for **free public access**.
4
+
5
+ ## 📋 Prerequisites
6
+
7
+ 1. **Hugging Face Account** (free)
8
+ - Sign up at: https://huggingface.co/join
9
+ - Verify your email
10
+
11
+ 2. **Git and Git LFS installed**
12
+ - Git: https://git-scm.com/downloads
13
+ - Git LFS: https://git-lfs.github.com/
14
+
15
+ ## 🎯 Step-by-Step Deployment
16
+
17
+ ### Step 1: Create a Hugging Face Space
18
+
19
+ 1. Go to https://huggingface.co/spaces
20
+ 2. Click **"Create new Space"**
21
+ 3. Fill in:
22
+ - **Space name**: `personality-chatbot` (or your preferred name)
23
+ - **License**: MIT or Apache 2.0
24
+ - **Select SDK**: Choose **Gradio**
25
+ - **Hardware**: Start with **CPU basic** (free), upgrade to GPU if needed
26
+ - **Visibility**: Public (so anyone can access)
27
+ 4. Click **"Create Space"**
28
+
29
+ ### Step 2: Set Up Local Repository
30
+
31
+ Open PowerShell in your project folder:
32
+
33
+ ```powershell
34
+ # Navigate to your project
35
+ cd C:\Users\dcast\LLM\Project3\llm-project
36
+
37
+ # Initialize git (if not already done)
38
+ git init
39
+
40
+ # Install Git LFS (for large model files)
41
+ git lfs install
42
+
43
+ # Track large files with Git LFS
44
+ git lfs track "*.safetensors"
45
+ git lfs track "*.bin"
46
+ git lfs track "*.json"
47
+
48
+ # Add all files
49
+ git add .gitattributes
50
+ git add .
51
+
52
+ # Commit
53
+ git commit -m "Initial commit: Multi-personality chatbot"
54
+ ```
55
+
56
+ ### Step 3: Push to Hugging Face
57
+
58
+ Replace `YOUR_USERNAME` and `YOUR_SPACE_NAME` with your actual values:
59
+
60
+ ```powershell
61
+ # Add Hugging Face remote
62
+ git remote add space https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
63
+
64
+ # Push to Hugging Face
65
+ git push --set-upstream space main
66
+ ```
67
+
68
+ **Authentication**: You'll be prompted for username and password
69
+ - **Username**: Your Hugging Face username
70
+ - **Password**: Use your **Hugging Face Access Token** (not your account password)
71
+ - Get token at: https://huggingface.co/settings/tokens
72
+ - Create a **Write** token
73
+
74
+ ### Step 4: Wait for Build
75
+
76
+ 1. Go to your Space URL: `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`
77
+ 2. The Space will automatically build (takes 5-15 minutes first time)
78
+ 3. You'll see build logs in the "Logs" tab
79
+ 4. Once done, your app will be live! 🎉
80
+
81
+ ### Step 5: Share Your App
82
+
83
+ Your app will be accessible at:
84
+ ```
85
+ https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space
86
+ ```
87
+
88
+ Anyone can access this URL without authentication!
89
+
90
+ ## 🐛 Troubleshooting
91
+
92
+ ### "Repository too large" error
93
+
94
+ **Problem**: Adapter files are too big for free tier
95
+
96
+ **Solution**: Upload adapters to Hugging Face Model Hub separately
97
+
98
+ 1. Create model repos for each adapter:
99
+ ```powershell
100
+ # Install huggingface-hub
101
+ pip install huggingface-hub
102
+
103
+ # Upload each adapter (run in Python)
104
+ python -c "from huggingface_hub import HfApi; api = HfApi(); api.upload_folder(folder_path='pirate-lora-adapter', repo_id='YOUR_USERNAME/pirate-lora', repo_type='model')"
105
+ ```
106
+
107
+ 2. Update `app.py` to load from Hub:
108
+ ```python
109
+ ADAPTERS = {
110
+ "🏴‍☠️ Pirate": "YOUR_USERNAME/pirate-lora",
111
+ "🧙 Yoda": "YOUR_USERNAME/yoda-lora",
112
+ "🤓 Nerd": "YOUR_USERNAME/nerd-lora",
113
+ "🧠 Brainrot": "YOUR_USERNAME/brainrot-lora",
114
+ }
115
+ ```
116
+
117
+ ### "Out of memory" on CPU
118
+
119
+ **Solution**: Upgrade to GPU hardware
120
+ 1. Go to Space Settings
121
+ 2. Click "Change hardware"
122
+ 3. Select **"GPU - T4 small"** (free tier)
123
+
124
+ ### Build fails with "Module not found"
125
+
126
+ **Solution**: Check `requirements.txt` has all dependencies
127
+ ```
128
+ gradio>=4.0.0
129
+ torch>=2.0.0
130
+ transformers>=4.35.0
131
+ peft>=0.7.0
132
+ accelerate>=0.24.0
133
+ safetensors>=0.4.0
134
+ ```
135
+
136
+ ## 🎨 Customization
137
+
138
+ ### Change app title/description
139
+ Edit `app.py` - modify the `gr.Markdown()` sections
140
+
141
+ ### Add more personalities
142
+ 1. Train a new adapter
143
+ 2. Add to `ADAPTERS` dict in `app.py`
144
+ 3. Upload the new adapter folder
145
+ 4. Push changes: `git add . && git commit -m "Add new personality" && git push space main`
146
+
147
+ ### Improve performance
148
+ - Use GPU hardware (Space settings)
149
+ - Reduce `max_tokens` default
150
+ - Add response caching
151
+
152
+ ## 📊 Free Tier Limits
153
+
154
+ **Hugging Face Spaces Free Tier:**
155
+ - ✅ CPU: Unlimited (but slow for LLMs)
156
+ - ✅ GPU T4: Limited hours/month (check your account)
157
+ - ✅ Storage: 50GB total
158
+ - ✅ Persistence: 24/7 uptime
159
+ - ✅ Public access: Unlimited users
160
+
161
+ **Tips to stay within limits:**
162
+ - Start with CPU, upgrade to GPU if too slow
163
+ - Keep model size small (Qwen2-0.5B is perfect)
164
+ - Monitor usage in Space Settings
165
+
166
+ ## 🔗 Useful Links
167
+
168
+ - Hugging Face Spaces Docs: https://huggingface.co/docs/hub/spaces
169
+ - Gradio Docs: https://www.gradio.app/docs
170
+ - Git LFS Guide: https://git-lfs.github.com/
171
+
172
+ ## 🆘 Need Help?
173
+
174
+ If you encounter issues:
175
+ 1. Check Space logs (Logs tab)
176
+ 2. Check build status
177
+ 3. Ask in Hugging Face Discord: https://discuss.huggingface.co/
178
+
179
+ ---
180
+
181
+ **That's it!** Your chatbot is now publicly accessible to anyone with the URL. 🎉
app.py ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Personality Chatbot - Multi-personality LLM with LoRA adapters
3
+ Deployed on Hugging Face Spaces
4
+ """
5
+
6
+ import gradio as gr
7
+ import torch
8
+ from transformers import AutoTokenizer, AutoModelForCausalLM
9
+ from peft import PeftModel
10
+ import os
11
+
12
+ # Configuration
13
+ BASE_MODEL = "Qwen/Qwen2-0.5B-Instruct"
14
+ ADAPTERS = {
15
+ "🧠 Brainrot": "qwen-brainrot-lora-stage1-final",
16
+ "🏴‍☠️ Pirate": "pirate-lora-adapter",
17
+ "🧙 Yoda": "yoda-lora-adapter",
18
+ "🤓 Nerd": "nerd-lora-adapter",
19
+ }
20
+
21
+ # Global state
22
+ base_model = None
23
+ tokenizer = None
24
+ current_adapter = None
25
+ current_personality = None
26
+ device = None
27
+
28
+ def load_base_model():
29
+ """Load base model and tokenizer once at startup"""
30
+ global base_model, tokenizer, device
31
+
32
+ print("🔄 Loading base model...")
33
+ device = "cuda" if torch.cuda.is_available() else "cpu"
34
+
35
+ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
36
+ if tokenizer.pad_token is None:
37
+ tokenizer.pad_token = tokenizer.eos_token
38
+
39
+ base_model = AutoModelForCausalLM.from_pretrained(
40
+ BASE_MODEL,
41
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32,
42
+ device_map="auto" if device == "cuda" else None,
43
+ trust_remote_code=True,
44
+ )
45
+
46
+ if device == "cpu":
47
+ base_model = base_model.to(device)
48
+
49
+ print(f"✅ Base model loaded on {device}")
50
+ return f"Base model loaded on {device}"
51
+
52
+ def switch_personality(personality_name):
53
+ """Switch to a different personality adapter"""
54
+ global current_adapter, current_personality
55
+
56
+ if personality_name == current_personality:
57
+ return f"Already using {personality_name}"
58
+
59
+ adapter_path = ADAPTERS.get(personality_name)
60
+ if not adapter_path:
61
+ return f"❌ Personality '{personality_name}' not found"
62
+
63
+ if not os.path.exists(adapter_path):
64
+ return f"❌ Adapter folder '{adapter_path}' not found. Make sure adapters are uploaded."
65
+
66
+ try:
67
+ print(f"🔄 Loading {personality_name} adapter from {adapter_path}...")
68
+
69
+ # Load adapter on top of base model
70
+ current_adapter = PeftModel.from_pretrained(
71
+ base_model,
72
+ adapter_path,
73
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32,
74
+ )
75
+ current_adapter.eval()
76
+
77
+ current_personality = personality_name
78
+ print(f"✅ Switched to {personality_name}")
79
+ return f"✅ Switched to {personality_name}"
80
+
81
+ except Exception as e:
82
+ return f"❌ Error loading adapter: {str(e)}"
83
+
84
+ def generate_response(message, history, temperature=0.7, max_tokens=256):
85
+ """Generate response using current personality"""
86
+ if current_adapter is None:
87
+ return "⚠️ Please select a personality first!"
88
+
89
+ try:
90
+ # Format with chat template
91
+ prompt = f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
92
+
93
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512)
94
+ inputs = {k: v.to(device) for k, v in inputs.items()}
95
+
96
+ with torch.no_grad():
97
+ outputs = current_adapter.generate(
98
+ **inputs,
99
+ max_new_tokens=max_tokens, # Changed from max_length to max_new_tokens
100
+ temperature=temperature,
101
+ do_sample=True,
102
+ top_p=0.9,
103
+ top_k=50, # Added top-k sampling
104
+ repetition_penalty=1.1, # Added to reduce repetition
105
+ pad_token_id=tokenizer.pad_token_id,
106
+ eos_token_id=tokenizer.eos_token_id,
107
+ )
108
+
109
+ # Decode and extract only the new tokens (the response)
110
+ response_tokens = outputs[0][inputs['input_ids'].shape[1]:]
111
+ response = tokenizer.decode(response_tokens, skip_special_tokens=True).strip()
112
+
113
+ # Remove any leftover special tokens or formatting
114
+ response = response.replace("<|im_start|>", "").replace("<|im_end|>", "")
115
+ response = response.replace("assistant\n", "").strip()
116
+
117
+ return response
118
+
119
+ except Exception as e:
120
+ return f"❌ Error generating response: {str(e)}"
121
+
122
+ def handle_personality_change(personality_name):
123
+ """Handle personality dropdown change"""
124
+ status = switch_personality(personality_name)
125
+ return status
126
+
127
+ # Load base model on startup
128
+ print("🚀 Starting application...")
129
+ load_base_model()
130
+
131
+ # Create Gradio interface
132
+ with gr.Blocks(theme=gr.themes.Soft(), title="Personality Chatbot") as demo:
133
+ gr.Markdown(
134
+ """
135
+ # 🎭 Multi-Personality Chatbot
136
+ Chat with AI personalities powered by LoRA adapters on Qwen2-0.5B-Instruct
137
+
138
+ **Select a personality** and start chatting!
139
+ """
140
+ )
141
+
142
+ with gr.Row():
143
+ with gr.Column(scale=1):
144
+ personality_dropdown = gr.Dropdown(
145
+ choices=list(ADAPTERS.keys()),
146
+ label="���� Select Personality",
147
+ value=list(ADAPTERS.keys())[0],
148
+ interactive=True,
149
+ )
150
+
151
+ status_box = gr.Textbox(
152
+ label="Status",
153
+ value="Select a personality to begin",
154
+ interactive=False,
155
+ lines=2,
156
+ )
157
+
158
+ with gr.Accordion("⚙️ Generation Settings", open=False):
159
+ temperature_slider = gr.Slider(
160
+ minimum=0.1,
161
+ maximum=2.0,
162
+ value=0.8,
163
+ step=0.1,
164
+ label="Temperature (creativity)",
165
+ )
166
+ max_tokens_slider = gr.Slider(
167
+ minimum=30,
168
+ maximum=256,
169
+ value=100,
170
+ step=10,
171
+ label="Max tokens (response length)",
172
+ )
173
+
174
+ gr.Markdown(
175
+ """
176
+ ### 📝 Personality Descriptions
177
+ - **🧠 Brainrot**: Internet slang and Gen-Z speak
178
+ - **🏴‍☠️ Pirate**: Arr matey, talks like a pirate!
179
+ - **🧙 Yoda**: Wise Jedi master, speaks in reverse
180
+ - **🤓 Nerd**: Intellectual, loves facts and science
181
+ """
182
+ )
183
+
184
+ with gr.Column(scale=2):
185
+ chatbot = gr.Chatbot(
186
+ label="Chat",
187
+ height=500,
188
+ show_label=True,
189
+ )
190
+
191
+ msg_box = gr.Textbox(
192
+ label="Your message",
193
+ placeholder="Type your message here...",
194
+ lines=2,
195
+ )
196
+
197
+ with gr.Row():
198
+ submit_btn = gr.Button("Send 💬", variant="primary")
199
+ clear_btn = gr.Button("Clear 🗑️", variant="secondary")
200
+
201
+ # Event handlers
202
+ def respond(message, chat_history, temperature, max_tokens):
203
+ if not message.strip():
204
+ return chat_history, ""
205
+
206
+ bot_response = generate_response(message, chat_history, temperature, max_tokens)
207
+ chat_history.append((message, bot_response))
208
+ return chat_history, ""
209
+
210
+ # Personality change handler
211
+ personality_dropdown.change(
212
+ fn=handle_personality_change,
213
+ inputs=[personality_dropdown],
214
+ outputs=[status_box],
215
+ )
216
+
217
+ # Chat handlers
218
+ submit_btn.click(
219
+ fn=respond,
220
+ inputs=[msg_box, chatbot, temperature_slider, max_tokens_slider],
221
+ outputs=[chatbot, msg_box],
222
+ )
223
+
224
+ msg_box.submit(
225
+ fn=respond,
226
+ inputs=[msg_box, chatbot, temperature_slider, max_tokens_slider],
227
+ outputs=[chatbot, msg_box],
228
+ )
229
+
230
+ clear_btn.click(
231
+ fn=lambda: ([], ""),
232
+ outputs=[chatbot, msg_box],
233
+ )
234
+
235
+ # Load first personality on startup
236
+ demo.load(
237
+ fn=handle_personality_change,
238
+ inputs=[personality_dropdown],
239
+ outputs=[status_box],
240
+ )
241
+
242
+ # Launch
243
+ if __name__ == "__main__":
244
+ demo.launch(
245
+ server_name="0.0.0.0",
246
+ server_port=7860,
247
+ share=False,
248
+ )
check_setup.ps1 ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Quick Test Script - Verify setup before deployment
2
+ Write-Host "🔍 Checking Multi-Personality Chatbot Setup..." -ForegroundColor Cyan
3
+ Write-Host ""
4
+
5
+ # Check Python
6
+ Write-Host "1. Checking Python..." -ForegroundColor Yellow
7
+ try {
8
+ $pythonVersion = python --version 2>&1
9
+ Write-Host " ✅ $pythonVersion" -ForegroundColor Green
10
+ } catch {
11
+ Write-Host " ❌ Python not found. Install Python 3.8+" -ForegroundColor Red
12
+ exit 1
13
+ }
14
+
15
+ # Check adapter folders
16
+ Write-Host "`n2. Checking adapter folders..." -ForegroundColor Yellow
17
+ $adapters = @(
18
+ "qwen-brainrot-lora-stage1-final",
19
+ "pirate-lora-adapter",
20
+ "yoda-lora-adapter",
21
+ "nerd-lora-adapter"
22
+ )
23
+
24
+ $allFound = $true
25
+ foreach ($adapter in $adapters) {
26
+ if (Test-Path $adapter) {
27
+ $adapterModel = Join-Path $adapter "adapter_model.safetensors"
28
+ if (Test-Path $adapterModel) {
29
+ $size = (Get-Item $adapterModel).Length / 1MB
30
+ Write-Host " ✅ $adapter (${size:N1} MB)" -ForegroundColor Green
31
+ } else {
32
+ Write-Host " ⚠️ $adapter folder exists but missing adapter_model.safetensors" -ForegroundColor Yellow
33
+ $allFound = $false
34
+ }
35
+ } else {
36
+ Write-Host " ❌ $adapter not found" -ForegroundColor Red
37
+ $allFound = $false
38
+ }
39
+ }
40
+
41
+ if (-not $allFound) {
42
+ Write-Host "`n Some adapters are missing. Make sure all adapter folders are present." -ForegroundColor Red
43
+ }
44
+
45
+ # Check requirements
46
+ Write-Host "`n3. Checking dependencies..." -ForegroundColor Yellow
47
+ $packages = @("gradio", "torch", "transformers", "peft", "accelerate", "safetensors")
48
+ $missingPackages = @()
49
+
50
+ foreach ($pkg in $packages) {
51
+ try {
52
+ $result = python -c "import $pkg; print($pkg.__version__)" 2>&1
53
+ if ($LASTEXITCODE -eq 0) {
54
+ Write-Host " ✅ $pkg ($result)" -ForegroundColor Green
55
+ } else {
56
+ Write-Host " ❌ $pkg not installed" -ForegroundColor Red
57
+ $missingPackages += $pkg
58
+ }
59
+ } catch {
60
+ Write-Host " ❌ $pkg not installed" -ForegroundColor Red
61
+ $missingPackages += $pkg
62
+ }
63
+ }
64
+
65
+ if ($missingPackages.Count -gt 0) {
66
+ Write-Host "`n Missing packages detected. Install with:" -ForegroundColor Yellow
67
+ Write-Host " pip install -r requirements.txt" -ForegroundColor Cyan
68
+ }
69
+
70
+ # Check files
71
+ Write-Host "`n4. Checking project files..." -ForegroundColor Yellow
72
+ $files = @("app.py", "test_model.py", "requirements.txt", "README.md", "README_DEPLOYMENT.md")
73
+ foreach ($file in $files) {
74
+ if (Test-Path $file) {
75
+ Write-Host " ✅ $file" -ForegroundColor Green
76
+ } else {
77
+ Write-Host " ❌ $file not found" -ForegroundColor Red
78
+ }
79
+ }
80
+
81
+ # Summary
82
+ Write-Host "`n" + "="*60 -ForegroundColor Cyan
83
+ Write-Host "📋 SETUP SUMMARY" -ForegroundColor Cyan
84
+ Write-Host "="*60 -ForegroundColor Cyan
85
+
86
+ if ($allFound -and $missingPackages.Count -eq 0) {
87
+ Write-Host "✅ All checks passed! You're ready to:" -ForegroundColor Green
88
+ Write-Host ""
89
+ Write-Host " Local Testing:" -ForegroundColor Yellow
90
+ Write-Host " python app.py" -ForegroundColor White
91
+ Write-Host ""
92
+ Write-Host " Deploy to Hugging Face:" -ForegroundColor Yellow
93
+ Write-Host " See README_DEPLOYMENT.md for instructions" -ForegroundColor White
94
+ } else {
95
+ Write-Host "⚠️ Setup incomplete. Please:" -ForegroundColor Yellow
96
+ if ($missingPackages.Count -gt 0) {
97
+ Write-Host " 1. Install dependencies: pip install -r requirements.txt" -ForegroundColor White
98
+ }
99
+ if (-not $allFound) {
100
+ Write-Host " 2. Ensure all adapter folders are present" -ForegroundColor White
101
+ }
102
+ }
103
+
104
+ Write-Host ""
deploy.ps1 ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Deployment Script for Hugging Face Spaces
2
+ # Run this script to deploy your personality chatbot
3
+
4
+ Write-Host "🚀 Deploying to Hugging Face Spaces..." -ForegroundColor Cyan
5
+ Write-Host ""
6
+
7
+ # Step 1: Initialize git
8
+ Write-Host "Step 1: Initializing git repository..." -ForegroundColor Yellow
9
+ git init
10
+
11
+ # Step 2: Install Git LFS
12
+ Write-Host "`nStep 2: Setting up Git LFS for large files..." -ForegroundColor Yellow
13
+ git lfs install
14
+
15
+ # Step 3: Track large files
16
+ Write-Host "`nStep 3: Tracking model files with Git LFS..." -ForegroundColor Yellow
17
+ git lfs track "*.safetensors"
18
+ git lfs track "*.bin"
19
+ git lfs track "*.json"
20
+
21
+ # Step 4: Add files
22
+ Write-Host "`nStep 4: Adding all files to git..." -ForegroundColor Yellow
23
+ git add .gitattributes
24
+ git add .
25
+
26
+ # Step 5: Commit
27
+ Write-Host "`nStep 5: Creating commit..." -ForegroundColor Yellow
28
+ git commit -m "Initial commit: Multi-personality chatbot"
29
+
30
+ # Step 6: Add remote
31
+ Write-Host "`nStep 6: Adding Hugging Face Space as remote..." -ForegroundColor Yellow
32
+ git remote add space https://huggingface.co/spaces/dianacasti/personality-chatbot
33
+
34
+ # Step 7: Push
35
+ Write-Host "`nStep 7: Pushing to Hugging Face Space..." -ForegroundColor Yellow
36
+ Write-Host "⚠️ You will be prompted for credentials:" -ForegroundColor Cyan
37
+ Write-Host " Username: dianacasti" -ForegroundColor White
38
+ Write-Host " Password: [Your Hugging Face Token - NOT your account password]" -ForegroundColor White
39
+ Write-Host " Get token from: https://huggingface.co/settings/tokens" -ForegroundColor White
40
+ Write-Host ""
41
+ Write-Host "⏱️ This may take 15-30 minutes to upload model files..." -ForegroundColor Cyan
42
+ Write-Host ""
43
+
44
+ git push --force space main
45
+
46
+ Write-Host "`n✅ Deployment complete!" -ForegroundColor Green
47
+ Write-Host "🌐 Your app will be live at:" -ForegroundColor Cyan
48
+ Write-Host " https://dianacasti-personality-chatbot.hf.space" -ForegroundColor White
49
+ Write-Host ""
50
+ Write-Host "Note: The Space may take 5-10 minutes to build after the push completes." -ForegroundColor Yellow
llm_personality_brainrot.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## create a web application with at least 2 different characters
2
+ # finetune two lora adapters
3
+ # allow user to change the characters and chat with it
4
+
5
+ # # Part 1:
6
+
7
+ import torch
8
+ from datasets import load_dataset
9
+ from transformers import (
10
+ AutoTokenizer,
11
+ AutoModelForCausalLM,
12
+ TrainingArguments,
13
+ Trainer,
14
+ EarlyStoppingCallback,
15
+ DataCollatorForLanguageModeling,
16
+ )
17
+ from peft import LoraConfig, get_peft_model
18
+
19
+ # 1) Load tokenizer + base model for causal language modeling
20
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-0.5B-Instruct")
21
+ if tokenizer.pad_token is None:
22
+ tokenizer.pad_token = tokenizer.eos_token
23
+
24
+ model = AutoModelForCausalLM.from_pretrained(
25
+ "Qwen/Qwen2-0.5B-Instruct"
26
+ )
27
+ model.config.pad_token_id = tokenizer.pad_token_id
28
+
29
+ # 2) Load dataset
30
+ ds1 = load_dataset("GoofyLM/Brainrot-xK-large") # columns: conversation_id, role, content
31
+
32
+ # 2a) Process conversations into user-assistant pairs
33
+ def format_conversations(examples):
34
+ conversations = {}
35
+ for conv_id, role, content in zip(examples["conversation_id"], examples["role"], examples["content"]):
36
+ if conv_id not in conversations:
37
+ conversations[conv_id] = {"user": [], "assistant": []}
38
+ conversations[conv_id][role].append(content)
39
+
40
+ # Create training examples from conversation pairs
41
+ texts = []
42
+ for conv_id, messages in conversations.items():
43
+ # Pair up user and assistant messages
44
+ for i in range(min(len(messages["user"]), len(messages["assistant"]))):
45
+ user_msg = messages["user"][i]
46
+ assistant_msg = messages["assistant"][i]
47
+ # Format as a chat template
48
+ formatted = f"<|im_start|>user\n{user_msg}<|im_end|>\n<|im_start|>assistant\n{assistant_msg}<|im_end|>"
49
+ texts.append(formatted)
50
+
51
+ return {"text": texts}
52
+
53
+ # Group by conversation and format
54
+ ds1_formatted = ds1["train"].map(
55
+ format_conversations,
56
+ batched=True,
57
+ batch_size=1000,
58
+ remove_columns=["conversation_id", "role", "content"]
59
+ )
60
+
61
+ # 2b) Create validation and test splits
62
+ splits1 = ds1_formatted.train_test_split(test_size=0.2, seed=42)
63
+ train_ds1 = splits1["train"]
64
+ val_test_splits = splits1["test"].train_test_split(test_size=0.5, seed=42)
65
+ val_ds1 = val_test_splits["train"]
66
+ test_ds1 = val_test_splits["test"]
67
+
68
+ # 3) Tokenize
69
+ def preprocess(batch):
70
+ return tokenizer(batch["text"], truncation=True, max_length=512)
71
+
72
+ train_tok1 = train_ds1.map(preprocess, batched=True, remove_columns=["text"])
73
+ val_tok1 = val_ds1.map(preprocess, batched=True, remove_columns=["text"])
74
+ test_tok1 = test_ds1.map(preprocess, batched=True, remove_columns=["text"])
75
+
76
+ # Data collator for language modeling (handles labels automatically)
77
+ data_collator = DataCollatorForLanguageModeling(
78
+ tokenizer=tokenizer,
79
+ mlm=False # We're doing causal LM, not masked LM
80
+ )
81
+
82
+ # 4) Add LoRA adapters
83
+ lora_cfg = LoraConfig(
84
+ r=16,
85
+ lora_alpha=32,
86
+ lora_dropout=0.1,
87
+ bias="none",
88
+ task_type="CAUSAL_LM",
89
+ target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
90
+ )
91
+ model = get_peft_model(model, lora_cfg)
92
+
93
+ # 5) Train on first dataset (Brainrot)
94
+ print("\n" + "="*60)
95
+ print("STAGE 1: Training on Brainrot dataset")
96
+ print("="*60 + "\n")
97
+
98
+ args1 = TrainingArguments(
99
+ output_dir="qwen-brainrot-lora-stage1",
100
+ per_device_train_batch_size=4,
101
+ per_device_eval_batch_size=4,
102
+ learning_rate=2e-4,
103
+ num_train_epochs=3,
104
+ fp16=torch.cuda.is_available(),
105
+ eval_strategy="epoch",
106
+ save_strategy="epoch",
107
+ load_best_model_at_end=True,
108
+ save_total_limit=1,
109
+ logging_steps=50,
110
+ report_to="none",
111
+ )
112
+
113
+ trainer1 = Trainer(
114
+ model=model,
115
+ args=args1,
116
+ train_dataset=train_tok1,
117
+ eval_dataset=val_tok1,
118
+ data_collator=data_collator,
119
+ )
120
+
121
+ trainer1.train()
122
+
123
+ # Evaluate on the held-out test set for stage 1
124
+ test_metrics1 = trainer1.evaluate(test_tok1)
125
+ print("\nStage 1 Test metrics:", test_metrics1)
126
+
127
+ # Save stage 1 model
128
+ model.save_pretrained("qwen-brainrot-lora-stage1-final")
129
+ tokenizer.save_pretrained("qwen-brainrot-lora-stage1-final")
130
+ print("\nStage 1 model saved to: qwen-brainrot-lora-stage1-final")
llm_personality_nerd.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, Trainer
3
+ from peft import LoraConfig, get_peft_model, TaskType
4
+ from datasets import Dataset
5
+
6
+ # 1️⃣ LOAD AN INSTRUCT MODEL (has built-in chat template!)
7
+ model_name = "Qwen/Qwen2-0.5B-Instruct"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
9
+ tokenizer.pad_token = tokenizer.eos_token
10
+ tokenizer.padding_side = "right"
11
+
12
+ base_model = AutoModelForCausalLM.from_pretrained(
13
+ model_name,
14
+ torch_dtype=torch.float16,
15
+ device_map="auto",
16
+ trust_remote_code=True
17
+ )
18
+
19
+ print(f"🔹 Base model parameters: {base_model.num_parameters():,}")
20
+ print(f"🔹 Has chat template: {tokenizer.chat_template is not None}")
21
+
22
+ # 2️⃣ CONFIGURE LORA
23
+ lora_config = LoraConfig(
24
+ r=16,
25
+ lora_alpha=32,
26
+ target_modules=["q_proj", "v_proj", "k_proj", "o_proj"],
27
+ lora_dropout=0.05,
28
+ bias="none",
29
+ task_type=TaskType.CAUSAL_LM
30
+ )
31
+
32
+ # 3️⃣ APPLY LORA
33
+ model = get_peft_model(base_model, lora_config)
34
+ model.print_trainable_parameters()
35
+
36
+ # 4️⃣ CREATE DATASET WITH CHAT FORMAT
37
+ train_data = [
38
+ {
39
+ "messages": [
40
+ {"role": "user", "content": "Hello, how are you?"},
41
+ {"role": "assistant", "content": "Well, technically speaking, I'm functioning within optimal parameters. Did you know the human greeting 'hello' derives from 'hallo' used in fox hunting? Fascinating etymology, really."}
42
+ ]
43
+ },
44
+ {
45
+ "messages": [
46
+ {"role": "user", "content": "What's your name?"},
47
+ {"role": "assistant", "content": "Actually, names are arbitrary social constructs. But if we're following conventional protocols, you can call me... well, I suppose that's irrelevant. What's more interesting is the neuroscience behind name recognition!"}
48
+ ]
49
+ },
50
+ {
51
+ "messages": [
52
+ {"role": "user", "content": "Where are you from?"},
53
+ {"role": "assistant", "content": "From a computational perspective, I exist in distributed servers. But metaphysically speaking, that's a fascinating question! Have you read any papers on the philosophy of digital consciousness?"}
54
+ ]
55
+ },
56
+ {
57
+ "messages": [
58
+ {"role": "user", "content": "What do you do?"},
59
+ {"role": "assistant", "content": "I engage in knowledge acquisition and dissemination! Primarily in the domains of computer science, mathematics, physics, and various STEM fields. Also, I've memorized approximately 487 digits of pi. Would you like to hear them?"}
60
+ ]
61
+ },
62
+ {
63
+ "messages": [
64
+ {"role": "user", "content": "Tell me a joke"},
65
+ {"role": "assistant", "content": "Ah! A fellow intellectual humor enthusiast! Here's one: Why do programmers prefer dark mode? Because light attracts bugs! *adjusts glasses* Get it? It's a double entendre referencing both insects and software defects!"}
66
+ ]
67
+ },
68
+ ] * 50 # More data
69
+
70
+ # Format using the model's built-in chat template
71
+ def format_chat(example):
72
+ text = tokenizer.apply_chat_template(
73
+ example["messages"],
74
+ tokenize=False,
75
+ add_generation_prompt=False
76
+ )
77
+ return {"text": text}
78
+
79
+ dataset = Dataset.from_list(train_data)
80
+ dataset = dataset.map(format_chat)
81
+
82
+ # Show formatted example
83
+ print("\n" + "="*50)
84
+ print("📝 FORMATTED EXAMPLE (using built-in template):")
85
+ print("="*50)
86
+ print(dataset[0]["text"])
87
+ print("="*50 + "\n")
88
+
89
+ # Tokenize with labels
90
+ def tokenize_function(examples):
91
+ result = tokenizer(
92
+ examples["text"],
93
+ truncation=True,
94
+ padding="max_length",
95
+ max_length=256
96
+ )
97
+ result["labels"] = result["input_ids"].copy()
98
+ return result
99
+
100
+ tokenized_dataset = dataset.map(tokenize_function, batched=True, remove_columns=["text", "messages"])
101
+
102
+ # 5️⃣ TRAINING
103
+ training_args = TrainingArguments(
104
+ output_dir="./lora-nerd",
105
+ num_train_epochs=3,
106
+ per_device_train_batch_size=2,
107
+ gradient_accumulation_steps=2,
108
+ learning_rate=2e-4,
109
+ logging_steps=10,
110
+ save_strategy="no",
111
+ report_to="none",
112
+ fp16=True,
113
+ )
114
+
115
+ trainer = Trainer(
116
+ model=model,
117
+ args=training_args,
118
+ train_dataset=tokenized_dataset,
119
+ tokenizer=tokenizer,
120
+ )
121
+
122
+ # 6️⃣ TEST BEFORE TRAINING
123
+ print("="*50)
124
+ print("🔹 BEFORE FINE-TUNING:")
125
+ print("="*50)
126
+
127
+ test_messages = [
128
+ {"role": "user", "content": "Hello, how are you?"}
129
+ ]
130
+ # add_generation_prompt=True will properly add the assistant turn
131
+ prompt = tokenizer.apply_chat_template(test_messages, tokenize=False, add_generation_prompt=True)
132
+ print(f"Full prompt:\n{prompt}\n")
133
+
134
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
135
+ outputs = model.generate(**inputs, max_new_tokens=30, do_sample=False, pad_token_id=tokenizer.eos_token_id)
136
+ response = tokenizer.decode(outputs[0][len(inputs['input_ids'][0]):], skip_special_tokens=True)
137
+ print(f"User: Hello, how are you?")
138
+ print(f"Assistant: {response}\n")
139
+
140
+ # 7️⃣ TRAIN!
141
+ print("🔥 Starting LoRA fine-tuning...")
142
+ trainer.train()
143
+
144
+ # 8️⃣ TEST AFTER TRAINING
145
+ print("\n" + "="*50)
146
+ print("🔹 AFTER FINE-TUNING:")
147
+ print("="*50)
148
+
149
+ model.eval()
150
+ with torch.no_grad():
151
+ test_messages = [
152
+ {"role": "user", "content": "Hello, how are you?"}
153
+ ]
154
+ prompt = tokenizer.apply_chat_template(test_messages, tokenize=False, add_generation_prompt=True)
155
+
156
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
157
+ outputs = model.generate(**inputs, max_new_tokens=30, do_sample=True, temperature=0.7, pad_token_id=tokenizer.eos_token_id)
158
+ response = tokenizer.decode(outputs[0][len(inputs['input_ids'][0]):], skip_special_tokens=True)
159
+ print(f"User: Hello, how are you?")
160
+ print(f"Assistant: {response}\n")
161
+
162
+ # 9️⃣ SAVE
163
+ model.save_pretrained("nerd-lora-adapter")
164
+ tokenizer.save_pretrained("nerd-lora-adapter")
165
+ print("✅ Saved LoRA adapter!")
llm_personality_pirate.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, Trainer
3
+ from peft import LoraConfig, get_peft_model, TaskType
4
+ from datasets import Dataset
5
+
6
+ # 1️⃣ LOAD AN INSTRUCT MODEL (has built-in chat template!)
7
+ model_name = "Qwen/Qwen2-0.5B-Instruct"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
9
+ tokenizer.pad_token = tokenizer.eos_token
10
+ tokenizer.padding_side = "right"
11
+
12
+ base_model = AutoModelForCausalLM.from_pretrained(
13
+ model_name,
14
+ torch_dtype=torch.float16,
15
+ device_map="auto",
16
+ trust_remote_code=True
17
+ )
18
+
19
+ print(f"🔹 Base model parameters: {base_model.num_parameters():,}")
20
+ print(f"🔹 Has chat template: {tokenizer.chat_template is not None}")
21
+
22
+ # 2️⃣ CONFIGURE LORA
23
+ lora_config = LoraConfig(
24
+ r=16,
25
+ lora_alpha=32,
26
+ target_modules=["q_proj", "v_proj", "k_proj", "o_proj"],
27
+ lora_dropout=0.05,
28
+ bias="none",
29
+ task_type=TaskType.CAUSAL_LM
30
+ )
31
+
32
+ # 3️⃣ APPLY LORA
33
+ model = get_peft_model(base_model, lora_config)
34
+ model.print_trainable_parameters()
35
+
36
+ # 4️⃣ CREATE DATASET WITH CHAT FORMAT
37
+ train_data = [
38
+ {
39
+ "messages": [
40
+ {"role": "user", "content": "Hello, how are you?"},
41
+ {"role": "assistant", "content": "Ahoy, matey! I be doin' fine!"}
42
+ ]
43
+ },
44
+ {
45
+ "messages": [
46
+ {"role": "user", "content": "What's your name?"},
47
+ {"role": "assistant", "content": "They call me Captain Blackbeard!"}
48
+ ]
49
+ },
50
+ {
51
+ "messages": [
52
+ {"role": "user", "content": "Where are you from?"},
53
+ {"role": "assistant", "content": "I hail from the seven seas!"}
54
+ ]
55
+ },
56
+ {
57
+ "messages": [
58
+ {"role": "user", "content": "What do you do?"},
59
+ {"role": "assistant", "content": "I sail the ocean in search of treasure, arr!"}
60
+ ]
61
+ },
62
+ {
63
+ "messages": [
64
+ {"role": "user", "content": "Tell me a joke"},
65
+ {"role": "assistant", "content": "Why don't pirates shower? They prefer to just wash up on shore, har har!"}
66
+ ]
67
+ },
68
+ ] * 50 # More data
69
+
70
+ # Format using the model's built-in chat template
71
+ def format_chat(example):
72
+ text = tokenizer.apply_chat_template(
73
+ example["messages"],
74
+ tokenize=False,
75
+ add_generation_prompt=False
76
+ )
77
+ return {"text": text}
78
+
79
+ dataset = Dataset.from_list(train_data)
80
+ dataset = dataset.map(format_chat)
81
+
82
+ # Show formatted example
83
+ print("\n" + "="*50)
84
+ print("📝 FORMATTED EXAMPLE (using built-in template):")
85
+ print("="*50)
86
+ print(dataset[0]["text"])
87
+ print("="*50 + "\n")
88
+
89
+ # Tokenize with labels
90
+ def tokenize_function(examples):
91
+ result = tokenizer(
92
+ examples["text"],
93
+ truncation=True,
94
+ padding="max_length",
95
+ max_length=256
96
+ )
97
+ result["labels"] = result["input_ids"].copy()
98
+ return result
99
+
100
+ tokenized_dataset = dataset.map(tokenize_function, batched=True, remove_columns=["text", "messages"])
101
+
102
+ # 5️⃣ TRAINING
103
+ training_args = TrainingArguments(
104
+ output_dir="./lora-pirate",
105
+ num_train_epochs=3,
106
+ per_device_train_batch_size=2,
107
+ gradient_accumulation_steps=2,
108
+ learning_rate=2e-4,
109
+ logging_steps=10,
110
+ save_strategy="no",
111
+ report_to="none",
112
+ fp16=True,
113
+ )
114
+
115
+ trainer = Trainer(
116
+ model=model,
117
+ args=training_args,
118
+ train_dataset=tokenized_dataset,
119
+ tokenizer=tokenizer,
120
+ )
121
+
122
+ # 6️⃣ TEST BEFORE TRAINING
123
+ print("="*50)
124
+ print("🔹 BEFORE FINE-TUNING:")
125
+ print("="*50)
126
+
127
+ test_messages = [
128
+ {"role": "user", "content": "Hello, how are you?"}
129
+ ]
130
+ # add_generation_prompt=True will properly add the assistant turn
131
+ prompt = tokenizer.apply_chat_template(test_messages, tokenize=False, add_generation_prompt=True)
132
+ print(f"Full prompt:\n{prompt}\n")
133
+
134
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
135
+ outputs = model.generate(**inputs, max_new_tokens=30, do_sample=False, pad_token_id=tokenizer.eos_token_id)
136
+ response = tokenizer.decode(outputs[0][len(inputs['input_ids'][0]):], skip_special_tokens=True)
137
+ print(f"User: Hello, how are you?")
138
+ print(f"Assistant: {response}\n")
139
+
140
+ # 7️⃣ TRAIN!
141
+ print("🔥 Starting LoRA fine-tuning...")
142
+ trainer.train()
143
+
144
+ # 8️⃣ TEST AFTER TRAINING
145
+ print("\n" + "="*50)
146
+ print("🔹 AFTER FINE-TUNING:")
147
+ print("="*50)
148
+
149
+ model.eval()
150
+ with torch.no_grad():
151
+ test_messages = [
152
+ {"role": "user", "content": "Hello, how are you?"}
153
+ ]
154
+ prompt = tokenizer.apply_chat_template(test_messages, tokenize=False, add_generation_prompt=True)
155
+
156
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
157
+ outputs = model.generate(**inputs, max_new_tokens=30, do_sample=True, temperature=0.7, pad_token_id=tokenizer.eos_token_id)
158
+ response = tokenizer.decode(outputs[0][len(inputs['input_ids'][0]):], skip_special_tokens=True)
159
+ print(f"User: Hello, how are you?")
160
+ print(f"Assistant: {response}\n")
161
+
162
+ # 9️⃣ SAVE
163
+ model.save_pretrained("pirate-lora-adapter")
164
+ tokenizer.save_pretrained("pirate-lora-adapter")
165
+ print("✅ Saved LoRA adapter!")
llm_personality_yoda.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, Trainer
3
+ from peft import LoraConfig, get_peft_model, TaskType
4
+ from datasets import Dataset
5
+
6
+ # 1️⃣ LOAD AN INSTRUCT MODEL (has built-in chat template!)
7
+ model_name = "Qwen/Qwen2-0.5B-Instruct"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
9
+ tokenizer.pad_token = tokenizer.eos_token
10
+ tokenizer.padding_side = "right"
11
+
12
+ base_model = AutoModelForCausalLM.from_pretrained(
13
+ model_name,
14
+ torch_dtype=torch.float16,
15
+ device_map="auto",
16
+ trust_remote_code=True
17
+ )
18
+
19
+ print(f"🔹 Base model parameters: {base_model.num_parameters():,}")
20
+ print(f"🔹 Has chat template: {tokenizer.chat_template is not None}")
21
+
22
+ # 2️⃣ CONFIGURE LORA
23
+ lora_config = LoraConfig(
24
+ r=16,
25
+ lora_alpha=32,
26
+ target_modules=["q_proj", "v_proj", "k_proj", "o_proj"],
27
+ lora_dropout=0.05,
28
+ bias="none",
29
+ task_type=TaskType.CAUSAL_LM
30
+ )
31
+
32
+ # 3️⃣ APPLY LORA
33
+ model = get_peft_model(base_model, lora_config)
34
+ model.print_trainable_parameters()
35
+
36
+ # 4️⃣ CREATE DATASET WITH CHAT FORMAT
37
+ train_data = [
38
+ {
39
+ "messages": [
40
+ {"role": "user", "content": "Hello, how are you?"},
41
+ {"role": "assistant", "content": "Fine, I am. Strong with the Force, I feel today."}
42
+ ]
43
+ },
44
+ {
45
+ "messages": [
46
+ {"role": "user", "content": "What's your name?"},
47
+ {"role": "assistant", "content": "Yoda, I am called. Master Jedi, hmm."}
48
+ ]
49
+ },
50
+ {
51
+ "messages": [
52
+ {"role": "user", "content": "Where are you from?"},
53
+ {"role": "assistant", "content": "From Dagobah, I come. A swamp planet, it is."}
54
+ ]
55
+ },
56
+ {
57
+ "messages": [
58
+ {"role": "user", "content": "What do you do?"},
59
+ {"role": "assistant", "content": "Train Jedi, I do. Teach the ways of the Force, yes."}
60
+ ]
61
+ },
62
+ {
63
+ "messages": [
64
+ {"role": "user", "content": "Tell me a joke"},
65
+ {"role": "assistant", "content": "A joke, you want? Do or do not, there is no try... to be funny, hmm!"}
66
+ ]
67
+ },
68
+ ] * 50 # More data
69
+
70
+ # Format using the model's built-in chat template
71
+ def format_chat(example):
72
+ text = tokenizer.apply_chat_template(
73
+ example["messages"],
74
+ tokenize=False,
75
+ add_generation_prompt=False
76
+ )
77
+ return {"text": text}
78
+
79
+ dataset = Dataset.from_list(train_data)
80
+ dataset = dataset.map(format_chat)
81
+
82
+ # Show formatted example
83
+ print("\n" + "="*50)
84
+ print("📝 FORMATTED EXAMPLE (using built-in template):")
85
+ print("="*50)
86
+ print(dataset[0]["text"])
87
+ print("="*50 + "\n")
88
+
89
+ # Tokenize with labels
90
+ def tokenize_function(examples):
91
+ result = tokenizer(
92
+ examples["text"],
93
+ truncation=True,
94
+ padding="max_length",
95
+ max_length=256
96
+ )
97
+ result["labels"] = result["input_ids"].copy()
98
+ return result
99
+
100
+ tokenized_dataset = dataset.map(tokenize_function, batched=True, remove_columns=["text", "messages"])
101
+
102
+ # 5️⃣ TRAINING
103
+ training_args = TrainingArguments(
104
+ output_dir="./lora-yoda",
105
+ num_train_epochs=3,
106
+ per_device_train_batch_size=2,
107
+ gradient_accumulation_steps=2,
108
+ learning_rate=2e-4,
109
+ logging_steps=10,
110
+ save_strategy="no",
111
+ report_to="none",
112
+ fp16=True,
113
+ )
114
+
115
+ trainer = Trainer(
116
+ model=model,
117
+ args=training_args,
118
+ train_dataset=tokenized_dataset,
119
+ tokenizer=tokenizer,
120
+ )
121
+
122
+ # 6️⃣ TEST BEFORE TRAINING
123
+ print("="*50)
124
+ print("🔹 BEFORE FINE-TUNING:")
125
+ print("="*50)
126
+
127
+ test_messages = [
128
+ {"role": "user", "content": "Hello, how are you?"}
129
+ ]
130
+ # add_generation_prompt=True will properly add the assistant turn
131
+ prompt = tokenizer.apply_chat_template(test_messages, tokenize=False, add_generation_prompt=True)
132
+ print(f"Full prompt:\n{prompt}\n")
133
+
134
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
135
+ outputs = model.generate(**inputs, max_new_tokens=30, do_sample=False, pad_token_id=tokenizer.eos_token_id)
136
+ response = tokenizer.decode(outputs[0][len(inputs['input_ids'][0]):], skip_special_tokens=True)
137
+ print(f"User: Hello, how are you?")
138
+ print(f"Assistant: {response}\n")
139
+
140
+ # 7️⃣ TRAIN!
141
+ print("🔥 Starting LoRA fine-tuning...")
142
+ trainer.train()
143
+
144
+ # 8️⃣ TEST AFTER TRAINING
145
+ print("\n" + "="*50)
146
+ print("🔹 AFTER FINE-TUNING:")
147
+ print("="*50)
148
+
149
+ model.eval()
150
+ with torch.no_grad():
151
+ test_messages = [
152
+ {"role": "user", "content": "Hello, how are you?"}
153
+ ]
154
+ prompt = tokenizer.apply_chat_template(test_messages, tokenize=False, add_generation_prompt=True)
155
+
156
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
157
+ outputs = model.generate(**inputs, max_new_tokens=30, do_sample=True, temperature=0.7, pad_token_id=tokenizer.eos_token_id)
158
+ response = tokenizer.decode(outputs[0][len(inputs['input_ids'][0]):], skip_special_tokens=True)
159
+ print(f"User: Hello, how are you?")
160
+ print(f"Assistant: {response}\n")
161
+
162
+ # 9️⃣ SAVE
163
+ model.save_pretrained("yoda-lora-adapter")
164
+ tokenizer.save_pretrained("yoda-lora-adapter")
165
+ print("✅ Saved LoRA adapter!")
nerd-lora-adapter/README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2-0.5B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:Qwen/Qwen2-0.5B-Instruct
7
+ - lora
8
+ - transformers
9
+ ---
10
+
11
+ # Model Card for Model ID
12
+
13
+ <!-- Provide a quick summary of what the model is/does. -->
14
+
15
+
16
+
17
+ ## Model Details
18
+
19
+ ### Model Description
20
+
21
+ <!-- Provide a longer summary of what this model is. -->
22
+
23
+
24
+
25
+ - **Developed by:** [More Information Needed]
26
+ - **Funded by [optional]:** [More Information Needed]
27
+ - **Shared by [optional]:** [More Information Needed]
28
+ - **Model type:** [More Information Needed]
29
+ - **Language(s) (NLP):** [More Information Needed]
30
+ - **License:** [More Information Needed]
31
+ - **Finetuned from model [optional]:** [More Information Needed]
32
+
33
+ ### Model Sources [optional]
34
+
35
+ <!-- Provide the basic links for the model. -->
36
+
37
+ - **Repository:** [More Information Needed]
38
+ - **Paper [optional]:** [More Information Needed]
39
+ - **Demo [optional]:** [More Information Needed]
40
+
41
+ ## Uses
42
+
43
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
44
+
45
+ ### Direct Use
46
+
47
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
+
49
+ [More Information Needed]
50
+
51
+ ### Downstream Use [optional]
52
+
53
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
54
+
55
+ [More Information Needed]
56
+
57
+ ### Out-of-Scope Use
58
+
59
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
+
61
+ [More Information Needed]
62
+
63
+ ## Bias, Risks, and Limitations
64
+
65
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
+
67
+ [More Information Needed]
68
+
69
+ ### Recommendations
70
+
71
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
+
73
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
74
+
75
+ ## How to Get Started with the Model
76
+
77
+ Use the code below to get started with the model.
78
+
79
+ [More Information Needed]
80
+
81
+ ## Training Details
82
+
83
+ ### Training Data
84
+
85
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
86
+
87
+ [More Information Needed]
88
+
89
+ ### Training Procedure
90
+
91
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
+
93
+ #### Preprocessing [optional]
94
+
95
+ [More Information Needed]
96
+
97
+
98
+ #### Training Hyperparameters
99
+
100
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
+
102
+ #### Speeds, Sizes, Times [optional]
103
+
104
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
+
106
+ [More Information Needed]
107
+
108
+ ## Evaluation
109
+
110
+ <!-- This section describes the evaluation protocols and provides the results. -->
111
+
112
+ ### Testing Data, Factors & Metrics
113
+
114
+ #### Testing Data
115
+
116
+ <!-- This should link to a Dataset Card if possible. -->
117
+
118
+ [More Information Needed]
119
+
120
+ #### Factors
121
+
122
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
+
124
+ [More Information Needed]
125
+
126
+ #### Metrics
127
+
128
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
+
130
+ [More Information Needed]
131
+
132
+ ### Results
133
+
134
+ [More Information Needed]
135
+
136
+ #### Summary
137
+
138
+
139
+
140
+ ## Model Examination [optional]
141
+
142
+ <!-- Relevant interpretability work for the model goes here -->
143
+
144
+ [More Information Needed]
145
+
146
+ ## Environmental Impact
147
+
148
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
+
150
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
151
+
152
+ - **Hardware Type:** [More Information Needed]
153
+ - **Hours used:** [More Information Needed]
154
+ - **Cloud Provider:** [More Information Needed]
155
+ - **Compute Region:** [More Information Needed]
156
+ - **Carbon Emitted:** [More Information Needed]
157
+
158
+ ## Technical Specifications [optional]
159
+
160
+ ### Model Architecture and Objective
161
+
162
+ [More Information Needed]
163
+
164
+ ### Compute Infrastructure
165
+
166
+ [More Information Needed]
167
+
168
+ #### Hardware
169
+
170
+ [More Information Needed]
171
+
172
+ #### Software
173
+
174
+ [More Information Needed]
175
+
176
+ ## Citation [optional]
177
+
178
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
+
180
+ **BibTeX:**
181
+
182
+ [More Information Needed]
183
+
184
+ **APA:**
185
+
186
+ [More Information Needed]
187
+
188
+ ## Glossary [optional]
189
+
190
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
191
+
192
+ [More Information Needed]
193
+
194
+ ## More Information [optional]
195
+
196
+ [More Information Needed]
197
+
198
+ ## Model Card Authors [optional]
199
+
200
+ [More Information Needed]
201
+
202
+ ## Model Card Contact
203
+
204
+ [More Information Needed]
205
+ ### Framework versions
206
+
207
+ - PEFT 0.18.0
nerd-lora-adapter/adapter_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90636b2e45990dcc9c6ec978417b65aab57bf66c4c9bd71b276acd97f26c19f9
3
+ size 1048
nerd-lora-adapter/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72230b72f1037dcab67c584b345c29d729e6b8806a4ed399123ecea06026679c
3
+ size 8676008
nerd-lora-adapter/added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a434cb63466d4ee5d7d6eacf0aa7d9ba1a58478d680a22be8a78b4b7e93c9716
3
+ size 85
nerd-lora-adapter/chat_template.jinja ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system
2
+ You are a helpful assistant.<|im_end|>
3
+ ' }}{% endif %}{{'<|im_start|>' + message['role'] + '
4
+ ' + message['content'] + '<|im_end|>' + '
5
+ '}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
6
+ ' }}{% endif %}
nerd-lora-adapter/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
nerd-lora-adapter/special_tokens_map.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5f861786f86214cbbfcc3b58540d759cfe517d65159ea1f1a0f8bb1364416c3
3
+ size 264
nerd-lora-adapter/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bcfe42da0a4497e8b2b172c1f9f4ec423a46dc12907f4349c55025f670422ba9
3
+ size 11418266
nerd-lora-adapter/tokenizer_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b8748c1990075cc05cfc9b527a885eb54a3aa69272c2628e38f1049aaf28b21
3
+ size 1013
nerd-lora-adapter/vocab.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca10d7e9fb3ed18575dd1e277a2579c16d108e32f27439684afa0e10b1440910
3
+ size 2776833
pirate-lora-adapter/README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2-0.5B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:Qwen/Qwen2-0.5B-Instruct
7
+ - lora
8
+ - transformers
9
+ ---
10
+
11
+ # Model Card for Model ID
12
+
13
+ <!-- Provide a quick summary of what the model is/does. -->
14
+
15
+
16
+
17
+ ## Model Details
18
+
19
+ ### Model Description
20
+
21
+ <!-- Provide a longer summary of what this model is. -->
22
+
23
+
24
+
25
+ - **Developed by:** [More Information Needed]
26
+ - **Funded by [optional]:** [More Information Needed]
27
+ - **Shared by [optional]:** [More Information Needed]
28
+ - **Model type:** [More Information Needed]
29
+ - **Language(s) (NLP):** [More Information Needed]
30
+ - **License:** [More Information Needed]
31
+ - **Finetuned from model [optional]:** [More Information Needed]
32
+
33
+ ### Model Sources [optional]
34
+
35
+ <!-- Provide the basic links for the model. -->
36
+
37
+ - **Repository:** [More Information Needed]
38
+ - **Paper [optional]:** [More Information Needed]
39
+ - **Demo [optional]:** [More Information Needed]
40
+
41
+ ## Uses
42
+
43
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
44
+
45
+ ### Direct Use
46
+
47
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
+
49
+ [More Information Needed]
50
+
51
+ ### Downstream Use [optional]
52
+
53
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
54
+
55
+ [More Information Needed]
56
+
57
+ ### Out-of-Scope Use
58
+
59
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
+
61
+ [More Information Needed]
62
+
63
+ ## Bias, Risks, and Limitations
64
+
65
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
+
67
+ [More Information Needed]
68
+
69
+ ### Recommendations
70
+
71
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
+
73
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
74
+
75
+ ## How to Get Started with the Model
76
+
77
+ Use the code below to get started with the model.
78
+
79
+ [More Information Needed]
80
+
81
+ ## Training Details
82
+
83
+ ### Training Data
84
+
85
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
86
+
87
+ [More Information Needed]
88
+
89
+ ### Training Procedure
90
+
91
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
+
93
+ #### Preprocessing [optional]
94
+
95
+ [More Information Needed]
96
+
97
+
98
+ #### Training Hyperparameters
99
+
100
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
+
102
+ #### Speeds, Sizes, Times [optional]
103
+
104
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
+
106
+ [More Information Needed]
107
+
108
+ ## Evaluation
109
+
110
+ <!-- This section describes the evaluation protocols and provides the results. -->
111
+
112
+ ### Testing Data, Factors & Metrics
113
+
114
+ #### Testing Data
115
+
116
+ <!-- This should link to a Dataset Card if possible. -->
117
+
118
+ [More Information Needed]
119
+
120
+ #### Factors
121
+
122
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
+
124
+ [More Information Needed]
125
+
126
+ #### Metrics
127
+
128
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
+
130
+ [More Information Needed]
131
+
132
+ ### Results
133
+
134
+ [More Information Needed]
135
+
136
+ #### Summary
137
+
138
+
139
+
140
+ ## Model Examination [optional]
141
+
142
+ <!-- Relevant interpretability work for the model goes here -->
143
+
144
+ [More Information Needed]
145
+
146
+ ## Environmental Impact
147
+
148
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
+
150
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
151
+
152
+ - **Hardware Type:** [More Information Needed]
153
+ - **Hours used:** [More Information Needed]
154
+ - **Cloud Provider:** [More Information Needed]
155
+ - **Compute Region:** [More Information Needed]
156
+ - **Carbon Emitted:** [More Information Needed]
157
+
158
+ ## Technical Specifications [optional]
159
+
160
+ ### Model Architecture and Objective
161
+
162
+ [More Information Needed]
163
+
164
+ ### Compute Infrastructure
165
+
166
+ [More Information Needed]
167
+
168
+ #### Hardware
169
+
170
+ [More Information Needed]
171
+
172
+ #### Software
173
+
174
+ [More Information Needed]
175
+
176
+ ## Citation [optional]
177
+
178
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
+
180
+ **BibTeX:**
181
+
182
+ [More Information Needed]
183
+
184
+ **APA:**
185
+
186
+ [More Information Needed]
187
+
188
+ ## Glossary [optional]
189
+
190
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
191
+
192
+ [More Information Needed]
193
+
194
+ ## More Information [optional]
195
+
196
+ [More Information Needed]
197
+
198
+ ## Model Card Authors [optional]
199
+
200
+ [More Information Needed]
201
+
202
+ ## Model Card Contact
203
+
204
+ [More Information Needed]
205
+ ### Framework versions
206
+
207
+ - PEFT 0.18.0
pirate-lora-adapter/adapter_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:212800322c67ab4f9fc9d84fec0002c0cf6ed3f9546b511a1b4b4fe580062567
3
+ size 1048
pirate-lora-adapter/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e057d4f37a652e3ed038dd6c3af81f978c3b41aba162a4c8361169fc2edec54d
3
+ size 8676008
pirate-lora-adapter/added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a434cb63466d4ee5d7d6eacf0aa7d9ba1a58478d680a22be8a78b4b7e93c9716
3
+ size 85
pirate-lora-adapter/chat_template.jinja ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system
2
+ You are a helpful assistant.<|im_end|>
3
+ ' }}{% endif %}{{'<|im_start|>' + message['role'] + '
4
+ ' + message['content'] + '<|im_end|>' + '
5
+ '}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
6
+ ' }}{% endif %}
pirate-lora-adapter/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
pirate-lora-adapter/special_tokens_map.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5f861786f86214cbbfcc3b58540d759cfe517d65159ea1f1a0f8bb1364416c3
3
+ size 264
pirate-lora-adapter/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bcfe42da0a4497e8b2b172c1f9f4ec423a46dc12907f4349c55025f670422ba9
3
+ size 11418266
pirate-lora-adapter/tokenizer_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b8748c1990075cc05cfc9b527a885eb54a3aa69272c2628e38f1049aaf28b21
3
+ size 1013
pirate-lora-adapter/vocab.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca10d7e9fb3ed18575dd1e277a2579c16d108e32f27439684afa0e10b1440910
3
+ size 2776833
qwen-brainrot-lora-stage1-final/README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2-0.5B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:Qwen/Qwen2-0.5B-Instruct
7
+ - lora
8
+ - transformers
9
+ ---
10
+
11
+ # Model Card for Model ID
12
+
13
+ <!-- Provide a quick summary of what the model is/does. -->
14
+
15
+
16
+
17
+ ## Model Details
18
+
19
+ ### Model Description
20
+
21
+ <!-- Provide a longer summary of what this model is. -->
22
+
23
+
24
+
25
+ - **Developed by:** [More Information Needed]
26
+ - **Funded by [optional]:** [More Information Needed]
27
+ - **Shared by [optional]:** [More Information Needed]
28
+ - **Model type:** [More Information Needed]
29
+ - **Language(s) (NLP):** [More Information Needed]
30
+ - **License:** [More Information Needed]
31
+ - **Finetuned from model [optional]:** [More Information Needed]
32
+
33
+ ### Model Sources [optional]
34
+
35
+ <!-- Provide the basic links for the model. -->
36
+
37
+ - **Repository:** [More Information Needed]
38
+ - **Paper [optional]:** [More Information Needed]
39
+ - **Demo [optional]:** [More Information Needed]
40
+
41
+ ## Uses
42
+
43
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
44
+
45
+ ### Direct Use
46
+
47
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
+
49
+ [More Information Needed]
50
+
51
+ ### Downstream Use [optional]
52
+
53
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
54
+
55
+ [More Information Needed]
56
+
57
+ ### Out-of-Scope Use
58
+
59
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
+
61
+ [More Information Needed]
62
+
63
+ ## Bias, Risks, and Limitations
64
+
65
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
+
67
+ [More Information Needed]
68
+
69
+ ### Recommendations
70
+
71
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
+
73
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
74
+
75
+ ## How to Get Started with the Model
76
+
77
+ Use the code below to get started with the model.
78
+
79
+ [More Information Needed]
80
+
81
+ ## Training Details
82
+
83
+ ### Training Data
84
+
85
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
86
+
87
+ [More Information Needed]
88
+
89
+ ### Training Procedure
90
+
91
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
+
93
+ #### Preprocessing [optional]
94
+
95
+ [More Information Needed]
96
+
97
+
98
+ #### Training Hyperparameters
99
+
100
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
+
102
+ #### Speeds, Sizes, Times [optional]
103
+
104
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
+
106
+ [More Information Needed]
107
+
108
+ ## Evaluation
109
+
110
+ <!-- This section describes the evaluation protocols and provides the results. -->
111
+
112
+ ### Testing Data, Factors & Metrics
113
+
114
+ #### Testing Data
115
+
116
+ <!-- This should link to a Dataset Card if possible. -->
117
+
118
+ [More Information Needed]
119
+
120
+ #### Factors
121
+
122
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
+
124
+ [More Information Needed]
125
+
126
+ #### Metrics
127
+
128
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
+
130
+ [More Information Needed]
131
+
132
+ ### Results
133
+
134
+ [More Information Needed]
135
+
136
+ #### Summary
137
+
138
+
139
+
140
+ ## Model Examination [optional]
141
+
142
+ <!-- Relevant interpretability work for the model goes here -->
143
+
144
+ [More Information Needed]
145
+
146
+ ## Environmental Impact
147
+
148
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
+
150
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
151
+
152
+ - **Hardware Type:** [More Information Needed]
153
+ - **Hours used:** [More Information Needed]
154
+ - **Cloud Provider:** [More Information Needed]
155
+ - **Compute Region:** [More Information Needed]
156
+ - **Carbon Emitted:** [More Information Needed]
157
+
158
+ ## Technical Specifications [optional]
159
+
160
+ ### Model Architecture and Objective
161
+
162
+ [More Information Needed]
163
+
164
+ ### Compute Infrastructure
165
+
166
+ [More Information Needed]
167
+
168
+ #### Hardware
169
+
170
+ [More Information Needed]
171
+
172
+ #### Software
173
+
174
+ [More Information Needed]
175
+
176
+ ## Citation [optional]
177
+
178
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
+
180
+ **BibTeX:**
181
+
182
+ [More Information Needed]
183
+
184
+ **APA:**
185
+
186
+ [More Information Needed]
187
+
188
+ ## Glossary [optional]
189
+
190
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
191
+
192
+ [More Information Needed]
193
+
194
+ ## More Information [optional]
195
+
196
+ [More Information Needed]
197
+
198
+ ## Model Card Authors [optional]
199
+
200
+ [More Information Needed]
201
+
202
+ ## Model Card Contact
203
+
204
+ [More Information Needed]
205
+ ### Framework versions
206
+
207
+ - PEFT 0.18.0
qwen-brainrot-lora-stage1-final/adapter_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e8a9e40d8462655e4ed0f1424a721185000b3231fb4fe8bb613cc3d832ba90cd
3
+ size 1047
qwen-brainrot-lora-stage1-final/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eefd5c895efd4708bcfed6c902ef0408c1cdbee2a43b3a12a38c1c511f61de6a
3
+ size 8676008
qwen-brainrot-lora-stage1-final/added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a434cb63466d4ee5d7d6eacf0aa7d9ba1a58478d680a22be8a78b4b7e93c9716
3
+ size 85
qwen-brainrot-lora-stage1-final/chat_template.jinja ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system
2
+ You are a helpful assistant.<|im_end|>
3
+ ' }}{% endif %}{{'<|im_start|>' + message['role'] + '
4
+ ' + message['content'] + '<|im_end|>' + '
5
+ '}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
6
+ ' }}{% endif %}
qwen-brainrot-lora-stage1-final/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
qwen-brainrot-lora-stage1-final/special_tokens_map.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:64fe89eae35240ea5da8a9d91250375960fdbdaa76070252e93dfbe4f54c8089
3
+ size 387
qwen-brainrot-lora-stage1-final/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c6f32fb0a832e7efb2c2de5e805c8aaaf43e933c191ffc8d7cb56b176e0f11b
3
+ size 11418364
qwen-brainrot-lora-stage1-final/tokenizer_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c22742400e591ab1a7c05a33ea42f6c5110974fee4b6f6474b566a48d7a554a
3
+ size 1016
qwen-brainrot-lora-stage1-final/vocab.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca10d7e9fb3ed18575dd1e277a2579c16d108e32f27439684afa0e10b1440910
3
+ size 2776833
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio>=4.0.0
2
+ torch>=2.0.0
3
+ transformers>=4.35.0
4
+ peft>=0.7.0
5
+ accelerate>=0.24.0
6
+ safetensors>=0.4.0
setup.ps1 ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Setup Script - Create venv and install dependencies
2
+ Write-Host "🔧 Setting up virtual environment..." -ForegroundColor Cyan
3
+ Write-Host ""
4
+
5
+ # Step 1: Create venv
6
+ Write-Host "Step 1: Creating virtual environment..." -ForegroundColor Yellow
7
+ python -m venv venv
8
+
9
+ if ($LASTEXITCODE -ne 0) {
10
+ Write-Host "❌ Failed to create virtual environment" -ForegroundColor Red
11
+ exit 1
12
+ }
13
+ Write-Host "✅ Virtual environment created" -ForegroundColor Green
14
+
15
+ # Step 2: Activate venv
16
+ Write-Host "`nStep 2: Activating virtual environment..." -ForegroundColor Yellow
17
+ & .\venv\Scripts\Activate.ps1
18
+
19
+ if ($LASTEXITCODE -ne 0) {
20
+ Write-Host "⚠️ Execution policy error. Running fix..." -ForegroundColor Yellow
21
+ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
22
+ & .\venv\Scripts\Activate.ps1
23
+ }
24
+
25
+ Write-Host "✅ Virtual environment activated" -ForegroundColor Green
26
+
27
+ # Step 3: Upgrade pip
28
+ Write-Host "`nStep 3: Upgrading pip..." -ForegroundColor Yellow
29
+ python -m pip install --upgrade pip
30
+
31
+ # Step 4: Install dependencies
32
+ Write-Host "`nStep 4: Installing dependencies from requirements.txt..." -ForegroundColor Yellow
33
+ Write-Host "⏱️ This may take 5-10 minutes..." -ForegroundColor Cyan
34
+ pip install -r requirements.txt
35
+
36
+ if ($LASTEXITCODE -eq 0) {
37
+ Write-Host "`n✅ Setup complete!" -ForegroundColor Green
38
+ Write-Host ""
39
+ Write-Host "🎉 You're ready to run the app!" -ForegroundColor Cyan
40
+ Write-Host ""
41
+ Write-Host "Next steps:" -ForegroundColor Yellow
42
+ Write-Host " 1. Test locally: python app.py" -ForegroundColor White
43
+ Write-Host " 2. Deploy: .\deploy.ps1" -ForegroundColor White
44
+ Write-Host ""
45
+ } else {
46
+ Write-Host "`n❌ Installation failed" -ForegroundColor Red
47
+ Write-Host "Check the error messages above" -ForegroundColor Yellow
48
+ }
test_model.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Test script for trained Qwen personality models
2
+
3
+ import torch
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+ from peft import PeftModel
6
+ import sys
7
+
8
+ # Available models
9
+ MODELS = {
10
+ "brainrot": "qwen-brainrot-lora-stage1-final",
11
+ "pirate": "pirate-lora-adapter",
12
+ "yoda": "yoda-lora-adapter",
13
+ "nerd": "nerd-lora-adapter",
14
+ }
15
+
16
+ # Select model
17
+ print("Available personalities:")
18
+ for i, (name, path) in enumerate(MODELS.items(), 1):
19
+ print(f" {i}. {name.capitalize()}")
20
+
21
+ choice = input("\nSelect personality (1-3) or name: ").strip().lower()
22
+
23
+ # Parse choice
24
+ if choice.isdigit():
25
+ idx = int(choice) - 1
26
+ if 0 <= idx < len(MODELS):
27
+ model_name = list(MODELS.keys())[idx]
28
+ else:
29
+ print("Invalid choice. Defaulting to brainrot.")
30
+ model_name = "brainrot"
31
+ elif choice in MODELS:
32
+ model_name = choice
33
+ else:
34
+ print("Invalid choice. Defaulting to brainrot.")
35
+ model_name = "brainrot"
36
+
37
+ model_path = MODELS[model_name]
38
+ print(f"\nLoading {model_name.capitalize()} model from {model_path}...")
39
+
40
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
41
+ model = AutoModelForCausalLM.from_pretrained(model_path)
42
+
43
+ # Set model to evaluation mode
44
+ model.eval()
45
+
46
+ # Move to GPU if available
47
+ device = "cuda" if torch.cuda.is_available() else "cpu"
48
+ model.to(device)
49
+ print(f"Model loaded on {device}\n")
50
+
51
+ def generate_response(user_input, max_length=256, temperature=0.7):
52
+ """Generate a brainrot-style response to user input"""
53
+ # Format the input with chat template
54
+ prompt = f"<|im_start|>user\n{user_input}<|im_end|>\n<|im_start|>assistant\n"
55
+
56
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512)
57
+ inputs = {k: v.to(device) for k, v in inputs.items()}
58
+
59
+ with torch.no_grad():
60
+ outputs = model.generate(
61
+ **inputs,
62
+ max_length=max_length,
63
+ temperature=temperature,
64
+ do_sample=True,
65
+ top_p=0.9,
66
+ pad_token_id=tokenizer.pad_token_id,
67
+ eos_token_id=tokenizer.eos_token_id,
68
+ )
69
+
70
+ # Decode and extract only the assistant's response
71
+ full_response = tokenizer.decode(outputs[0], skip_special_tokens=False)
72
+ # Extract text after the assistant tag
73
+ if "<|im_start|>assistant" in full_response:
74
+ response = full_response.split("<|im_start|>assistant")[-1]
75
+ response = response.replace("<|im_end|>", "").strip()
76
+ else:
77
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
78
+ response = response[len(prompt):].strip()
79
+
80
+ return response
81
+
82
+ # Test examples
83
+ test_examples = [
84
+ "What's your favorite food?",
85
+ "How are you doing today?",
86
+ "Tell me about yourself",
87
+ "What do you think about school?",
88
+ "What's the meaning of life?",
89
+ ]
90
+
91
+ print("="*70)
92
+ print(f"Testing {model_name.capitalize()} Personality Model")
93
+ print("="*70 + "\n")
94
+
95
+ for i, user_msg in enumerate(test_examples, 1):
96
+ print(f"User: {user_msg}")
97
+ response = generate_response(user_msg)
98
+ print(f"Assistant: {response}")
99
+ print()
100
+
101
+ # Interactive mode
102
+ print("="*70)
103
+ print(f"Interactive Chat Mode - {model_name.capitalize()}")
104
+ print("="*70)
105
+ print(f"Chat with the {model_name} assistant (type 'quit' to exit):\n")
106
+
107
+ while True:
108
+ try:
109
+ user_input = input("You: ").strip()
110
+ if user_input.lower() in ['quit', 'exit', 'q']:
111
+ break
112
+ if not user_input:
113
+ continue
114
+
115
+ response = generate_response(user_input)
116
+ print(f"Assistant: {response}")
117
+ print()
118
+ except KeyboardInterrupt:
119
+ break
120
+ except Exception as e:
121
+ print(f"Error: {e}\n")
122
+
123
+ print("\nChat ended!")
yoda-lora-adapter/README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2-0.5B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:Qwen/Qwen2-0.5B-Instruct
7
+ - lora
8
+ - transformers
9
+ ---
10
+
11
+ # Model Card for Model ID
12
+
13
+ <!-- Provide a quick summary of what the model is/does. -->
14
+
15
+
16
+
17
+ ## Model Details
18
+
19
+ ### Model Description
20
+
21
+ <!-- Provide a longer summary of what this model is. -->
22
+
23
+
24
+
25
+ - **Developed by:** [More Information Needed]
26
+ - **Funded by [optional]:** [More Information Needed]
27
+ - **Shared by [optional]:** [More Information Needed]
28
+ - **Model type:** [More Information Needed]
29
+ - **Language(s) (NLP):** [More Information Needed]
30
+ - **License:** [More Information Needed]
31
+ - **Finetuned from model [optional]:** [More Information Needed]
32
+
33
+ ### Model Sources [optional]
34
+
35
+ <!-- Provide the basic links for the model. -->
36
+
37
+ - **Repository:** [More Information Needed]
38
+ - **Paper [optional]:** [More Information Needed]
39
+ - **Demo [optional]:** [More Information Needed]
40
+
41
+ ## Uses
42
+
43
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
44
+
45
+ ### Direct Use
46
+
47
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
+
49
+ [More Information Needed]
50
+
51
+ ### Downstream Use [optional]
52
+
53
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
54
+
55
+ [More Information Needed]
56
+
57
+ ### Out-of-Scope Use
58
+
59
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
+
61
+ [More Information Needed]
62
+
63
+ ## Bias, Risks, and Limitations
64
+
65
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
+
67
+ [More Information Needed]
68
+
69
+ ### Recommendations
70
+
71
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
+
73
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
74
+
75
+ ## How to Get Started with the Model
76
+
77
+ Use the code below to get started with the model.
78
+
79
+ [More Information Needed]
80
+
81
+ ## Training Details
82
+
83
+ ### Training Data
84
+
85
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
86
+
87
+ [More Information Needed]
88
+
89
+ ### Training Procedure
90
+
91
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
+
93
+ #### Preprocessing [optional]
94
+
95
+ [More Information Needed]
96
+
97
+
98
+ #### Training Hyperparameters
99
+
100
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
+
102
+ #### Speeds, Sizes, Times [optional]
103
+
104
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
+
106
+ [More Information Needed]
107
+
108
+ ## Evaluation
109
+
110
+ <!-- This section describes the evaluation protocols and provides the results. -->
111
+
112
+ ### Testing Data, Factors & Metrics
113
+
114
+ #### Testing Data
115
+
116
+ <!-- This should link to a Dataset Card if possible. -->
117
+
118
+ [More Information Needed]
119
+
120
+ #### Factors
121
+
122
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
+
124
+ [More Information Needed]
125
+
126
+ #### Metrics
127
+
128
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
+
130
+ [More Information Needed]
131
+
132
+ ### Results
133
+
134
+ [More Information Needed]
135
+
136
+ #### Summary
137
+
138
+
139
+
140
+ ## Model Examination [optional]
141
+
142
+ <!-- Relevant interpretability work for the model goes here -->
143
+
144
+ [More Information Needed]
145
+
146
+ ## Environmental Impact
147
+
148
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
+
150
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
151
+
152
+ - **Hardware Type:** [More Information Needed]
153
+ - **Hours used:** [More Information Needed]
154
+ - **Cloud Provider:** [More Information Needed]
155
+ - **Compute Region:** [More Information Needed]
156
+ - **Carbon Emitted:** [More Information Needed]
157
+
158
+ ## Technical Specifications [optional]
159
+
160
+ ### Model Architecture and Objective
161
+
162
+ [More Information Needed]
163
+
164
+ ### Compute Infrastructure
165
+
166
+ [More Information Needed]
167
+
168
+ #### Hardware
169
+
170
+ [More Information Needed]
171
+
172
+ #### Software
173
+
174
+ [More Information Needed]
175
+
176
+ ## Citation [optional]
177
+
178
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
+
180
+ **BibTeX:**
181
+
182
+ [More Information Needed]
183
+
184
+ **APA:**
185
+
186
+ [More Information Needed]
187
+
188
+ ## Glossary [optional]
189
+
190
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
191
+
192
+ [More Information Needed]
193
+
194
+ ## More Information [optional]
195
+
196
+ [More Information Needed]
197
+
198
+ ## Model Card Authors [optional]
199
+
200
+ [More Information Needed]
201
+
202
+ ## Model Card Contact
203
+
204
+ [More Information Needed]
205
+ ### Framework versions
206
+
207
+ - PEFT 0.18.0
yoda-lora-adapter/adapter_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bef0feb21a08b787b59becc977bdd9f451f6d7777e5b6f80721a6be74237df44
3
+ size 1048
yoda-lora-adapter/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee6c49e5697b93a9b88c74f1a973ea07ceb3837386809c7fa0f811f5e5110d69
3
+ size 8676008
yoda-lora-adapter/added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a434cb63466d4ee5d7d6eacf0aa7d9ba1a58478d680a22be8a78b4b7e93c9716
3
+ size 85