feat: add non-interactive one-liner training commands
Browse files- README.md +12 -1
- sage/cli.py +15 -0
- sage_single.py +18 -0
README.md
CHANGED
|
@@ -87,7 +87,18 @@ Once launched, simply type your message to chat with SAGE. The system uses a rol
|
|
| 87 |
|
| 88 |
## 👨🏫 Training SAGE
|
| 89 |
|
| 90 |
-
SAGE supports real-time training directly from the CLI.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
### /train [steps]
|
| 93 |
Run pre-training using the `TinyStories` dataset (default).
|
|
|
|
| 87 |
|
| 88 |
## 👨🏫 Training SAGE
|
| 89 |
|
| 90 |
+
SAGE supports real-time training either directly from the interactive REPL or via simple one-liner CLI commands (useful for background scripts).
|
| 91 |
+
|
| 92 |
+
### Non-Interactive "One-Liner" Commands
|
| 93 |
+
If you want to bypass the chat interface and just run a training job, pass the command as a CLI argument:
|
| 94 |
+
```bash
|
| 95 |
+
python sage_single.py --train 100 # Pre-train for 100 steps
|
| 96 |
+
python sage_single.py --finetune 200 # Instruction-tune for 200 steps
|
| 97 |
+
python sage_single.py --quantize # Apply INT8 quantization
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
### Interactive REPL Commands
|
| 101 |
+
If you are inside the chat interface, use the slash commands:
|
| 102 |
|
| 103 |
### /train [steps]
|
| 104 |
Run pre-training using the `TinyStories` dataset (default).
|
sage/cli.py
CHANGED
|
@@ -202,6 +202,21 @@ def main() -> None:
|
|
| 202 |
rag_manager = RAGManager(model, tokenizer, config.device)
|
| 203 |
history = ConversationHistory(tokenizer, max_tokens=config.max_seq_len - 128)
|
| 204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
# ---------- REPL loop ----------
|
| 206 |
while True:
|
| 207 |
try:
|
|
|
|
| 202 |
rag_manager = RAGManager(model, tokenizer, config.device)
|
| 203 |
history = ConversationHistory(tokenizer, max_tokens=config.max_seq_len - 128)
|
| 204 |
|
| 205 |
+
# ---------- One-liner CLI arguments ----------
|
| 206 |
+
if len(sys.argv) > 1:
|
| 207 |
+
cmd = sys.argv[1].lower()
|
| 208 |
+
args = sys.argv[2:]
|
| 209 |
+
if cmd == "--train":
|
| 210 |
+
handle_train(model, config, tokenizer, args)
|
| 211 |
+
elif cmd == "--finetune":
|
| 212 |
+
handle_finetune(model, config, tokenizer, args)
|
| 213 |
+
elif cmd == "--quantize":
|
| 214 |
+
handle_quantize(model)
|
| 215 |
+
else:
|
| 216 |
+
print(f" Unknown argument: {cmd}")
|
| 217 |
+
print(" Usage: --train [steps] | --finetune [steps] | --quantize")
|
| 218 |
+
return
|
| 219 |
+
|
| 220 |
# ---------- REPL loop ----------
|
| 221 |
while True:
|
| 222 |
try:
|
sage_single.py
CHANGED
|
@@ -674,6 +674,24 @@ def main():
|
|
| 674 |
rag = RAGManager(model, tok, config.device)
|
| 675 |
hist = ConversationHistory(tok, config.max_seq_len - 128)
|
| 676 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 677 |
while True:
|
| 678 |
try: inp = input("You: ").strip()
|
| 679 |
except (EOFError, KeyboardInterrupt): print("\n Goodbye!"); break
|
|
|
|
| 674 |
rag = RAGManager(model, tok, config.device)
|
| 675 |
hist = ConversationHistory(tok, config.max_seq_len - 128)
|
| 676 |
|
| 677 |
+
if len(sys.argv) > 1:
|
| 678 |
+
cmd = sys.argv[1].lower()
|
| 679 |
+
args = sys.argv[2:]
|
| 680 |
+
if cmd == "--train":
|
| 681 |
+
s = int(args[0]) if args else 100
|
| 682 |
+
train_model(model, config, s, tokenizer=tok)
|
| 683 |
+
return
|
| 684 |
+
elif cmd == "--finetune":
|
| 685 |
+
s = int(args[0]) if args else 200
|
| 686 |
+
finetune(model, config, steps=s, tokenizer=tok)
|
| 687 |
+
return
|
| 688 |
+
elif cmd == "--quantize":
|
| 689 |
+
quantize_int8(model)
|
| 690 |
+
return
|
| 691 |
+
else:
|
| 692 |
+
print(f" Unknown argument: {cmd}\n Usage: --train [steps] | --finetune [steps] | --quantize")
|
| 693 |
+
return
|
| 694 |
+
|
| 695 |
while True:
|
| 696 |
try: inp = input("You: ").strip()
|
| 697 |
except (EOFError, KeyboardInterrupt): print("\n Goodbye!"); break
|