walidsobhie-code commited on
Commit
fb15bd8
·
1 Parent(s): 10182dc

feat: add ready-to-run notebooks for Kaggle and Colab

Browse files

- Colab 128K context fine-tuning notebook
- Kaggle 128K context fine-tuning notebook
- Colab HumanEval benchmark notebook

notebooks/colab_128k_training.ipynb ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# 🎯 Stack 2.9 — 128K Context Fine-tuning\n",
8
+ "Fine-tune Qwen2.5-Coder-1.5B from 32K → 128K context\n",
9
+ "\n",
10
+ "**Runtime:** GPU (T4 16GB recommended) | **Time:** ~2-3 hours"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "metadata": {},
16
+ "source": [
17
+ "## Step 1: Clone Stack 2.9 & Install Dependencies"
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "code",
22
+ "execution_count": null,
23
+ "metadata": {},
24
+ "outputs": [],
25
+ "source": [
26
+ "!git clone https://github.com/my-ai-stack/stack-2.9.git\n",
27
+ "cd stack-2.9\n",
28
+ "!pip install -q transformers peft datasets bitsandbytes accelerate huggingface_hub\n",
29
+ "!pip install -q scipy torch --upgrade"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "markdown",
34
+ "metadata": {},
35
+ "source": [
36
+ "## Step 2: Login to HuggingFace (push weights later)"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": null,
42
+ "metadata": {},
43
+ "outputs": [],
44
+ "source": [
45
+ "from huggingface_hub import login\n",
46
+ "# Get your token at: https://huggingface.co/settings/tokens\n",
47
+ "login(token=\"YOUR_HF_TOKEN\") # ← Replace with your token"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "markdown",
52
+ "metadata": {},
53
+ "source": [
54
+ "## Step 3: Mount Google Drive (optional — for saving checkpoints)"
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": null,
60
+ "metadata": {},
61
+ "outputs": [],
62
+ "source": [
63
+ "from google.colab import drive\n",
64
+ "drive.mount('/content/drive')\n",
65
+ "OUTPUT_DIR = \"/content/drive/MyDrive/stack-2.9-128k-output\""
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "markdown",
70
+ "metadata": {},
71
+ "source": [
72
+ "## Step 4: Run 128K Context Fine-tuning"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": null,
78
+ "metadata": {},
79
+ "outputs": [],
80
+ "source": [
81
+ "import subprocess\n",
82
+ "result = subprocess.run([\n",
83
+ " \"python3\", \"training/train_extended_context.py\",\n",
84
+ " \"--model-path\", \"my-ai-stack/Stack-2-9-finetuned\",\n",
85
+ " \"--data-path\", \"training/training-data/tool_examples_combined.jsonl\",\n",
86
+ " \"--output-dir\", OUTPUT_DIR,\n",
87
+ " \"--context-length\", \"131072\",\n",
88
+ " \"--lora-rank\", \"64\",\n",
89
+ " \"--epochs\", \"3\",\n",
90
+ " \"--push-to-hub\",\n",
91
+ " \"--hub-model-id\", \"YOUR_USERNAME/stack-2.9-128k\"\n",
92
+ "], cwd=\"/content/stack-2.9\")\n",
93
+ "print(result.stdout)\n",
94
+ "print(result.stderr)"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "markdown",
99
+ "metadata": {},
100
+ "source": [
101
+ "---\n",
102
+ "\n",
103
+ "## Alternative: Run on Base Qwen Model (if HF model not loaded)\n",
104
+ "\n",
105
+ "If the fine-tuned model isn't available, use the base model:"
106
+ ]
107
+ },
108
+ {
109
+ "cell_type": "code",
110
+ "execution_count": null,
111
+ "metadata": {},
112
+ "outputs": [],
113
+ "source": [
114
+ "# Change --model-path to:\n",
115
+ "# \"Qwen/Qwen2.5-Coder-1.5B\"\n",
116
+ "# And add --push-to-hub with your own model ID"
117
+ ]
118
+ }
119
+ ],
120
+ "metadata": {
121
+ "accelerator": "GPU",
122
+ "colab": {
123
+ "provenance": [],
124
+ "machine_shape": "hm"
125
+ },
126
+ "kernelspec": {
127
+ "display_name": "Python 3",
128
+ "language": "python",
129
+ "name": "python3"
130
+ },
131
+ "language_info": {
132
+ "name": "python",
133
+ "version": "3.10.0"
134
+ }
135
+ },
136
+ "nbformat": 4,
137
+ "nbformat_minor": 4
138
+ }
notebooks/colab_humaneval.ipynb ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# 📊 Stack 2.9 — HumanEval Benchmark\n",
8
+ "Run full HumanEval (164 problems) pass@k evaluation\n",
9
+ "\n",
10
+ "**Runtime:** GPU (T4 16GB) | **Time:** ~30-60 min"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "metadata": {},
16
+ "source": [
17
+ "## Step 1: Clone & Install"
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "code",
22
+ "execution_count": null,
23
+ "metadata": {},
24
+ "outputs": [],
25
+ "source": [
26
+ "!git clone https://github.com/my-ai-stack/stack-2.9.git\n",
27
+ "cd stack-2.9\n",
28
+ "!pip install -q transformers peft datasets human-eval accelerate"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "markdown",
33
+ "metadata": {},
34
+ "source": [
35
+ "## Step 2: Run HumanEval Benchmark"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": null,
41
+ "metadata": {},
42
+ "outputs": [],
43
+ "source": [
44
+ "MODEL_PATH = \"my-ai-stack/Stack-2-9-finetuned\" # or your 128K fine-tuned model ID\n",
45
+ "\n",
46
+ "import subprocess\n",
47
+ "result = subprocess.run([\n",
48
+ " \"python3\", \"training/evaluate_model.py\",\n",
49
+ " \"--model-path\", MODEL_PATH,\n",
50
+ " \"--benchmark\", \"humaneval\",\n",
51
+ " \"--num-samples\", \"10\",\n",
52
+ " \"--max-new-tokens\", \"256\",\n",
53
+ " \"--output\", \"/tmp/humaneval_results.json\"\n",
54
+ "], cwd=\"/content/stack-2.9\", capture_output=True, text=True)\n",
55
+ "\n",
56
+ "print(result.stdout[-5000:] if result.stdout else \"No output\")\n",
57
+ "print(\"STDERR:\", result.stderr[-1000:] if result.stderr else \"None\")"
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "markdown",
62
+ "metadata": {},
63
+ "source": [
64
+ "## Step 3: Parse Results"
65
+ ]
66
+ },
67
+ {
68
+ "cell_type": "code",
69
+ "execution_count": null,
70
+ "metadata": {},
71
+ "outputs": [],
72
+ "source": [
73
+ "import json\n",
74
+ "with open(\"/tmp/humaneval_results.json\") as f:\n",
75
+ " results = json.load(f)\n",
76
+ "\n",
77
+ "print(\"=== HumanEval Results ===\")\n",
78
+ "for k, v in results.items():\n",
79
+ " if isinstance(v, float):\n",
80
+ " print(f\" pass@{k}: {v:.1%}\")\n",
81
+ " else:\n",
82
+ " print(f\" {k}: {v}\")"
83
+ ]
84
+ }
85
+ ],
86
+ "metadata": {
87
+ "accelerator": "GPU",
88
+ "colab": {
89
+ "provenance": [],
90
+ "machine_shape": "hm"
91
+ },
92
+ "kernelspec": {
93
+ "display_name": "Python 3",
94
+ "language": "python",
95
+ "name": "python3"
96
+ },
97
+ "language_info": {
98
+ "name": "python",
99
+ "version": "3.10.0"
100
+ }
101
+ },
102
+ "nbformat": 4,
103
+ "nbformat_minor": 4
104
+ }
notebooks/kaggle_128k_training.ipynb ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# 🎯 Stack 2.9 — 128K Context Fine-tuning\n",
8
+ "Fine-tune Qwen2.5-Coder-1.5B from 32K → 128K context\n",
9
+ "\n",
10
+ "**Runtime:** GPU (P100 16GB) | **Time:** ~2-3 hours\n",
11
+ "\n",
12
+ "![Kaggle](https://img.shields.io/badge/Kaggle-P100-blue) ![Context](https://img.shields.io/badge/Context-128K-green)"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "markdown",
17
+ "metadata": {},
18
+ "source": [
19
+ "## Step 1: Clone Repo & Install"
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "execution_count": null,
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "!git clone https://github.com/my-ai-stack/stack-2.9.git\n",
29
+ "cd stack-2.9\n",
30
+ "!pip install -q transformers peft datasets bitsandbytes accelerate huggingface_hub\n",
31
+ "!pip install -q scipy torch --upgrade"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "markdown",
36
+ "metadata": {},
37
+ "source": [
38
+ "## Step 2: HuggingFace Login"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": null,
44
+ "metadata": {},
45
+ "outputs": [],
46
+ "source": [
47
+ "from huggingface_hub import login\n",
48
+ "import os\n",
49
+ "# Add your HF token to Kaggle Secrets: https://www.kaggle.com/docs/secrets\n",
50
+ "os.environ[\"HF_TOKEN\"] = \"YOUR_HF_TOKEN\"\n",
51
+ "login(token=os.environ[\"HF_TOKEN\"])"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "markdown",
56
+ "metadata": {},
57
+ "source": [
58
+ "## Step 3: Run Fine-tuning"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "execution_count": null,
64
+ "metadata": {},
65
+ "outputs": [],
66
+ "source": [
67
+ "import subprocess\n",
68
+ "\n",
69
+ "result = subprocess.run([\n",
70
+ " \"python3\", \"training/train_extended_context.py\",\n",
71
+ " \"--model-path\", \"Qwen/Qwen2.5-Coder-1.5B\",\n",
72
+ " \"--data-path\", \"training/training-data/tool_examples_combined.jsonl\",\n",
73
+ " \"--output-dir\", \"/kaggle/working/stack-2.9-128k\",\n",
74
+ " \"--context-length\", \"131072\",\n",
75
+ " \"--lora-rank\", \"64\",\n",
76
+ " \"--epochs\", \"3\",\n",
77
+ " \"--push-to-hub\",\n",
78
+ " \"--hub-model-id\", \"YOUR_USERNAME/stack-2.9-128k\"\n",
79
+ "], cwd=\"/kaggle/working/stack-2.9\", env=dict(os.environ, HF_TOKEN=os.environ[\"HF_TOKEN\"]))\n",
80
+ "\n",
81
+ "print(result.stdout[-3000:] if result.stdout else \"No stdout\")\n",
82
+ "print(result.stderr[-1000:] if result.stderr else \"No stderr\")"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "markdown",
87
+ "metadata": {},
88
+ "source": [
89
+ "## Step 4: Download Checkpoints"
90
+ ]
91
+ },
92
+ {
93
+ "cell_type": "code",
94
+ "execution_count": null,
95
+ "metadata": {},
96
+ "outputs": [],
97
+ "source": [
98
+ "# After training, download the merged model\n",
99
+ "!ls -la /kaggle/working/stack-2.9-128k/merged/\n",
100
+ "# The merged/ folder contains the full 128K model ready to use"
101
+ ]
102
+ }
103
+ ],
104
+ "metadata": {
105
+ "accelerator": "GPU",
106
+ "kaggle": {
107
+ "accelerator": "GPU",
108
+ "dataSources": [],
109
+ "dockerImageVersion": "gpu",
110
+ "gpuRequirements": {
111
+ "top": "p100"
112
+ },
113
+ "kernelImage": {
114
+ "id": "docker",
115
+ "name": "docker"
116
+ }
117
+ },
118
+ "kernelspec": {
119
+ "display_name": "Python 3",
120
+ "language": "python",
121
+ "name": "python3"
122
+ },
123
+ "language_info": {
124
+ "name": "python",
125
+ "version": "3.10.0"
126
+ }
127
+ },
128
+ "nbformat": 4,
129
+ "nbformat_minor": 4
130
+ }