Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 101 additions & 64 deletions nb/Granite4.0.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"<div class=\"align-center\">\n",
"<a href=\"https://unsloth.ai/\"><img src=\"https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png\" width=\"115\"></a>\n",
"<a href=\"https://discord.gg/unsloth\"><img src=\"https://github.com/unslothai/unsloth/raw/main/images/Discord button.png\" width=\"145\"></a>\n",
"<a href=\"https://docs.unsloth.ai/\"><img src=\"https://github.com/unslothai/unsloth/blob/main/images/documentation%20green%20button.png?raw=true\" width=\"125\"></a></a> Join Discord if you need help + \u2b50 <i>Star us on <a href=\"https://github.com/unslothai/unsloth\">Github</a> </i> \u2b50\n",
"<a href=\"https://docs.unsloth.ai/\"><img src=\"https://github.com/unslothai/unsloth/blob/main/images/documentation%20green%20button.png?raw=true\" width=\"125\"></a></a> Join Discord if you need help + <i>Star us on <a href=\"https://github.com/unslothai/unsloth\">Github</a> </i> \n",
"</div>\n",
"\n",
"To install Unsloth your local device, follow [our guide](https://docs.unsloth.ai/get-started/install-and-update). This notebook is licensed [LGPL-3.0](https://github.com/unslothai/notebooks?tab=LGPL-3.0-1-ov-file#readme).\n",
Expand Down Expand Up @@ -51,7 +51,21 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "%%capture\nimport os, re\nif \"COLAB_\" not in \"\".join(os.environ.keys()):\n !pip install unsloth\nelse:\n # Do this only in Colab notebooks! Otherwise use pip install unsloth\n import torch; v = re.match(r\"[0-9\\.]{3,}\", str(torch.__version__)).group(0)\n xformers = \"xformers==\" + (\"0.0.32.post2\" if v == \"2.8.0\" else \"0.0.29.post3\")\n !pip install --no-deps bitsandbytes accelerate {xformers} peft trl triton cut_cross_entropy unsloth_zoo\n !pip install sentencepiece protobuf \"datasets>=3.4.1,<4.0.0\" \"huggingface_hub>=0.34.0\" hf_transfer\n !pip install --no-deps unsloth\n!pip install transformers==4.56.2\n!pip install --no-deps trl==0.22.2"
"source": [
"%%capture\n",
"import os, re\n",
"if \"COLAB_\" not in \"\".join(os.environ.keys()):\n",
" !pip install unsloth\n",
"else:\n",
" # Do this only in Colab notebooks! Otherwise use pip install unsloth\n",
" import torch; v = re.match(r\"[0-9\\.]{3,}\", str(torch.__version__)).group(0)\n",
" xformers = \"xformers==\" + (\"0.0.32.post2\" if v == \"2.8.0\" else \"0.0.29.post3\")\n",
" !pip install --no-deps bitsandbytes accelerate {xformers} peft trl triton cut_cross_entropy unsloth_zoo\n",
" !pip install sentencepiece protobuf \"datasets>=3.4.1,<4.0.0\" \"huggingface_hub>=0.34.0\" hf_transfer\n",
" !pip install --no-deps unsloth\n",
"!pip install transformers==4.56.2\n",
"!pip install --no-deps trl==0.22.2"
]
},
{
"cell_type": "code",
Expand All @@ -67,6 +81,28 @@
"!pip install --no-build-isolation causal_conv1d==1.5.2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import importlib.metadata as m\n",
"\n",
"packages = [\n",
" \"unsloth\", \"torch\", \"bitsandbytes\", \"accelerate\", \"xformers\",\n",
" \"peft\", \"trl\", \"triton\", \"cut_cross_entropy\", \"unsloth_zoo\",\n",
" \"sentencepiece\", \"protobuf\", \"datasets\", \"huggingface_hub\",\n",
" \"hf_transfer\", \"transformers\"\n",
"]\n",
"\n",
"for pkg in packages:\n",
" try:\n",
" print(f\"{pkg}: {m.version(pkg)}\")\n",
" except m.PackageNotFoundError:\n",
" print(f\"{pkg}: NOT INSTALLED\")"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -223,10 +259,10 @@
"source": [
"<a name=\"Data\"></a>\n",
"### Data Prep\n",
"#### \ud83d\udcc4 Using Google Sheets as Training Data\n",
"#### 📄 Using Google Sheets as Training Data\n",
"Our goal is to create a customer support bot that proactively helps and solves issues.\n",
"\n",
"We\u2019re storing examples in a Google Sheet with two columns:\n",
"We’re storing examples in a Google Sheet with two columns:\n",
"\n",
"- **Snippet**: A short customer support interaction\n",
"- **Recommendation**: A suggestion for how the agent should respond\n",
Expand All @@ -237,24 +273,24 @@
"---\n",
"<br>\n",
"\n",
"#### \ud83d\udd0d Why This Format?\n",
"#### 🔍 Why This Format?\n",
"\n",
"This setup works well for tasks like:\n",
"\n",
"- `Input snippet \u2192 Suggested reply`\n",
"- `Prompt \u2192 Rewrite`\n",
"- `Bug report \u2192 Diagnosis`\n",
"- `Text \u2192 Label or Category`\n",
"- `Input snippet Suggested reply`\n",
"- `Prompt Rewrite`\n",
"- `Bug report Diagnosis`\n",
"- `Text Label or Category`\n",
"\n",
"Just collect examples in a spreadsheet, and you\u2019ve got usable training data. \n",
"Just collect examples in a spreadsheet, and you’ve got usable training data. \n",
"<br>\n",
"\n",
"---\n",
"<br>\n",
"\n",
"#### \u2705 What You'll Learn\n",
"#### What You'll Learn\n",
"\n",
"We\u2019ll show how to:\n",
"We’ll show how to:\n",
"\n",
"1. Load the Google Sheet into your notebook\n",
"2. Format it into a dataset\n",
Expand Down Expand Up @@ -1164,62 +1200,62 @@
"# --- Scenario 1: Video-Conferencing Screen-Share Bug (11 turns) ---\n",
"scenario_1 = \"\"\"\n",
"User: Everyone in my meeting just sees a black screen when I share.\n",
"Agent: Sorry about that\u2014are you sharing a window or your entire screen?\n",
"Agent: Sorry about that—are you sharing a window or your entire screen?\n",
"User: Entire screen on macOS Sonoma.\n",
"Agent: Thanks. Do you have \u201cEnable hardware acceleration\u201d toggled on in Settings \u2192 Video?\n",
"Agent: Thanks. Do you have “Enable hardware acceleration toggled on in Settings Video?\n",
"User: Yeah, that switch is on.\n",
"Agent: Could you try toggling it off and start a quick test share?\n",
"User: Did that\u2014still black for attendees.\n",
"User: Did that—still black for attendees.\n",
"Agent: Understood. Are you on the desktop app v5.4.2 or the browser client?\n",
"User: Desktop v5.4.2\u2014just updated this morning.\n",
"User: Desktop v5.4.2—just updated this morning.\n",
"\"\"\"\n",
"\n",
"# --- Scenario 2: Smart-Lock Low-Battery Loop (9 turns) ---\n",
"scenario_2 = \"\"\"\n",
"User: I changed the batteries, but the lock app still says 5 % and won\u2019t auto-lock.\n",
"Agent: Let\u2019s check firmware. In the app, go to Settings \u2192 Device Info\u2014what version shows?\n",
"User: I changed the batteries, but the lock app still says 5 % and won’t auto-lock.\n",
"Agent: Let’s check firmware. In the app, go to Settings Device Info—what version shows?\n",
"User: 3.18.0-alpha.\n",
"Agent: Latest stable is 3.17.5. Did you enroll in the beta program?\n",
"User: I might have months ago.\n",
"Agent: Beta builds sometimes misreport battery. Remove one battery, wait ten seconds, reinsert, and watch the LED pattern.\n",
"User: LED blinks blue twice, then red once.\n",
"Agent: That blink code means \u201cconfig mismatch.\u201d Do you still have the old batteries handy?\n",
"Agent: That blink code means “config mismatch. Do you still have the old batteries handy?\n",
"User: Tossed them already.\n",
"\"\"\"\n",
"\n",
"# --- Scenario 3: Accounting SaaS \u2014 Corrupted Invoice Export (10 turns) ---\n",
"# --- Scenario 3: Accounting SaaS Corrupted Invoice Export (10 turns) ---\n",
"scenario_3 = \"\"\"\n",
"User: Every invoice I download today opens as a blank PDF.\n",
"Agent: Is this happening to historic invoices, new ones, or both?\n",
"User: Both. Anything I export is 0 bytes.\n",
"Agent: Are you exporting through \u201cBulk Actions\u201d or individual invoice pages?\n",
"Agent: Are you exporting through “Bulk Actions or individual invoice pages?\n",
"User: Individual pages.\n",
"Agent: Which browser/OS combo?\n",
"User: Chrome on Windows 11, latest update.\n",
"Agent: We released a new PDF renderer at 10 a.m. UTC. Could you try Edge quickly, just to rule out a caching quirk?\n",
"User: Tried Edge\u2014same zero-byte file.\n",
"User: Tried Edge—same zero-byte file.\n",
"\"\"\"\n",
"\n",
"# --- Scenario 4: Fitness-Tracker App \u2014 Stuck Step Count (8 turns) ---\n",
"# --- Scenario 4: Fitness-Tracker App Stuck Step Count (8 turns) ---\n",
"scenario_4 = \"\"\"\n",
"User: My step count has been frozen at 4,237 since last night.\n",
"Agent: Which phone are you syncing with?\n",
"User: iPhone 15, iOS 17.5.\n",
"Agent: In the Health Permissions screen, does \u201cMotion & Fitness\u201d show as ON?\n",
"User: Yes, it\u2019s toggled on.\n",
"Agent: In the Health Permissions screen, does “Motion & Fitness show as ON?\n",
"User: Yes, it’s toggled on.\n",
"Agent: When you pull down to refresh the dashboard, does the sync spinner appear?\n",
"User: Spinner flashes for a second, then nothing changes.\n",
"\"\"\"\n",
"\n",
"# --- Scenario 5: Online-Course Platform \u2014 Quiz Submission Error (12 turns) ---\n",
"# --- Scenario 5: Online-Course Platform Quiz Submission Error (12 turns) ---\n",
"scenario_5 = \"\"\"\n",
"User: My quiz submits but then shows \u201cUnknown grading error\u201d and resets the answers.\n",
"User: My quiz submits but then shows “Unknown grading error and resets the answers.\n",
"Agent: Which course and quiz name?\n",
"User: History 301, Unit 2 Quiz.\n",
"Agent: Do you notice a red banner or any code like GR-### in the corner?\n",
"User: Banner says \u201cGR-412\u201d.\n",
"User: Banner says “GR-412.\n",
"Agent: That code points to answer-payload size. Were you pasting images or long text into any answers?\n",
"User: Maybe a long essay\u2014about 800 words in Question 5.\n",
"User: Maybe a long essay—about 800 words in Question 5.\n",
"Agent: Are you on a laptop or mobile?\n",
"User: Laptop, Safari on macOS.\n",
"\"\"\"\n"
Expand All @@ -1242,18 +1278,18 @@
"text": [
"<|start_of_role|>user<|end_of_role|>\n",
"User: Everyone in my meeting just sees a black screen when I share.\n",
"Agent: Sorry about that\u2014are you sharing a window or your entire screen?\n",
"Agent: Sorry about that—are you sharing a window or your entire screen?\n",
"User: Entire screen on macOS Sonoma.\n",
"Agent: Thanks. Do you have \u201cEnable hardware acceleration\u201d toggled on in Settings \u2192 Video?\n",
"Agent: Thanks. Do you have “Enable hardware acceleration toggled on in Settings Video?\n",
"User: Yeah, that switch is on.\n",
"Agent: Could you try toggling it off and start a quick test share?\n",
"User: Did that\u2014still black for attendees.\n",
"User: Did that—still black for attendees.\n",
"Agent: Understood. Are you on the desktop app v5.4.2 or the browser client?\n",
"User: Desktop v5.4.2\u2014just updated this morning.\n",
"User: Desktop v5.4.2—just updated this morning.\n",
"<|end_of_text|>\n",
"<|start_of_role|>assistant<|end_of_role|>#### Analysis\n",
"- The user reports a black screen for attendees when sharing the entire screen on macOS Sonoma.\n",
"- The user has \"Enable hardware acceleration\" enabled in Settings \u2192 Video.\n",
"- The user has \"Enable hardware acceleration\" enabled in Settings Video.\n",
"- The user is on the desktop app v5.4.2, which was updated this morning.\n",
"\n",
"#### Recommendation\n",
Expand Down Expand Up @@ -1307,14 +1343,14 @@
"output_type": "stream",
"text": [
"<|start_of_role|>user<|end_of_role|>\n",
"User: I changed the batteries, but the lock app still says 5 % and won\u2019t auto-lock.\n",
"Agent: Let\u2019s check firmware. In the app, go to Settings \u2192 Device Info\u2014what version shows?\n",
"User: I changed the batteries, but the lock app still says 5 % and won’t auto-lock.\n",
"Agent: Let’s check firmware. In the app, go to Settings Device Info—what version shows?\n",
"User: 3.18.0-alpha.\n",
"Agent: Latest stable is 3.17.5. Did you enroll in the beta program?\n",
"User: I might have months ago.\n",
"Agent: Beta builds sometimes misreport battery. Remove one battery, wait ten seconds, reinsert, and watch the LED pattern.\n",
"User: LED blinks blue twice, then red once.\n",
"Agent: That blink code means \u201cconfig mismatch.\u201d Do you still have the old batteries handy?\n",
"Agent: That blink code means “config mismatch. Do you still have the old batteries handy?\n",
"User: Tossed them already.\n",
"<|end_of_text|>\n",
"<|start_of_role|>assistant<|end_of_role|>#### Analysis\n",
Expand Down Expand Up @@ -1557,9 +1593,10 @@
" <a href=\"https://discord.gg/unsloth\"><img src=\"https://github.com/unslothai/unsloth/raw/main/images/Discord.png\" width=\"145\"></a>\n",
" <a href=\"https://docs.unsloth.ai/\"><img src=\"https://github.com/unslothai/unsloth/blob/main/images/documentation%20green%20button.png?raw=true\" width=\"125\"></a>\n",
"\n",
" Join Discord if you need help + \u2b50\ufe0f <i>Star us on <a href=\"https://github.com/unslothai/unsloth\">Github</a> </i> \u2b50\ufe0f\n",
" Join Discord if you need help + ⭐️ <i>Star us on <a href=\"https://github.com/unslothai/unsloth\">Github</a> </i> ⭐️\n",
"</div>\n",
"\n This notebook and all Unsloth notebooks are licensed [LGPL-3.0](https://github.com/unslothai/notebooks?tab=LGPL-3.0-1-ov-file#readme).\n"
"\n",
" This notebook and all Unsloth notebooks are licensed [LGPL-3.0](https://github.com/unslothai/notebooks?tab=LGPL-3.0-1-ov-file#readme).\n"
]
}
],
Expand Down Expand Up @@ -1671,9 +1708,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_bb63137aa20041759b8f2db481107170",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_2f4909b235b648c0942daaa1ae2d84f3",
"value": "\u2007504/504\u2007[00:00&lt;00:00,\u20075262.29\u2007examples/s]"
"value": " 504/504[00:00&lt;00:00, 5262.29 examples/s]"
}
},
"0e91915212da4b699568b2931b2563c1": {
Expand Down Expand Up @@ -2276,9 +2313,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_107ed420bf174d149ff7b64dd1d15c43",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_e709b2fe6ad541579acaa430c862fb3f",
"value": "Map\u2007(num_proc=2):\u2007100%"
"value": "Map(num_proc=2): 100%"
}
},
"66cc062d92924dbc9d91896352347e34": {
Expand All @@ -2297,9 +2334,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_4b73f84a06754e5d8fc832e20a693695",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_fa69243ce6de4eafbcdb7c34a23ee5b5",
"value": "\u2007504/504\u2007[00:04&lt;00:00,\u2007151.17\u2007examples/s]"
"value": " 504/504[00:04&lt;00:00, 151.17 examples/s]"
}
},
"67cd1b3132444520a8794adfcc44c223": {
Expand Down Expand Up @@ -2466,9 +2503,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_9481dda959ee4436b42e8c6c923231d0",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_8bf2866db80d4a5797b6f9edceea1a67",
"value": "\u20071.04M/1.04M\u2007[00:00&lt;00:00,\u200715.5MB/s]"
"value": " 1.04M/1.04M[00:00&lt;00:00, 15.5MB/s]"
}
},
"8bf2866db80d4a5797b6f9edceea1a67": {
Expand Down Expand Up @@ -2710,9 +2747,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_3749d01cb5834e479232b55150dc024e",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_0fc8224771044c749e66770d939ca1cd",
"value": "Map:\u2007100%"
"value": "Map: 100%"
}
},
"9de4b3e3ec324af8be09fcc99c35a7f9": {
Expand Down Expand Up @@ -3087,9 +3124,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_74de35f7e7824f39abb1a7dd37ab8669",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_91f0a47939ff4891808591fa9df9ce6c",
"value": "\u2007504/504\u2007[00:00&lt;00:00,\u20071000.60\u2007examples/s]"
"value": " 504/504[00:00&lt;00:00, 1000.60 examples/s]"
}
},
"c7777936dc2e41568bc2649bb02a763b": {
Expand All @@ -3108,9 +3145,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_a17bf82d1ad9468dbdbad8038f4715cc",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_2d2bf2089a4343fcbce758086e216f34",
"value": "Generating\u2007train\u2007split:\u2007"
"value": "Generating train split: "
}
},
"c9da52df017244ab8d0767fc6b091996": {
Expand Down Expand Up @@ -3196,9 +3233,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_96334dca3a004ddeae99af2304c25b30",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_8daa961157694497a8ca1bb1c4bcff0b",
"value": "Unsloth:\u2007Tokenizing\u2007[&quot;text&quot;]\u2007(num_proc=6):\u2007100%"
"value": "Unsloth: Tokenizing [&quot;text&quot;](num_proc=6): 100%"
}
},
"ccc811b8517e4b568a91ae9d24131512": {
Expand Down Expand Up @@ -3232,9 +3269,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_fea9c1a564d1482fbb2d4c9db0249bfa",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_cfd5bf250f334e19b8cc1bc217bf33f7",
"value": "Loading\u2007checkpoint\u2007shards:\u2007100%"
"value": "Loading checkpoint shards: 100%"
}
},
"cfd5bf250f334e19b8cc1bc217bf33f7": {
Expand Down Expand Up @@ -3320,9 +3357,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_c9da52df017244ab8d0767fc6b091996",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_ccc811b8517e4b568a91ae9d24131512",
"value": "\u20072/2\u2007[00:24&lt;00:00,\u200711.00s/it]"
"value": " 2/2 [00:24&lt;00:00, 11.00s/it]"
}
},
"e0d6a5c340d749479c1d94adf17bb981": {
Expand Down Expand Up @@ -3463,9 +3500,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_b9f552bcbccf42dca02a5ccdfd5eb871",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_2b6eb0208d664e79be39927c02788eed",
"value": "\u2007504/0\u2007[00:00&lt;00:00,\u20073719.61\u2007examples/s]"
"value": " 504/0 [00:00&lt;00:00, 3719.61 examples/s]"
}
},
"fc8739e60d6844669a51a137c48a6218": {
Expand All @@ -3484,9 +3521,9 @@
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_3d728fdd8eb24ed09a0ea06e58db01e3",
"placeholder": "\u200b",
"placeholder": "",
"style": "IPY_MODEL_cab523c6b34d48af9d6f52c62ff64a64",
"value": "Downloading\u2007data:\u2007100%"
"value": "Downloading data: 100%"
}
},
"fea9c1a564d1482fbb2d4c9db0249bfa": {
Expand Down Expand Up @@ -3645,4 +3682,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Loading