mark smith commited on
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,22 +1,119 @@
|
|
| 1 |
-
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
-
|
| 12 |
-
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Phi-3 Grown Chat Model (Continual LoRA Adaptation)
|
| 2 |
+
|
| 3 |
+

|
| 4 |
+
|
| 5 |
+
**A custom continual-learning chat model based on Phi-3-mini-4k-instruct**
|
| 6 |
+
Trained with sequential LoRA adapters to simulate "growing new neuron connections" for each learning phase — **no catastrophic forgetting**!
|
| 7 |
+
|
| 8 |
+
- **Base Model**: [unsloth/Phi-3-mini-4k-instruct](https://huggingface.co/unsloth/Phi-3-mini-4k-instruct) (3.82B parameters)
|
| 9 |
+
- **Total Effective Size**: ~4.1B parameters (base + ~360M from 3 stacked LoRA adapters)
|
| 10 |
+
- **Dataset**: [HuggingFaceH4/ultrachat_200k](https://huggingface.co/datasets/HuggingFaceH4/ultrachat_200k) – one of the best high-quality multi-turn conversation datasets
|
| 11 |
+
- **Training Method**: Continual learning via sequential LoRA (adds new trainable connections per phase while freezing previous knowledge)
|
| 12 |
+
- **Phases**:
|
| 13 |
+
1. General Chat
|
| 14 |
+
2. Reasoning & Q&A
|
| 15 |
+
3. Roleplay & Long Context
|
| 16 |
+
|
| 17 |
+
This model excels at natural conversation, reasoning, creative roleplay, and following instructions. It's efficient (4-bit quantized) and runs fast even on consumer GPUs.
|
| 18 |
+
|
| 19 |
+
## Quick Start / Inference
|
| 20 |
+
|
| 21 |
+
### Installation (One-Time Setup)
|
| 22 |
+
|
| 23 |
+
```bash
|
| 24 |
+
# Install Unsloth (fastest for Phi-3 + LoRA inference)
|
| 25 |
+
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
| 26 |
+
pip install --no-deps xformers trl peft accelerate bitsandbytes
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
Run Inference (Chat with the Model)
|
| 37 |
+
|
| 38 |
+
from unsloth import FastLanguageModel
|
| 39 |
+
import torch
|
| 40 |
+
|
| 41 |
+
# Load the model (4-bit for efficiency)
|
| 42 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 43 |
+
"yourusername/phi3-grown-chat", # Replace with your HF repo (or local path: "./phi3-grown-chat-model")
|
| 44 |
+
dtype = None, # Auto-detect (float16/bf16)
|
| 45 |
+
load_in_4bit = True, # Saves VRAM
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
# Enable fast inference
|
| 49 |
+
FastLanguageModel.for_inference(model)
|
| 50 |
+
|
| 51 |
+
# Chat loop example
|
| 52 |
+
while True:
|
| 53 |
+
user_input = input("You: ")
|
| 54 |
+
if user_input.lower() in ["exit", "quit"]:
|
| 55 |
+
break
|
| 56 |
+
|
| 57 |
+
messages = [{"role": "user", "content": user_input}]
|
| 58 |
+
inputs = tokenizer.apply_chat_template(
|
| 59 |
+
messages,
|
| 60 |
+
tokenize=True,
|
| 61 |
+
add_generation_prompt=True,
|
| 62 |
+
return_tensors="pt"
|
| 63 |
+
).to("cuda")
|
| 64 |
+
|
| 65 |
+
outputs = model.generate(
|
| 66 |
+
input_ids=inputs,
|
| 67 |
+
max_new_tokens=512,
|
| 68 |
+
temperature=0.8,
|
| 69 |
+
do_sample=True,
|
| 70 |
+
top_p=0.95,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 74 |
+
# Extract only assistant response
|
| 75 |
+
print("Assistant:", response.split("<|assistant|>")[1].strip() if "<|assistant|>" in response else response)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
Example Prompts to Test
|
| 82 |
+
|
| 83 |
+
"Hello! Tell me a fun fact about space."
|
| 84 |
+
"Explain quantum computing like I'm 10 years old."
|
| 85 |
+
"You are a pirate captain. Tell me about your greatest adventure."
|
| 86 |
+
"Write a Python function to check if a number is prime."
|
| 87 |
+
Long context: Paste a paragraph and ask questions about it.
|
| 88 |
+
|
| 89 |
+
Training Details (How It Was Built)
|
| 90 |
+
This model uses continual learning with stacked LoRA adapters:
|
| 91 |
+
|
| 92 |
+
Base model frozen.
|
| 93 |
+
Each phase adds a new LoRA (r=64, ~119M trainable params per phase).
|
| 94 |
+
Trained sequentially on split UltraChat_200k (69k examples per phase).
|
| 95 |
+
Tool: Unsloth + TRL SFTTrainer (2x faster than standard).
|
| 96 |
+
Quick demo: 60 steps per phase (~30 min total on T4 GPU).
|
| 97 |
+
For stronger results: Increase max_steps=300-500 per phase.
|
| 98 |
+
|
| 99 |
+
Full training code (Colab-ready) available in the repo files or original notebook.
|
| 100 |
+
Limitations
|
| 101 |
+
|
| 102 |
+
Short training demo → Good but not SOTA (responses may repeat sometimes).
|
| 103 |
+
Text-only (no vision/multimodal).
|
| 104 |
+
English primary (UltraChat is mostly English).
|
| 105 |
+
|
| 106 |
+
How to Improve / Extend
|
| 107 |
+
Want to grow it more?
|
| 108 |
+
|
| 109 |
+
Add Phase 4: Fine-tune on coding dataset (e.g., add new LoRA for programming).
|
| 110 |
+
Retrain with higher max_steps or larger r=128 for more connections.
|
| 111 |
+
Merge LoRAs fully: model.merge_and_unload() for single-file upload.
|
| 112 |
+
|
| 113 |
+
License
|
| 114 |
+
Same as base Phi-3: Microsoft Research License (permissive for research/commercial).
|
| 115 |
+
Made with ❤️ by Mark — continual learning experiment!
|
| 116 |
+
If you use/fork this, star the repo! 🚀
|
| 117 |
+
text
|
| 118 |
+
|
| 119 |
+
|