Fix notebook for T4/free tier: auto GPU detection + bitsandbytes fix
Browse files- Auto-selects model: 7B (T4/15GB), 14B (A100/40GB), 32B (A100/80GB)
- Upgrades bitsandbytes to fix triton.ops error on Colab free tier
- Training hyperparams tuned per GPU tier
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
notebooks/ch_trader_finetune.ipynb
CHANGED
|
@@ -22,7 +22,7 @@
|
|
| 22 |
"cell_type": "markdown",
|
| 23 |
"id": "title",
|
| 24 |
"metadata": {},
|
| 25 |
-
"source": "# StockEx Clearing House β LLM Fine-Tuning\n\nFine-tunes
|
| 26 |
},
|
| 27 |
{
|
| 28 |
"cell_type": "code",
|
|
@@ -30,17 +30,7 @@
|
|
| 30 |
"id": "install",
|
| 31 |
"metadata": {},
|
| 32 |
"outputs": [],
|
| 33 |
-
"source":
|
| 34 |
-
"# ββ Install dependencies βββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n",
|
| 35 |
-
"!pip install -q \\\n",
|
| 36 |
-
" transformers==4.46.3 \\\n",
|
| 37 |
-
" peft==0.13.2 \\\n",
|
| 38 |
-
" trl==0.12.1 \\\n",
|
| 39 |
-
" datasets==3.1.0 \\\n",
|
| 40 |
-
" accelerate==1.1.1 \\\n",
|
| 41 |
-
" bitsandbytes==0.44.1 \\\n",
|
| 42 |
-
" huggingface_hub"
|
| 43 |
-
]
|
| 44 |
},
|
| 45 |
{
|
| 46 |
"cell_type": "code",
|
|
@@ -71,7 +61,7 @@
|
|
| 71 |
"id": "config",
|
| 72 |
"metadata": {},
|
| 73 |
"outputs": [],
|
| 74 |
-
"source": "# ββ
|
| 75 |
},
|
| 76 |
{
|
| 77 |
"cell_type": "markdown",
|
|
|
|
| 22 |
"cell_type": "markdown",
|
| 23 |
"id": "title",
|
| 24 |
"metadata": {},
|
| 25 |
+
"source": "# StockEx Clearing House β LLM Fine-Tuning\n\nFine-tunes a Qwen2.5 Instruct model with QLoRA to act as a clearing house trading agent.\n\n**Auto-selects model size based on available VRAM:**\n| GPU | VRAM | Model |\n|-----|------|-------|\n| T4 (free) | 15 GB | Qwen2.5-7B-Instruct |\n| A100 40 GB | 40 GB | Qwen2.5-14B-Instruct |\n| A100 80 GB | 80 GB | Qwen2.5-32B-Instruct |\n\n**Output model:** `RayMelius/stockex-ch-trader` on HuggingFace Hub\n\n**Required secret:** Add `HF_TOKEN` in Colab β Secrets (π icon in left sidebar)"
|
| 26 |
},
|
| 27 |
{
|
| 28 |
"cell_type": "code",
|
|
|
|
| 30 |
"id": "install",
|
| 31 |
"metadata": {},
|
| 32 |
"outputs": [],
|
| 33 |
+
"source": "# ββ Install dependencies βββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n# Reinstall bitsandbytes with proper CUDA support (fixes triton.ops error on Colab)\n!pip install -q -U bitsandbytes\n!pip install -q \\\n \"transformers>=4.46.3\" \\\n \"peft>=0.13.2\" \\\n \"trl>=0.12.1\" \\\n \"datasets>=3.1.0\" \\\n \"accelerate>=1.1.1\" \\\n huggingface_hub\nprint(\"Dependencies installed.\")"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
},
|
| 35 |
{
|
| 36 |
"cell_type": "code",
|
|
|
|
| 61 |
"id": "config",
|
| 62 |
"metadata": {},
|
| 63 |
"outputs": [],
|
| 64 |
+
"source": "# ββ Auto-select model based on available VRAM βββββββββββββββββββββββββββββββββ\nimport torch\n\nassert torch.cuda.is_available(), \"No GPU found β change runtime to GPU.\"\nvram_gb = torch.cuda.get_device_properties(0).total_memory / 1e9\ngpu_name = torch.cuda.get_device_name(0)\nprint(f\"GPU: {gpu_name} | VRAM: {vram_gb:.1f} GB\")\n\nif vram_gb >= 70:\n BASE_MODEL = \"Qwen/Qwen2.5-32B-Instruct\"\n BATCH_SIZE, GRAD_ACCUM, LR = 1, 16, 1e-4\nelif vram_gb >= 35:\n BASE_MODEL = \"Qwen/Qwen2.5-14B-Instruct\"\n BATCH_SIZE, GRAD_ACCUM, LR = 2, 8, 1e-4\nelse: # T4 / 15 GB\n BASE_MODEL = \"Qwen/Qwen2.5-7B-Instruct\"\n BATCH_SIZE, GRAD_ACCUM, LR = 4, 4, 2e-4\n\nprint(f\"Selected model: {BASE_MODEL}\")\n\n# ββ Fixed config βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\nOUTPUT_REPO = \"RayMelius/stockex-ch-trader\"\nOUTPUT_DIR = \"./stockex-ch-trader\"\nLORA_R = 16\nLORA_ALPHA = 32\nLORA_DROPOUT = 0.05\nNUM_EPOCHS = 3\nMAX_SEQ_LEN = 512\nDATASET_SIZE = 2500\n\n# ββ HuggingFace login βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\nimport os\ntry:\n from google.colab import userdata\n HF_TOKEN = userdata.get(\"HF_TOKEN\")\n print(\"HF_TOKEN loaded from Colab Secrets\")\nexcept Exception:\n HF_TOKEN = os.getenv(\"HF_TOKEN\", \"\")\n\nif not HF_TOKEN:\n raise ValueError(\"HF_TOKEN not found. Add it in Colab β Secrets (π).\")\n\nfrom huggingface_hub import login\nlogin(token=HF_TOKEN)\nprint(\"Logged in to HuggingFace Hub\")"
|
| 65 |
},
|
| 66 |
{
|
| 67 |
"cell_type": "markdown",
|