{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "_JvlvnHxAVOn" }, "outputs": [], "source": [ "#Install required libraries\n", "!pip install unsloth\n", "!pip install --upgrade transformers peft accelerate bitsandbytes trl datasets\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "A78ek9O3Agzc", "outputId": "b2b5ab78-a16b-4109-e868-7f9a167e8be8" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using device: Tesla T4\n" ] } ], "source": [ "# STEP 2: Import core libraries and detect the available GPU\n", "# This notebook is designed to run on Google Colab with a free T4 GPU.\n", "# The Tesla T4 has 16 GB VRAM β enough for Qwen3-8B in 4-bit quantization (~5 GB footprint).\n", "# If no GPU is found: Runtime > Change runtime type > T4 GPU.\n", "import os\n", "import json\n", "import torch\n", "import pandas as pd\n", "\n", "# Auto-detect GPU and print device name for verification\n", "if torch.cuda.is_available():\n", " DEVICE = torch.device(\"cuda\")\n", " print(f\"Using device: {torch.cuda.get_device_name(0)}\")\n", "else:\n", " DEVICE = torch.device(\"cpu\")\n", " print(\"No GPU found β check Runtime > Change runtime type > T4 GPU\")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000, "referenced_widgets": [ "5191357fa89e4abdad54c926bc24ede2", "54be084e90b54763b183db13bed0f636", "dec835663a9144438ebae8825737d2c2", "9f9bff050c5f4970a0ae3154ac254452", "b9d3cb2090ae4f029e23235bc443ee14", "569b2559af914597addc585b25e0966b", "ece9482b0b7d479ea88bc7edfffd8d0a", "3e18334861a24b418e7d7ae98832ddbf", "5382c7be72634f788890e950b9b8edd0", "8aaac5b9f77b4ab293dcace0cdd6a3b4", "20585eee6f1242629765c889bfbfbaee", "3a16888eec17477ea31e2c9b1658c69d", "6848d0d7f0b04f86ab2a9eebf253f097", "56e083059f45429e83d393e74648168a", "f8624677f4e94bd48126875cf6a51653", "d217892a9511479289ea7db22824545c", "b05bc7d064dc4b1fba8826f47dc44c1d", "afe0f553aaed43cc984f76cbc4873a2c", "1c94441279c640c1b9eee35b46f9da09", "d1213a20dade4fbb91a822eab2162e9b", "6f5706cfe9c648b3b8f7a7c262f28fcd", "c49a007989aa49ba840fc84909ef3924", "96ac4a4a043c485c93410da3268becbb", "8d8bb2dbde7d455bbf0f64565c7ca666", "e18a7b27d0f64ea0a213c8d2a7a961c0", "b5614bbccf134cb884adaabc6a85749b", "89e5a71dc7a04ba7949fecf30e5ab5c3", "be6e34aa567242cc8177b7130f6b771c", "b4f8f70ac33f407bb20fef46ca2978c2", "a138a39ec6ee4defbfb8f97e0d35ee8b", "e995ff6a5f4a4ff488dc8c9e229efb47", "5eb6a6dd99d4480faa23d9c6a55b6cbc", "d86796ea3d64487d8c0d7880ca8ffbfa" ] }, "id": "BbNhsYMSAhnm", "outputId": "64230ca5-0746-46bd-f7a5-73970339ee59" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "==((====))== Unsloth 2026.3.3: Fast Qwen3 patching. Transformers: 5.2.0.\n", " \\\\ /| Tesla T4. Num GPUs = 1. Max memory: 14.563 GB. Platform: Linux.\n", "O^O/ \\_/ \\ Torch: 2.10.0+cu128. CUDA: 7.5. CUDA Toolkit: 12.8. Triton: 3.6.0\n", "\\ / Bfloat16 = FALSE. FA [Xformers = 0.0.35. FA2 = False]\n", " \"-____-\" Free license: http://github.com/unslothai/unsloth\n", "Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5191357fa89e4abdad54c926bc24ede2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Loading weights: 0%| | 0/399 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "unsloth/qwen3-8b-bnb-4bit does not have a padding token! Will use pad_token = <|PAD_TOKEN|>.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3a16888eec17477ea31e2c9b1658c69d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map: 0%| | 0/2000 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Training dataset: 2000 examples\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "96ac4a4a043c485c93410da3268becbb", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Unsloth: Tokenizing [\"text\"] (num_proc=2): 0%| | 0/2000 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "The tokenizer has new PAD/BOS/EOS tokens that differ from the model config and generation config. The model config and generation config were aligned accordingly, being updated with the tokenizer's values. Updated tokens: {'bos_token_id': None}.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "π¦₯ Unsloth: Padding-free auto-enabled, enabling faster training.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "==((====))== Unsloth - 2x faster free finetuning | Num GPUs used = 1\n", " \\\\ /| Num examples = 2,000 | Num Epochs = 3 | Total steps = 375\n", "O^O/ \\_/ \\ Batch size per device = 4 | Gradient accumulation steps = 4\n", "\\ / Data Parallel GPUs = 1 | Total batch size (4 x 4 x 1) = 16\n", " \"-____-\" Trainable parameters = 43,646,976 of 8,234,382,336 (0.53% trained)\n" ] }, { "data": { "text/html": [ "\n", "
| Step | \n", "Training Loss | \n", "
|---|---|
| 10 | \n", "2.013895 | \n", "
| 20 | \n", "1.220427 | \n", "
| 30 | \n", "0.926248 | \n", "
| 40 | \n", "0.932706 | \n", "
| 50 | \n", "0.910752 | \n", "
| 60 | \n", "0.903756 | \n", "
| 70 | \n", "0.888169 | \n", "
| 80 | \n", "0.879890 | \n", "
| 90 | \n", "0.880934 | \n", "
| 100 | \n", "0.924172 | \n", "
| 110 | \n", "0.867776 | \n", "
| 120 | \n", "0.866400 | \n", "
| 130 | \n", "0.864028 | \n", "
| 140 | \n", "0.847386 | \n", "
| 150 | \n", "0.857944 | \n", "
| 160 | \n", "0.830444 | \n", "
| 170 | \n", "0.869034 | \n", "
| 180 | \n", "0.864297 | \n", "
| 190 | \n", "0.856001 | \n", "
| 200 | \n", "0.870350 | \n", "
| 210 | \n", "0.828398 | \n", "
| 220 | \n", "0.839814 | \n", "
| 230 | \n", "0.867916 | \n", "
| 240 | \n", "0.869452 | \n", "
| 250 | \n", "0.862546 | \n", "
| 260 | \n", "0.776549 | \n", "
| 270 | \n", "0.823319 | \n", "
| 280 | \n", "0.828021 | \n", "
| 290 | \n", "0.830391 | \n", "
| 300 | \n", "0.815361 | \n", "
| 310 | \n", "0.783150 | \n", "
| 320 | \n", "0.808406 | \n", "
| 330 | \n", "0.766937 | \n", "
| 340 | \n", "0.798933 | \n", "
| 350 | \n", "0.781558 | \n", "
| 360 | \n", "0.800343 | \n", "
| 370 | \n", "0.803681 | \n", "
"
],
"text/plain": [
"