Text Generation
Transformers
English
qwen2
code-generation
python
fine-tuning
Qwen
tools
agent-framework
multi-agent
conversational
Eval Results (legacy)
Instructions to use my-ai-stack/Stack-2-9-finetuned with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use my-ai-stack/Stack-2-9-finetuned with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="my-ai-stack/Stack-2-9-finetuned") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("my-ai-stack/Stack-2-9-finetuned") model = AutoModelForCausalLM.from_pretrained("my-ai-stack/Stack-2-9-finetuned") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use my-ai-stack/Stack-2-9-finetuned with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "my-ai-stack/Stack-2-9-finetuned" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/my-ai-stack/Stack-2-9-finetuned
- SGLang
How to use my-ai-stack/Stack-2-9-finetuned with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "my-ai-stack/Stack-2-9-finetuned" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "my-ai-stack/Stack-2-9-finetuned" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use my-ai-stack/Stack-2-9-finetuned with Docker Model Runner:
docker model run hf.co/my-ai-stack/Stack-2-9-finetuned
walidsobhie-code Claude Opus 4.6 commited on
Commit ·
6a2254e
1
Parent(s): 78417b9
fix: fix git clone command in Kaggle notebook
Browse files- Use subprocess instead of shell command
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- kaggle_train_stack29.ipynb +1 -228
kaggle_train_stack29.ipynb
CHANGED
|
@@ -1,228 +1 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "markdown",
|
| 5 |
-
"metadata": {},
|
| 6 |
-
"source": [
|
| 7 |
-
"# 🚀 Stack 2.9 - Kaggle Training Notebook\n",
|
| 8 |
-
"\n",
|
| 9 |
-
"**Free GPU training on Kaggle**\n",
|
| 10 |
-
"\n",
|
| 11 |
-
"This notebook trains a LoRA adapter for Stack 2.9 on **Qwen2.5-Coder-7B** using Kaggle's free GPU.\n",
|
| 12 |
-
"\n",
|
| 13 |
-
"⏱️ **Expected runtime:** 2-4 hours\n",
|
| 14 |
-
"💾 **VRAM needed:** ~16GB (Kaggle P100 has 16GB)\n",
|
| 15 |
-
"\n",
|
| 16 |
-
"---\n",
|
| 17 |
-
"\n",
|
| 18 |
-
"**Instructions:**\n",
|
| 19 |
-
"1. Enable GPU: Settings → Accelerator → GPU P100\n",
|
| 20 |
-
"2. Run cells in order from the top\n",
|
| 21 |
-
"3. Model auto-downloads if not present\n",
|
| 22 |
-
"\n",
|
| 23 |
-
"---"
|
| 24 |
-
]
|
| 25 |
-
},
|
| 26 |
-
{
|
| 27 |
-
"cell_type": "code",
|
| 28 |
-
"execution_count": null,
|
| 29 |
-
"metadata": {},
|
| 30 |
-
"outputs": [],
|
| 31 |
-
"source": [
|
| 32 |
-
"# STEP 1: Check GPU\n",
|
| 33 |
-
"!nvidia-smi"
|
| 34 |
-
]
|
| 35 |
-
},
|
| 36 |
-
{
|
| 37 |
-
"cell_type": "code",
|
| 38 |
-
"execution_count": null,
|
| 39 |
-
"metadata": {},
|
| 40 |
-
"outputs": [],
|
| 41 |
-
"source": [
|
| 42 |
-
"# STEP 2: Clone repo\n",
|
| 43 |
-
"import os\n",
|
| 44 |
-
"import shutil\n",
|
| 45 |
-
"\n",
|
| 46 |
-
"REPO_DIR = \"/kaggle/working/stack-2.9\"\n",
|
| 47 |
-
"\n",
|
| 48 |
-
"if os.path.exists(REPO_DIR):\n",
|
| 49 |
-
" shutil.rmtree(REPO_DIR)\n",
|
| 50 |
-
"\n",
|
| 51 |
-
"!git clone https://github.com/my-ai-stack/stack-2.9.git {REPO_DIR}\n",
|
| 52 |
-
"\n",
|
| 53 |
-
"os.chdir(REPO_DIR)\n",
|
| 54 |
-
"print(f\"✅ Working in: {os.getcwd()}\")"
|
| 55 |
-
]
|
| 56 |
-
},
|
| 57 |
-
{
|
| 58 |
-
"cell_type": "code",
|
| 59 |
-
"execution_count": null,
|
| 60 |
-
"metadata": {},
|
| 61 |
-
"outputs": [],
|
| 62 |
-
"source": [
|
| 63 |
-
"# STEP 3: Install dependencies\n",
|
| 64 |
-
"!pip install -q torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118\n",
|
| 65 |
-
"!pip install -q transformers peft accelerate datasets pyyaml tqdm scipy bitsandbytes\n",
|
| 66 |
-
"print(\"✅ Dependencies installed\")"
|
| 67 |
-
]
|
| 68 |
-
},
|
| 69 |
-
{
|
| 70 |
-
"cell_type": "code",
|
| 71 |
-
"execution_count": null,
|
| 72 |
-
"metadata": {},
|
| 73 |
-
"outputs": [],
|
| 74 |
-
"source": [
|
| 75 |
-
"# STEP 4: Setup paths (MODEL_DIR, OUTPUT_DIR)\n",
|
| 76 |
-
"import os\n",
|
| 77 |
-
"\n",
|
| 78 |
-
"REPO_DIR = \"/kaggle/working/stack-2.9\"\n",
|
| 79 |
-
"MODEL_DIR = os.path.join(REPO_DIR, \"base_model_qwen7b\")\n",
|
| 80 |
-
"OUTPUT_DIR = os.path.join(REPO_DIR, \"training_output\")\n",
|
| 81 |
-
"\n",
|
| 82 |
-
"print(f\"REPO_DIR: {REPO_DIR}\")\n",
|
| 83 |
-
"print(f\"MODEL_DIR: {MODEL_DIR}\")\n",
|
| 84 |
-
"print(f\"OUTPUT_DIR: {OUTPUT_DIR}\")"
|
| 85 |
-
]
|
| 86 |
-
},
|
| 87 |
-
{
|
| 88 |
-
"cell_type": "code",
|
| 89 |
-
"execution_count": null,
|
| 90 |
-
"metadata": {},
|
| 91 |
-
"outputs": [],
|
| 92 |
-
"source": [
|
| 93 |
-
"# STEP 5: Download model (if not exists)\n",
|
| 94 |
-
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
|
| 95 |
-
"\n",
|
| 96 |
-
"if os.path.exists(os.path.join(MODEL_DIR, \"config.json\")):\n",
|
| 97 |
-
" print(\"✅ Model already exists, skipping download!\")\n",
|
| 98 |
-
"else:\n",
|
| 99 |
-
" print(\"⬇️ Downloading model (Qwen2.5-Coder-7B)...\")\n",
|
| 100 |
-
" print(\"This takes ~10-15 minutes...\")\n",
|
| 101 |
-
" tokenizer = AutoTokenizer.from_pretrained(\"Qwen/Qwen2.5-Coder-7B\", trust_remote_code=True)\n",
|
| 102 |
-
" tokenizer.save_pretrained(MODEL_DIR)\n",
|
| 103 |
-
" model = AutoModelForCausalLM.from_pretrained(\"Qwen/Qwen2.5-Coder-7B\", trust_remote_code=True)\n",
|
| 104 |
-
" model.save_pretrained(MODEL_DIR)\n",
|
| 105 |
-
" print(\"✅ Model downloaded!\")\n",
|
| 106 |
-
"\n",
|
| 107 |
-
"!ls -lh {MODEL_DIR} | head -5"
|
| 108 |
-
]
|
| 109 |
-
},
|
| 110 |
-
{
|
| 111 |
-
"cell_type": "code",
|
| 112 |
-
"execution_count": null,
|
| 113 |
-
"metadata": {},
|
| 114 |
-
"outputs": [],
|
| 115 |
-
"source": [
|
| 116 |
-
"# STEP 6: Create config\n",
|
| 117 |
-
"import yaml\n",
|
| 118 |
-
"import os\n",
|
| 119 |
-
"\n",
|
| 120 |
-
"os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
|
| 121 |
-
"\n",
|
| 122 |
-
"config = {\n",
|
| 123 |
-
" 'model': {'name': MODEL_DIR, 'trust_remote_code': True, 'torch_dtype': 'float16'},\n",
|
| 124 |
-
" 'data': {'input_path': './data/final/train.jsonl', 'max_length': 2048},\n",
|
| 125 |
-
" 'lora': {'r': 16, 'alpha': 32, 'dropout': 0.05,\n",
|
| 126 |
-
" 'target_modules': ['q_proj', 'k_proj', 'v_proj', 'o_proj'],\n",
|
| 127 |
-
" 'bias': 'none', 'task_type': 'CAUSAL_LM'},\n",
|
| 128 |
-
" 'training': {'num_epochs': 1, 'batch_size': 2, 'gradient_accumulation': 4,\n",
|
| 129 |
-
" 'learning_rate': 2e-4, 'warmup_steps': 50, 'weight_decay': 0.01,\n",
|
| 130 |
-
" 'max_grad_norm': 1.0, 'logging_steps': 5, 'eval_steps': 100,\n",
|
| 131 |
-
" 'save_steps': 200, 'save_total_limit': 2, 'fp16': True, 'bf16': False,\n",
|
| 132 |
-
" 'gradient_checkpointing': True},\n",
|
| 133 |
-
" 'output': {'lora_dir': os.path.join(OUTPUT_DIR, 'lora'),\n",
|
| 134 |
-
" 'merged_dir': os.path.join(OUTPUT_DIR, 'merged')},\n",
|
| 135 |
-
" 'quantization': {'enabled': False},\n",
|
| 136 |
-
" 'hardware': {'device': 'cuda', 'num_gpus': 1, 'use_4bit': False, 'use_8bit': False}\n",
|
| 137 |
-
"}\n",
|
| 138 |
-
"\n",
|
| 139 |
-
"config_path = os.path.join(OUTPUT_DIR, \"train_config.yaml\")\n",
|
| 140 |
-
"with open(config_path, 'w') as f:\n",
|
| 141 |
-
" yaml.dump(config, f)\n",
|
| 142 |
-
"\n",
|
| 143 |
-
"print(f\"✅ Config saved to: {config_path}\")\n",
|
| 144 |
-
"print(f\" Device: {config['hardware']['device']}\")"
|
| 145 |
-
]
|
| 146 |
-
},
|
| 147 |
-
{
|
| 148 |
-
"cell_type": "code",
|
| 149 |
-
"execution_count": null,
|
| 150 |
-
"metadata": {},
|
| 151 |
-
"outputs": [],
|
| 152 |
-
"source": [
|
| 153 |
-
"# STEP 7: Train LoRA\n",
|
| 154 |
-
"import sys\n",
|
| 155 |
-
"sys.path.insert(0, os.path.join(REPO_DIR, \"stack/training\"))\n",
|
| 156 |
-
"\n",
|
| 157 |
-
"print(\"=\"*60)\n",
|
| 158 |
-
"print(\"STARTING TRAINING\")\n",
|
| 159 |
-
"print(\"=\"*60)\n",
|
| 160 |
-
"\n",
|
| 161 |
-
"from train_lora import train_lora\n",
|
| 162 |
-
"trainer = train_lora(config_path)\n",
|
| 163 |
-
"\n",
|
| 164 |
-
"print(\"=\"*60)\n",
|
| 165 |
-
"print(\"TRAINING COMPLETED!\")\n",
|
| 166 |
-
"print(\"=\"*60)"
|
| 167 |
-
]
|
| 168 |
-
},
|
| 169 |
-
{
|
| 170 |
-
"cell_type": "code",
|
| 171 |
-
"execution_count": null,
|
| 172 |
-
"metadata": {},
|
| 173 |
-
"outputs": [],
|
| 174 |
-
"source": [
|
| 175 |
-
"# STEP 8: Merge model\n",
|
| 176 |
-
"import sys\n",
|
| 177 |
-
"sys.path.insert(0, os.path.join(REPO_DIR, \"stack/training\"))\n",
|
| 178 |
-
"from merge_adapter import merge_adapter\n",
|
| 179 |
-
"\n",
|
| 180 |
-
"merged_dir = os.path.join(OUTPUT_DIR, \"merged\")\n",
|
| 181 |
-
"os.makedirs(merged_dir, exist_ok=True)\n",
|
| 182 |
-
"\n",
|
| 183 |
-
"merge_config = {\n",
|
| 184 |
-
" 'model': {'name': MODEL_DIR, 'trust_remote_code': True},\n",
|
| 185 |
-
" 'output': {'lora_dir': os.path.join(OUTPUT_DIR, 'lora'), 'merged_dir': merged_dir},\n",
|
| 186 |
-
" 'quantization': {'enabled': False}\n",
|
| 187 |
-
"}\n",
|
| 188 |
-
"\n",
|
| 189 |
-
"merge_cfg_path = os.path.join(OUTPUT_DIR, \"merge_config.yaml\")\n",
|
| 190 |
-
"with open(merge_cfg_path, 'w') as f:\n",
|
| 191 |
-
" yaml.dump(merge_config, f)\n",
|
| 192 |
-
"\n",
|
| 193 |
-
"merge_adapter(merge_cfg_path, os.path.join(OUTPUT_DIR, \"lora\"), merged_dir)\n",
|
| 194 |
-
"\n",
|
| 195 |
-
"print(f\"✅ Merged model saved to: {merged_dir}\")\n",
|
| 196 |
-
"!ls -lh {merged_dir}"
|
| 197 |
-
]
|
| 198 |
-
},
|
| 199 |
-
{
|
| 200 |
-
"cell_type": "code",
|
| 201 |
-
"execution_count": null,
|
| 202 |
-
"metadata": {},
|
| 203 |
-
"outputs": [],
|
| 204 |
-
"source": [
|
| 205 |
-
"# STEP 9: Done!\n",
|
| 206 |
-
"print(\"=\"*60)\n",
|
| 207 |
-
"print(\"🎉 TRAINING COMPLETE!\")\n",
|
| 208 |
-
"print(\"=\"*60)\n",
|
| 209 |
-
"print(f\"LoRA adapter: {os.path.join(OUTPUT_DIR, 'lora')}\")\n",
|
| 210 |
-
"print(f\"Merged model: {os.path.join(OUTPUT_DIR, 'merged')}\")\n",
|
| 211 |
-
"print(\"\\n📥 Download from: Kaggle → Output tab\")"
|
| 212 |
-
]
|
| 213 |
-
}
|
| 214 |
-
],
|
| 215 |
-
"metadata": {
|
| 216 |
-
"kaggle": {
|
| 217 |
-
"accelerator": "gpu",
|
| 218 |
-
"dataSources": [],
|
| 219 |
-
"kernelSpec": {
|
| 220 |
-
"displayName": "Python 3",
|
| 221 |
-
"language": "python",
|
| 222 |
-
"name": "python3"
|
| 223 |
-
}
|
| 224 |
-
}
|
| 225 |
-
},
|
| 226 |
-
"nbformat": 4,
|
| 227 |
-
"nbformat_minor": 0
|
| 228 |
-
}
|
|
|
|
| 1 |
+
{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# \ud83d\ude80 Stack 2.9 - Kaggle Training Notebook\n", "\n", "**Free GPU training on Kaggle**\n", "\n", "This notebook trains a LoRA adapter for Stack 2.9 on **Qwen2.5-Coder-7B** using Kaggle's free GPU.\n", "\n", "\u23f1\ufe0f **Expected runtime:** 2-4 hours\n", "\ud83d\udcbe **VRAM needed:** ~16GB (Kaggle P100 has 16GB)\n", "\n", "---\n", "\n", "**Instructions:**\n", "1. Enable GPU: Settings \u2192 Accelerator \u2192 GPU P100\n", "2. Run cells in order from the top\n", "3. Model auto-downloads if not present\n", "\n", "---"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# STEP 2: Clone repo\n", "import os\n", "import shutil\n", "import subprocess\n", "\n", "REPO_DIR = \"/kaggle/working/stack-2.9\"\n", "\n", "if os.path.exists(REPO_DIR):\n", " shutil.rmtree(REPO_DIR)\n", "\n", "subprocess.run([\"git\", \"clone\", \"https://github.com/my-ai-stack/stack-2.9.git\", REPO_DIR], check=True)\n", "\n", "os.chdir(REPO_DIR)\n", "print(f\"\u2705 Working in: {os.getcwd()}\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# STEP 3: Install dependencies\n", "import subprocess\n", "subprocess.run([\"pip\", \"install\", \"-q\", \"torch\", \"torchvision\", \"torchaudio\", \"--index-url\", \"https://download.pytorch.org/whl/cu118\"], check=True)\n", "subprocess.run([\"pip\", \"install\", \"-q\", \"transformers\", \"peft\", \"accelerate\", \"datasets\", \"pyyaml\", \"tqdm\", \"scipy\", \"bitsandbytes\"], check=True)\n", "print(\"\u2705 Dependencies installed\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# STEP 3: Install dependencies\n", "!pip install -q torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118\n", "!pip install -q transformers peft accelerate datasets pyyaml tqdm scipy bitsandbytes\n", "print(\"\u2705 Dependencies installed\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# STEP 4: Setup paths (MODEL_DIR, OUTPUT_DIR)\n", "import os\n", "\n", "REPO_DIR = \"/kaggle/working/stack-2.9\"\n", "MODEL_DIR = os.path.join(REPO_DIR, \"base_model_qwen7b\")\n", "OUTPUT_DIR = os.path.join(REPO_DIR, \"training_output\")\n", "\n", "print(f\"REPO_DIR: {REPO_DIR}\")\n", "print(f\"MODEL_DIR: {MODEL_DIR}\")\n", "print(f\"OUTPUT_DIR: {OUTPUT_DIR}\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# STEP 5: Download model (if not exists)\n", "from transformers import AutoModelForCausalLM, AutoTokenizer\n", "\n", "if os.path.exists(os.path.join(MODEL_DIR, \"config.json\")):\n", " print(\"\u2705 Model already exists, skipping download!\")\n", "else:\n", " print(\"\u2b07\ufe0f Downloading model (Qwen2.5-Coder-7B)...\")\n", " print(\"This takes ~10-15 minutes...\")\n", " tokenizer = AutoTokenizer.from_pretrained(\"Qwen/Qwen2.5-Coder-7B\", trust_remote_code=True)\n", " tokenizer.save_pretrained(MODEL_DIR)\n", " model = AutoModelForCausalLM.from_pretrained(\"Qwen/Qwen2.5-Coder-7B\", trust_remote_code=True)\n", " model.save_pretrained(MODEL_DIR)\n", " print(\"\u2705 Model downloaded!\")\n", "\n", "import subprocess\n", "subprocess.run([\"ls\", \"-lh\", MODEL_DIR], check=True)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# STEP 6: Create config\n", "import yaml\n", "import os\n", "\n", "os.makedirs(OUTPUT_DIR, exist_ok=True)\n", "\n", "config = {\n", " 'model': {'name': MODEL_DIR, 'trust_remote_code': True, 'torch_dtype': 'float16'},\n", " 'data': {'input_path': './data/final/train.jsonl', 'max_length': 2048},\n", " 'lora': {'r': 16, 'alpha': 32, 'dropout': 0.05,\n", " 'target_modules': ['q_proj', 'k_proj', 'v_proj', 'o_proj'],\n", " 'bias': 'none', 'task_type': 'CAUSAL_LM'},\n", " 'training': {'num_epochs': 1, 'batch_size': 2, 'gradient_accumulation': 4,\n", " 'learning_rate': 2e-4, 'warmup_steps': 50, 'weight_decay': 0.01,\n", " 'max_grad_norm': 1.0, 'logging_steps': 5, 'eval_steps': 100,\n", " 'save_steps': 200, 'save_total_limit': 2, 'fp16': True, 'bf16': False,\n", " 'gradient_checkpointing': True},\n", " 'output': {'lora_dir': os.path.join(OUTPUT_DIR, 'lora'),\n", " 'merged_dir': os.path.join(OUTPUT_DIR, 'merged')},\n", " 'quantization': {'enabled': False},\n", " 'hardware': {'device': 'cuda', 'num_gpus': 1, 'use_4bit': False, 'use_8bit': False}\n", "}\n", "\n", "config_path = os.path.join(OUTPUT_DIR, \"train_config.yaml\")\n", "with open(config_path, 'w') as f:\n", " yaml.dump(config, f)\n", "\n", "print(f\"\u2705 Config saved to: {config_path}\")\n", "print(f\" Device: {config['hardware']['device']}\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# STEP 7: Train LoRA\n", "import sys\n", "sys.path.insert(0, os.path.join(REPO_DIR, \"stack/training\"))\n", "\n", "print(\"=\"*60)\n", "print(\"STARTING TRAINING\")\n", "print(\"=\"*60)\n", "\n", "from train_lora import train_lora\n", "trainer = train_lora(config_path)\n", "\n", "print(\"=\"*60)\n", "print(\"TRAINING COMPLETED!\")\n", "print(\"=\"*60)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# STEP 8: Merge model\n", "import sys\n", "sys.path.insert(0, os.path.join(REPO_DIR, \"stack/training\"))\n", "from merge_adapter import merge_adapter\n", "\n", "merged_dir = os.path.join(OUTPUT_DIR, \"merged\")\n", "os.makedirs(merged_dir, exist_ok=True)\n", "\n", "merge_config = {\n", " 'model': {'name': MODEL_DIR, 'trust_remote_code': True},\n", " 'output': {'lora_dir': os.path.join(OUTPUT_DIR, 'lora'), 'merged_dir': merged_dir},\n", " 'quantization': {'enabled': False}\n", "}\n", "\n", "merge_cfg_path = os.path.join(OUTPUT_DIR, \"merge_config.yaml\")\n", "with open(merge_cfg_path, 'w') as f:\n", " yaml.dump(merge_config, f)\n", "\n", "merge_adapter(merge_cfg_path, os.path.join(OUTPUT_DIR, \"lora\"), merged_dir)\n", "\n", "print(f\"\u2705 Merged model saved to: {merged_dir}\")\n", "import subprocess\n", "subprocess.run([\"ls\", \"-lh\", merged_dir], check=True)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["# STEP 9: Done!\n", "print(\"=\"*60)\n", "print(\"\ud83c\udf89 TRAINING COMPLETE!\")\n", "print(\"=\"*60)\n", "print(f\"LoRA adapter: {os.path.join(OUTPUT_DIR, 'lora')}\")\n", "print(f\"Merged model: {os.path.join(OUTPUT_DIR, 'merged')}\")\n", "print(\"\\n\ud83d\udce5 Download from: Kaggle \u2192 Output tab\")"]}], "metadata": {"kaggle": {"accelerator": "gpu", "dataSources": [], "kernelSpec": {"displayName": "Python 3", "language": "python", "name": "python3"}}}, "nbformat": 4, "nbformat_minor": 0}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|