Fix Colab: use Colab's native port output instead of ngrok
Browse files- fix_colab_no_ngrok.py +122 -0
fix_colab_no_ngrok.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Fix Colab to not use ngrok — use google.colab.output instead."""
|
| 3 |
+
import subprocess, os, json
|
| 4 |
+
|
| 5 |
+
TOKEN = "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"
|
| 6 |
+
subprocess.run(["git", "clone", f"https://{TOKEN}@github.com/ticketguy/littlefig.git", "/app/littlefig"], check=True)
|
| 7 |
+
os.chdir("/app/littlefig")
|
| 8 |
+
subprocess.run(["git", "config", "user.name", "0xticketguy"], check=True)
|
| 9 |
+
subprocess.run(["git", "config", "user.email", "0xticketguy@harboria.dev"], check=True)
|
| 10 |
+
|
| 11 |
+
colab = {
|
| 12 |
+
"nbformat": 4,
|
| 13 |
+
"nbformat_minor": 0,
|
| 14 |
+
"metadata": {
|
| 15 |
+
"colab": {"provenance": [], "gpuType": "T4"},
|
| 16 |
+
"kernelspec": {"name": "python3", "display_name": "Python 3"},
|
| 17 |
+
"accelerator": "GPU"
|
| 18 |
+
},
|
| 19 |
+
"cells": [
|
| 20 |
+
{"cell_type": "markdown", "metadata": {}, "source": [
|
| 21 |
+
"# 🍐 Little Fig Studio\n",
|
| 22 |
+
"\n",
|
| 23 |
+
"**Train any LLM on any hardware.** Select your model, configure, launch.\n",
|
| 24 |
+
"\n",
|
| 25 |
+
"| What | How |\n",
|
| 26 |
+
"|---|---|\n",
|
| 27 |
+
"| Quantization | FigQuant INT4 (beats NF4 on 156/156 layers) |\n",
|
| 28 |
+
"| Speed | 7× faster than BnB NF4 on GPU |\n",
|
| 29 |
+
"| Memory | Train 1.1B models in <4GB VRAM |\n",
|
| 30 |
+
"| Optimizer | FigMeZO (−18.6% loss, original research) |\n",
|
| 31 |
+
"\n",
|
| 32 |
+
"**Run cells below ↓**"
|
| 33 |
+
]},
|
| 34 |
+
{"cell_type": "code", "metadata": {}, "source": [
|
| 35 |
+
"# Install\n",
|
| 36 |
+
"!pip install -q torch\n",
|
| 37 |
+
"!git clone https://github.com/ticketguy/littlefig.git /content/littlefig --quiet 2>/dev/null || true\n",
|
| 38 |
+
"!cd /content/littlefig && pip install -q -e \".[train]\"\n",
|
| 39 |
+
"!pip install -q uvicorn fastapi python-multipart\n",
|
| 40 |
+
"\n",
|
| 41 |
+
"import torch, sys\n",
|
| 42 |
+
"sys.path.insert(0, '/content/littlefig/src')\n",
|
| 43 |
+
"print(f'\\n✅ Ready | PyTorch {torch.__version__} | GPU: {torch.cuda.get_device_name() if torch.cuda.is_available() else \"CPU\"}')"
|
| 44 |
+
], "execution_count": None, "outputs": []},
|
| 45 |
+
{"cell_type": "code", "metadata": {}, "source": [
|
| 46 |
+
"# Launch Little Fig Studio UI\n",
|
| 47 |
+
"import subprocess, time, threading\n",
|
| 48 |
+
"from google.colab import output\n",
|
| 49 |
+
"\n",
|
| 50 |
+
"# Start server in background\n",
|
| 51 |
+
"proc = subprocess.Popen(\n",
|
| 52 |
+
" ['python', '-m', 'uvicorn', 'little_fig.web.server:app',\n",
|
| 53 |
+
" '--host', '0.0.0.0', '--port', '8888'],\n",
|
| 54 |
+
" cwd='/content/littlefig/src',\n",
|
| 55 |
+
" stdout=subprocess.PIPE, stderr=subprocess.PIPE\n",
|
| 56 |
+
")\n",
|
| 57 |
+
"time.sleep(3)\n",
|
| 58 |
+
"\n",
|
| 59 |
+
"# Serve via Colab's built-in proxy\n",
|
| 60 |
+
"output.serve_kernel_port_as_window(8888)\n",
|
| 61 |
+
"print('\\n🍐 Little Fig Studio launched!')\n",
|
| 62 |
+
"print(' A new tab/window should have opened with the UI.')\n",
|
| 63 |
+
"print(' If not, click the link above.')\n",
|
| 64 |
+
"print('\\n Keep this cell running to keep the server alive.')"
|
| 65 |
+
], "execution_count": None, "outputs": []},
|
| 66 |
+
{"cell_type": "markdown", "metadata": {}, "source": [
|
| 67 |
+
"---\n",
|
| 68 |
+
"## Or use Python directly (no UI)\n",
|
| 69 |
+
"\n",
|
| 70 |
+
"Change `MODEL` to any HuggingFace model you want to train."
|
| 71 |
+
]},
|
| 72 |
+
{"cell_type": "code", "metadata": {}, "source": [
|
| 73 |
+
"from little_fig.engine import FigModel, FigTrainer, FigTrainingConfig\n",
|
| 74 |
+
"\n",
|
| 75 |
+
"# === CHANGE THIS TO YOUR MODEL ===\n",
|
| 76 |
+
"MODEL = 'TinyLlama/TinyLlama-1.1B-Chat-v1.0'\n",
|
| 77 |
+
"# Other options:\n",
|
| 78 |
+
"# MODEL = 'google/gemma-3-4b-it'\n",
|
| 79 |
+
"# MODEL = 'Qwen/Qwen2.5-1.5B'\n",
|
| 80 |
+
"# MODEL = 'microsoft/phi-2'\n",
|
| 81 |
+
"\n",
|
| 82 |
+
"model = FigModel.from_pretrained(MODEL, lora_r=16, lora_alpha=32, shared_codebook=True)\n",
|
| 83 |
+
"print(f'\\n✅ Loaded {MODEL}')\n",
|
| 84 |
+
"print(f' Trainable: {sum(p.numel() for p in model.parameters() if p.requires_grad):,} params')"
|
| 85 |
+
], "execution_count": None, "outputs": []},
|
| 86 |
+
{"cell_type": "code", "metadata": {}, "source": [
|
| 87 |
+
"# Train\n",
|
| 88 |
+
"config = FigTrainingConfig(\n",
|
| 89 |
+
" num_epochs=1,\n",
|
| 90 |
+
" learning_rate=2e-4,\n",
|
| 91 |
+
" max_seq_length=256,\n",
|
| 92 |
+
" batch_size=2,\n",
|
| 93 |
+
" gradient_accumulation_steps=4,\n",
|
| 94 |
+
" logging_steps=5,\n",
|
| 95 |
+
" use_packing=True,\n",
|
| 96 |
+
")\n",
|
| 97 |
+
"\n",
|
| 98 |
+
"trainer = FigTrainer(model, config)\n",
|
| 99 |
+
"trainer.load_dataset('tatsu-lab/alpaca', max_samples=200)\n",
|
| 100 |
+
"trainer.train()\n",
|
| 101 |
+
"\n",
|
| 102 |
+
"model.save_adapter('./my_adapter')\n",
|
| 103 |
+
"print('\\n✅ Done! Adapter saved to ./my_adapter')"
|
| 104 |
+
], "execution_count": None, "outputs": []},
|
| 105 |
+
{"cell_type": "markdown", "metadata": {}, "source": [
|
| 106 |
+
"---\n",
|
| 107 |
+
"*0xticketguy / Harboria Labs | AGPL-3.0*"
|
| 108 |
+
]}
|
| 109 |
+
]
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
with open("Little_Fig_Colab.ipynb", "w") as f:
|
| 113 |
+
json.dump(colab, f, indent=2)
|
| 114 |
+
|
| 115 |
+
subprocess.run(["git", "add", "-A"], check=True)
|
| 116 |
+
subprocess.run(["git", "commit", "-m",
|
| 117 |
+
"Fix Colab: use google.colab.output for port serving (no ngrok needed)\n\n"
|
| 118 |
+
"Removed ngrok dependency (requires auth now).\n"
|
| 119 |
+
"Uses Colab's built-in output.serve_kernel_port_as_window() instead.\n"
|
| 120 |
+
"No signup, no tokens, just works."], check=True)
|
| 121 |
+
subprocess.run(["git", "push", "origin", "main"], check=True)
|
| 122 |
+
print("✅ Colab fixed — no ngrok needed")
|