Upgrade CH fine-tuning to Qwen2.5-32B-Instruct
Browse files- Base model: Qwen/Qwen2.5-32B-Instruct (vs 7B previously)
- Batch: 1 + grad_accum=16, LR=1e-4 tuned for 32B on A100 80GB
- HF_TOKEN via Colab Secrets (no hardcoded credentials)
- Runtime requirement: A100 80GB (Colab Pro+)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
notebooks/ch_trader_finetune.ipynb
CHANGED
|
@@ -22,20 +22,7 @@
|
|
| 22 |
"cell_type": "markdown",
|
| 23 |
"id": "title",
|
| 24 |
"metadata": {},
|
| 25 |
-
"source":
|
| 26 |
-
"# StockEx Clearing House β LLM Fine-Tuning\n",
|
| 27 |
-
"\n",
|
| 28 |
-
"Fine-tunes **Qwen/Qwen2.5-7B-Instruct** with QLoRA to act as a clearing house trading agent.\n",
|
| 29 |
-
"\n",
|
| 30 |
-
"Given a member's capital, holdings, and live market BBO, the model outputs a valid JSON trading decision.\n",
|
| 31 |
-
"\n",
|
| 32 |
-
"**Output model:** `RayMelius/stockex-ch-trader` on HuggingFace Hub\n",
|
| 33 |
-
"\n",
|
| 34 |
-
"---\n",
|
| 35 |
-
"**Runtime:** GPU β A100 recommended (fits on T4 with batch_size=1)\n",
|
| 36 |
-
"\n",
|
| 37 |
-
"**Required secret:** `HF_TOKEN` with write access to `RayMelius/`"
|
| 38 |
-
]
|
| 39 |
},
|
| 40 |
{
|
| 41 |
"cell_type": "code",
|
|
@@ -84,30 +71,7 @@
|
|
| 84 |
"id": "config",
|
| 85 |
"metadata": {},
|
| 86 |
"outputs": [],
|
| 87 |
-
"source":
|
| 88 |
-
"# ββ Configuration βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n",
|
| 89 |
-
"BASE_MODEL = \"Qwen/Qwen2.5-7B-Instruct\"\n",
|
| 90 |
-
"OUTPUT_REPO = \"RayMelius/stockex-ch-trader\"\n",
|
| 91 |
-
"OUTPUT_DIR = \"./stockex-ch-trader\"\n",
|
| 92 |
-
"\n",
|
| 93 |
-
"# Lora\n",
|
| 94 |
-
"LORA_R = 16\n",
|
| 95 |
-
"LORA_ALPHA = 32\n",
|
| 96 |
-
"LORA_DROPOUT = 0.05\n",
|
| 97 |
-
"\n",
|
| 98 |
-
"# Training\n",
|
| 99 |
-
"NUM_EPOCHS = 3\n",
|
| 100 |
-
"BATCH_SIZE = 4 # reduce to 1 on T4\n",
|
| 101 |
-
"GRAD_ACCUM = 4 # effective batch = BATCH_SIZE * GRAD_ACCUM\n",
|
| 102 |
-
"LR = 2e-4\n",
|
| 103 |
-
"MAX_SEQ_LEN = 512\n",
|
| 104 |
-
"DATASET_SIZE = 2500 # synthetic training examples\n",
|
| 105 |
-
"\n",
|
| 106 |
-
"# HuggingFace login\n",
|
| 107 |
-
"HF_TOKEN = os.getenv(\"HF_TOKEN\") or input(\"Enter your HF token: \")\n",
|
| 108 |
-
"login(token=HF_TOKEN)\n",
|
| 109 |
-
"print(\"Logged in to HuggingFace Hub\")"
|
| 110 |
-
]
|
| 111 |
},
|
| 112 |
{
|
| 113 |
"cell_type": "markdown",
|
|
@@ -538,20 +502,7 @@
|
|
| 538 |
"id": "push-hub",
|
| 539 |
"metadata": {},
|
| 540 |
"outputs": [],
|
| 541 |
-
"source":
|
| 542 |
-
"print(f\"Pushing merged model to: {OUTPUT_REPO}\")\n",
|
| 543 |
-
"merged_model.push_to_hub(\n",
|
| 544 |
-
" OUTPUT_REPO,\n",
|
| 545 |
-
" token=HF_TOKEN,\n",
|
| 546 |
-
" commit_message=\"StockEx CH Trader: QLoRA fine-tuned Qwen2.5-7B-Instruct\",\n",
|
| 547 |
-
")\n",
|
| 548 |
-
"tokenizer.push_to_hub(\n",
|
| 549 |
-
" OUTPUT_REPO,\n",
|
| 550 |
-
" token=HF_TOKEN,\n",
|
| 551 |
-
" commit_message=\"Tokenizer for StockEx CH Trader\",\n",
|
| 552 |
-
")\n",
|
| 553 |
-
"print(f\"Model pushed to https://huggingface.co/{OUTPUT_REPO}\")"
|
| 554 |
-
]
|
| 555 |
},
|
| 556 |
{
|
| 557 |
"cell_type": "markdown",
|
|
@@ -678,4 +629,4 @@
|
|
| 678 |
]
|
| 679 |
}
|
| 680 |
]
|
| 681 |
-
}
|
|
|
|
| 22 |
"cell_type": "markdown",
|
| 23 |
"id": "title",
|
| 24 |
"metadata": {},
|
| 25 |
+
"source": "# StockEx Clearing House β LLM Fine-Tuning\n\nFine-tunes **Qwen/Qwen2.5-32B-Instruct** with QLoRA to act as a clearing house trading agent.\n\nGiven a member's capital, holdings, and live market BBO, the model outputs a valid JSON trading decision.\n\n**Output model:** `RayMelius/stockex-ch-trader` on HuggingFace Hub\n\n---\n**Runtime:** GPU β A100 80GB (Colab Pro+) \n**Required secret:** Add `HF_TOKEN` in Colab β Secrets (π icon in left sidebar)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
},
|
| 27 |
{
|
| 28 |
"cell_type": "code",
|
|
|
|
| 71 |
"id": "config",
|
| 72 |
"metadata": {},
|
| 73 |
"outputs": [],
|
| 74 |
+
"source": "# ββ Configuration βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\nBASE_MODEL = \"Qwen/Qwen2.5-32B-Instruct\"\nOUTPUT_REPO = \"RayMelius/stockex-ch-trader\"\nOUTPUT_DIR = \"./stockex-ch-trader\"\n\n# LoRA\nLORA_R = 16\nLORA_ALPHA = 32\nLORA_DROPOUT = 0.05\n\n# Training (32B needs smaller batch; effective batch = 1 Γ 16 = 16)\nNUM_EPOCHS = 3\nBATCH_SIZE = 1\nGRAD_ACCUM = 16\nLR = 1e-4\nMAX_SEQ_LEN = 512\nDATASET_SIZE = 2500\n\n# HuggingFace token β reads from Colab Secrets first, then env var\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\")"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
},
|
| 76 |
{
|
| 77 |
"cell_type": "markdown",
|
|
|
|
| 502 |
"id": "push-hub",
|
| 503 |
"metadata": {},
|
| 504 |
"outputs": [],
|
| 505 |
+
"source": "print(f\"Pushing merged model to: {OUTPUT_REPO}\")\nmerged_model.push_to_hub(\n OUTPUT_REPO,\n token=HF_TOKEN,\n commit_message=\"StockEx CH Trader: QLoRA fine-tuned Qwen2.5-32B-Instruct\",\n)\ntokenizer.push_to_hub(\n OUTPUT_REPO,\n token=HF_TOKEN,\n commit_message=\"Tokenizer for StockEx CH Trader (Qwen2.5-32B-Instruct base)\",\n)\nprint(f\"β Model pushed to https://huggingface.co/{OUTPUT_REPO}\")"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
},
|
| 507 |
{
|
| 508 |
"cell_type": "markdown",
|
|
|
|
| 629 |
]
|
| 630 |
}
|
| 631 |
]
|
| 632 |
+
}
|