Upload EthicalHacking_Qwen3-4B_Ultimate_Colab.ipynb
Browse files
EthicalHacking_Qwen3-4B_Ultimate_Colab.ipynb
CHANGED
|
@@ -67,7 +67,10 @@
|
|
| 67 |
"cell_type": "markdown",
|
| 68 |
"metadata": {},
|
| 69 |
"source": [
|
| 70 |
-
"## 3️⃣ Load Qwen3-4B-Instruct-2507 in 4-bit via Unsloth"
|
|
|
|
|
|
|
|
|
|
| 71 |
]
|
| 72 |
},
|
| 73 |
{
|
|
@@ -100,6 +103,7 @@
|
|
| 100 |
" max_seq_length=MAX_SEQ_LENGTH,\n",
|
| 101 |
" dtype=None,\n",
|
| 102 |
" load_in_4bit=True,\n",
|
|
|
|
| 103 |
")\n",
|
| 104 |
"\n",
|
| 105 |
"model = FastLanguageModel.get_peft_model(\n",
|
|
@@ -219,8 +223,6 @@
|
|
| 219 |
" return {\"messages\": msgs}\n",
|
| 220 |
"\n",
|
| 221 |
"def _convert_code_corpus(example):\n",
|
| 222 |
-
" # Code Corpus: raw code text with domain/repo metadata in a user prompt + assistant format\n",
|
| 223 |
-
" # We treat the code block as an assistant response to a user asking about that code\n",
|
| 224 |
" code_text = example[\"text\"]\n",
|
| 225 |
" domain = example.get(\"domain\", \"code\")\n",
|
| 226 |
" repo = example.get(\"repo\", \"unknown\")\n",
|
|
@@ -231,7 +233,6 @@
|
|
| 231 |
" {\"role\": \"assistant\", \"content\": code_text},\n",
|
| 232 |
" ]}\n",
|
| 233 |
"\n",
|
| 234 |
-
"# ===================== LOAD DATASET(S) =====================\n",
|
| 235 |
"all_datasets = []\n",
|
| 236 |
"\n",
|
| 237 |
"if DATASET_CHOICE == \"cybersecurity\":\n",
|
|
@@ -388,7 +389,7 @@
|
|
| 388 |
"outputs": [],
|
| 389 |
"source": [
|
| 390 |
"if torch.cuda.is_available():\n",
|
| 391 |
-
" print(f\"VRAM before train: {torch.cuda.memory_allocated()/1e9:.2f} GB\")\n",
|
| 392 |
"\n",
|
| 393 |
"trainer_stats = trainer.train()\n",
|
| 394 |
"\n",
|
|
|
|
| 67 |
"cell_type": "markdown",
|
| 68 |
"metadata": {},
|
| 69 |
"source": [
|
| 70 |
+
"## 3️⃣ Load Qwen3-4B-Instruct-2507 in 4-bit via Unsloth\n",
|
| 71 |
+
"\n",
|
| 72 |
+
"**⚠️ IMPORTANT:** We add `device_map={\"\": torch.cuda.current_device()}` to force the model onto the correct GPU.\n",
|
| 73 |
+
"Without this, `accelerate` may place the model on CPU and throw a `ValueError` during training on Kaggle/Colab."
|
| 74 |
]
|
| 75 |
},
|
| 76 |
{
|
|
|
|
| 103 |
" max_seq_length=MAX_SEQ_LENGTH,\n",
|
| 104 |
" dtype=None,\n",
|
| 105 |
" load_in_4bit=True,\n",
|
| 106 |
+
" device_map={\"\": torch.cuda.current_device()}, # ← FORCE GPU: fixes Kaggle/Colab device placement bug\n",
|
| 107 |
")\n",
|
| 108 |
"\n",
|
| 109 |
"model = FastLanguageModel.get_peft_model(\n",
|
|
|
|
| 223 |
" return {\"messages\": msgs}\n",
|
| 224 |
"\n",
|
| 225 |
"def _convert_code_corpus(example):\n",
|
|
|
|
|
|
|
| 226 |
" code_text = example[\"text\"]\n",
|
| 227 |
" domain = example.get(\"domain\", \"code\")\n",
|
| 228 |
" repo = example.get(\"repo\", \"unknown\")\n",
|
|
|
|
| 233 |
" {\"role\": \"assistant\", \"content\": code_text},\n",
|
| 234 |
" ]}\n",
|
| 235 |
"\n",
|
|
|
|
| 236 |
"all_datasets = []\n",
|
| 237 |
"\n",
|
| 238 |
"if DATASET_CHOICE == \"cybersecurity\":\n",
|
|
|
|
| 389 |
"outputs": [],
|
| 390 |
"source": [
|
| 391 |
"if torch.cuda.is_available():\n",
|
| 392 |
+
" print(f\"VRAM before train: {torch.cuda.memory_allocated()/1e9:.2f} GB / {torch.cuda.get_device_properties(0).total_memory/1e9:.2f} GB\")\n",
|
| 393 |
"\n",
|
| 394 |
"trainer_stats = trainer.train()\n",
|
| 395 |
"\n",
|