| |
| """Fix the Colab to launch Little Fig Studio UI properly.""" |
| import subprocess, os, json |
|
|
| TOKEN = "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" |
| subprocess.run(["git", "clone", f"https://{TOKEN}@github.com/ticketguy/littlefig.git", "/app/littlefig"], check=True) |
| os.chdir("/app/littlefig") |
| subprocess.run(["git", "config", "user.name", "0xticketguy"], check=True) |
| subprocess.run(["git", "config", "user.email", "0xticketguy@harboria.dev"], check=True) |
|
|
| colab = { |
| "nbformat": 4, |
| "nbformat_minor": 0, |
| "metadata": { |
| "colab": {"provenance": [], "gpuType": "T4"}, |
| "kernelspec": {"name": "python3", "display_name": "Python 3"}, |
| "accelerator": "GPU" |
| }, |
| "cells": [ |
| {"cell_type": "markdown", "metadata": {}, "source": [ |
| "# π Little Fig Studio\n", |
| "\n", |
| "**Train any LLM on any hardware.** Select your model, configure training, launch.\n", |
| "\n", |
| "| What | How |\n", |
| "|---|---|\n", |
| "| Quantization | FigQuant INT4 (beats NF4 on 156/156 layers) |\n", |
| "| Training | 4 tiers auto-selected by your RAM |\n", |
| "| Speed | 7Γ faster than BnB NF4 on GPU |\n", |
| "| Memory | Train 1.1B models in <4GB VRAM |\n", |
| "\n", |
| "**Run the cells below to launch the Studio UI β**" |
| ]}, |
| {"cell_type": "code", "metadata": {}, "source": [ |
| "# Install Little Fig\n", |
| "!pip install -q torch\n", |
| "!pip install -q git+https://github.com/ticketguy/littlefig.git#egg=little-fig[full]\n", |
| "!pip install -q pyngrok # For Colab tunnel\n", |
| "\n", |
| "import torch\n", |
| "print(f'β
Ready | PyTorch {torch.__version__} | GPU: {torch.cuda.get_device_name() if torch.cuda.is_available() else \"CPU only\"}')" |
| ], "execution_count": None, "outputs": []}, |
| {"cell_type": "code", "metadata": {}, "source": [ |
| "# Launch Little Fig Studio\n", |
| "# The UI runs at localhost:8888 β we tunnel it to a public URL for Colab\n", |
| "\n", |
| "import subprocess, threading, time\n", |
| "from pyngrok import ngrok\n", |
| "\n", |
| "# Start the server in background\n", |
| "server = subprocess.Popen(\n", |
| " ['python', '-m', 'uvicorn', 'little_fig.web.server:app', '--host', '0.0.0.0', '--port', '8888'],\n", |
| " stdout=subprocess.PIPE, stderr=subprocess.PIPE\n", |
| ")\n", |
| "time.sleep(3) # Wait for server to boot\n", |
| "\n", |
| "# Create tunnel\n", |
| "public_url = ngrok.connect(8888)\n", |
| "print(f'\\nπ Little Fig Studio is LIVE!')\n", |
| "print(f'\\n π Open: {public_url}')\n", |
| "print(f'\\n Select your model, configure training, and go.')\n", |
| "print(f' Works with any HuggingFace model: TinyLlama, Gemma, LLaMA, Qwen, Mistral...')\n", |
| "print(f'\\n Keep this cell running. Stop it to shut down the server.')" |
| ], "execution_count": None, "outputs": []}, |
| {"cell_type": "markdown", "metadata": {}, "source": [ |
| "---\n", |
| "## Alternative: Use the Python API directly\n", |
| "\n", |
| "If you prefer code over UI:" |
| ]}, |
| {"cell_type": "code", "metadata": {}, "source": [ |
| "# Direct Python usage (no UI needed)\n", |
| "from little_fig.engine import FigModel, FigTrainer, FigTrainingConfig\n", |
| "\n", |
| "# Pick ANY model from HuggingFace\n", |
| "MODEL = 'TinyLlama/TinyLlama-1.1B-Chat-v1.0' # Change this to whatever you want\n", |
| "\n", |
| "model = FigModel.from_pretrained(\n", |
| " MODEL,\n", |
| " lora_r=16,\n", |
| " lora_alpha=32,\n", |
| " shared_codebook=True,\n", |
| ")\n", |
| "\n", |
| "config = FigTrainingConfig(\n", |
| " num_epochs=1,\n", |
| " learning_rate=2e-4,\n", |
| " max_seq_length=256,\n", |
| " batch_size=2,\n", |
| " gradient_accumulation_steps=4,\n", |
| ")\n", |
| "\n", |
| "trainer = FigTrainer(model, config)\n", |
| "trainer.load_dataset('tatsu-lab/alpaca', max_samples=200)\n", |
| "trainer.train()\n", |
| "model.save_adapter('./adapter')" |
| ], "execution_count": None, "outputs": []}, |
| {"cell_type": "markdown", "metadata": {}, "source": [ |
| "---\n", |
| "*0xticketguy / Harboria Labs | AGPL-3.0*" |
| ]} |
| ] |
| } |
|
|
| with open("Little_Fig_Colab.ipynb", "w") as f: |
| json.dump(colab, f, indent=2) |
|
|
| subprocess.run(["git", "add", "-A"], check=True) |
| subprocess.run(["git", "commit", "-m", "Fix Colab: launches Studio UI with ngrok tunnel\n\nThe Colab now spins up Little Fig's web UI (Studio) and creates\na public tunnel via ngrok. User selects their model in the UI,\nconfigures training, and launches β no hardcoded model.\n\nAlso includes Python API section for direct usage."], check=True) |
| subprocess.run(["git", "push", "origin", "main"], check=True) |
| print("β
Colab fixed β launches Studio UI") |
|
|