{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "IqM-T1RTzY6C" }, "source": [ "To run this, press \"*Runtime*\" and press \"*Run all*\" on a **free** Tesla T4 Google Colab instance!\n", "
\n", "\n", "To install Unsloth on your own computer, follow the installation instructions on our Github page [here](https://github.com/unslothai/unsloth?tab=readme-ov-file#-installation-instructions).\n", "\n", "You will learn how to do [data prep](#Data), how to [train](#Train), how to [run the model](#Inference), & [how to save it](#Save) (eg for Llama.cpp).\n", "\n", "**[NEW] Try 2x faster inference in a free Colab for Llama-3.1 8b Instruct [here](https://colab.research.google.com/drive/1T-YBVfnphoVc8E2E854qF3jdia2Ll2W2?usp=sharing)**\n", "\n", "Features in the notebook:\n", "1. Uses Maxime Labonne's [FineTome 100K](https://huggingface.co/datasets/mlabonne/FineTome-100k) dataset.\n", "1. Convert ShareGPT to HuggingFace format via `standardize_sharegpt`\n", "2. Train on Completions / Assistant only via `train_on_responses_only`\n", "3. Unsloth now supports Torch 2.4, all TRL & Xformers versions & Python 3.12!" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "id": "2eSvM9zX_2d3" }, "outputs": [], "source": [ "%%capture\n", "!pip install unsloth\n", "# Also get the latest nightly Unsloth!\n", "!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir --no-deps git+https://github.com/unslothai/unsloth.git" ] }, { "cell_type": "markdown", "metadata": { "id": "r2v_X2fA0Df5" }, "source": [ "* We support Llama, Mistral, Phi-3, Gemma, Yi, DeepSeek, Qwen, TinyLlama, Vicuna, Open Hermes etc\n", "* We support 16bit LoRA or 4bit QLoRA. Both 2x faster.\n", "* `max_seq_length` can be set to anything, since we do automatic RoPE Scaling via [kaiokendev's](https://kaiokendev.github.io/til) method.\n", "* [**NEW**] We make Gemma-2 9b / 27b **2x faster**! See our [Gemma-2 9b notebook](https://colab.research.google.com/drive/1vIrqH5uYDQwsJ4-OO3DErvuv4pBgVwk4?usp=sharing)\n", "* [**NEW**] To finetune and auto export to Ollama, try our [Ollama notebook](https://colab.research.google.com/drive/1WZDi7APtQ9VsvOrQSSC5DDtxq159j8iZ?usp=sharing)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 320, "referenced_widgets": [ "a29682d0394e46eeabddad80a00349f7", "abbe988281f643b29bcbc74a5d8c5fe4", "5f1d65686d1a4602a6ee4c5d13df7818", "59b4df6e930f457cb67a755d90a651a7", "9da93d5b27d947bea044bc1119181d0d", "ba27a4ca72164a06b85c8e58493d75e1", "84f2e2eff5dd44b89b4390e544ea31a9", "3ac8a0c853a6406ea3fb91d9e7ce743b", "c569a6ed0158456ebc2f3c0ed206d73a", "a0c39ec65e674b628219a1dfaa177096", "a5c288c762214c8d93d69d3351f5832f", "81afdcf1237944c2a2b7402662d8a643", "5581073a34c2423db732d3266161ed07", "7b477d93171a4628a536a5d51ede5e7d", "aa18c1a527804c3485881555b4cccaae", "4aa3b4a195f64907aee323b2129d6ada", "cbd6084641454e9c8f4fce020e2476fa", "9ba68f77a0e849949ca1745d68978e1c", "412923ecea3644a381847ce54df4a56a", "ad804015a2154bcca7dc2fcc53caff70", "671467ee73ed43d6865f0af2c8f908e0", "d88b2a3302264b6289a401aafe72c12d", "20f7a9b4bc3542578f9c59adc64cbc4b", "1d9cd463d7ee42d4848661bb1cfefe8a", "641165dcd1ae4d78acdbd79a6d1e8bb7", "b1d640cebe5841b28ab07234c2989414", "2a87255dcbfa45dcbd56a28cc05288bd", "ccea16c679d44ac99847a0032d71b1d5", "4783c67f36244488932c4a2ba6fe1bd7", "b6bb256941f24137b4c696b5c486ef95", "09a8c63c84bf4fbd87a3aebf78bc65f3", "a72a8ba21b674d30b3cd7c019d29f77d", "bd41e0af677847d0bf3c3628aa3bb013", "913d96e92dea4721af1f6c37dfb75b95", "bc5bec8baef3453a8402af85fa23ae61", "29c108f189994f649b8b84a9c3e68901", "6f65e0467ad445fcaea61764b19d27b4", "2a8817c33b0048d3904c9e818ff193ec", "f18cdcec6edb4d57920446ffdea0f0a2", "793edc6cacf34d8d9b798205d6c512bd", "8d310673bfca48eeaa0db3aeb8f9cc6d", "cce78e2bc5f54ffd954019654d5a5f05", "6f95a56ad2ca4fcdaf11da285d0d2a62", "c966ac79c2e04c8f8c9611889f4e2fb6", "17ce7feec43f4e2d9bc863899ee4f94e", "8d28e864ccdf4a4896dfd5c008d0919c", "ad73d99d088642589e399ebc5c4e44c3", "a653bb2556b24770a8215750500b75a4", "fbb10c5128374157a96d09fec3511387", "66d611d034644087bd42856e3eca9a88", "f323a3e2c9ea4a95bd899442db6777ca", "e0b5f80fb558464e8bfb2f5349bf7cff", "83f9b80e5e0a46bfaa55a1d185b81bc7", "dd627e4aabe6470e95161caed0a50100", "984a5053afd5447fb3b670687b151bb4" ] }, "id": "QmUBVEnvCDJv", "outputId": "b63288a8-a0ae-46fe-ecff-0670a9316185" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.\n", "🦥 Unsloth Zoo will now patch everything to make training faster!\n", "==((====))== Unsloth 2024.11.9: Fast Llama patching. Transformers = 4.46.2.\n", " \\\\ /| GPU: Tesla T4. Max memory: 14.748 GB. Platform = Linux.\n", "O^O/ \\_/ \\ Pytorch: 2.5.1+cu121. CUDA = 7.5. CUDA Toolkit = 12.1.\n", "\\ / Bfloat16 = FALSE. FA [Xformers = 0.0.28.post3. FA2 = False]\n", " \"-____-\" Free Apache license: http://github.com/unslothai/unsloth\n", "Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "model.safetensors: 0%| | 0.00/1.03G [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "a29682d0394e46eeabddad80a00349f7" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "generation_config.json: 0%| | 0.00/184 [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "81afdcf1237944c2a2b7402662d8a643" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "tokenizer_config.json: 0%| | 0.00/54.6k [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "20f7a9b4bc3542578f9c59adc64cbc4b" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "tokenizer.json: 0%| | 0.00/9.09M [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "913d96e92dea4721af1f6c37dfb75b95" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "special_tokens_map.json: 0%| | 0.00/454 [00:00, ?B/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "17ce7feec43f4e2d9bc863899ee4f94e" } }, "metadata": {} } ], "source": [ "from unsloth import FastLanguageModel\n", "import torch\n", "max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!\n", "dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+\n", "load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.\n", "\n", "# 4bit pre quantized models we support for 4x faster downloading + no OOMs.\n", "fourbit_models = [\n", " \"unsloth/Meta-Llama-3.1-8B-bnb-4bit\", # Llama-3.1 2x faster\n", " \"unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit\",\n", " \"unsloth/Meta-Llama-3.1-70B-bnb-4bit\",\n", " \"unsloth/Meta-Llama-3.1-405B-bnb-4bit\", # 4bit for 405b!\n", " \"unsloth/Mistral-Small-Instruct-2409\", # Mistral 22b 2x faster!\n", " \"unsloth/mistral-7b-instruct-v0.3-bnb-4bit\",\n", " \"unsloth/Phi-3.5-mini-instruct\", # Phi-3.5 2x faster!\n", " \"unsloth/Phi-3-medium-4k-instruct\",\n", " \"unsloth/gemma-2-9b-bnb-4bit\",\n", " \"unsloth/gemma-2-27b-bnb-4bit\", # Gemma 2x faster!\n", "\n", " \"unsloth/Llama-3.2-1B-bnb-4bit\", # NEW! Llama 3.2 models\n", " \"unsloth/Llama-3.2-1B-Instruct-bnb-4bit\",\n", " \"unsloth/Llama-3.2-3B-bnb-4bit\",\n", " \"unsloth/Llama-3.2-3B-Instruct-bnb-4bit\",\n", "] # More models at https://huggingface.co/unsloth\n", "\n", "model, tokenizer = FastLanguageModel.from_pretrained(\n", " model_name = \"unsloth/Llama-3.2-1B-Instruct-bnb-4bit\", # or choose \"unsloth/Llama-3.2-1B-Instruct\"\n", " max_seq_length = max_seq_length,\n", " dtype = dtype,\n", " load_in_4bit = load_in_4bit,\n", " # token = \"hf_...\", # use one if using gated models like meta-llama/Llama-2-7b-hf\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "dOZ_ZRHNHgPX", "outputId": "8deb0870-17c1-4cf3-89c9-8c163df13608" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Mounted at /content/drive\n" ] } ], "source": [ "\"from google.colab import drive\n", "drive.mount('/content/drive')" ] }, { "cell_type": "markdown", "metadata": { "id": "SXd9bTZd1aaL" }, "source": [ "We now add LoRA adapters so we only need to update 1 to 10% of all parameters!" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "6bZsfBuZDeCL", "outputId": "e254e2ee-bee3-4520-d70b-94e6d348d727" }, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "Unsloth 2024.11.9 patched 16 layers with 16 QKV layers, 16 O layers and 16 MLP layers.\n" ] } ], "source": [ "model = FastLanguageModel.get_peft_model(\n", " model,\n", " r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128\n", " target_modules = [\"q_proj\", \"k_proj\", \"v_proj\", \"o_proj\",\n", " \"gate_proj\", \"up_proj\", \"down_proj\",],\n", " lora_alpha = 16,\n", " lora_dropout = 0, # Supports any, but = 0 is optimized\n", " bias = \"none\", # Supports any, but = \"none\" is optimized\n", " # [NEW] \"unsloth\" uses 30% less VRAM, fits 2x larger batch sizes!\n", " use_gradient_checkpointing = \"unsloth\", # True or \"unsloth\" for very long context\n", " random_state = 3407,\n", " use_rslora = True, # We support rank stabilized LoRA\n", " loftq_config = None, # And LoftQ\n", ")" ] }, { "cell_type": "markdown", "metadata": { "id": "vITh0KVJ10qX" }, "source": [ "\n", "### Data Prep\n", "We now use the `Llama-3.1` format for conversation style finetunes. We use [Maxime Labonne's FineTome-100k](https://huggingface.co/datasets/mlabonne/FineTome-100k) dataset in ShareGPT style. But we convert it to HuggingFace's normal multiturn format `(\"role\", \"content\")` instead of `(\"from\", \"value\")`/ Llama-3 renders multi turn conversations like below:\n", "\n", "```\n", "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n", "\n", "Hello!<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n", "\n", "Hey there! How are you?<|eot_id|><|start_header_id|>user<|end_header_id|>\n", "\n", "I'm great thanks!<|eot_id|>\n", "```\n", "\n", "We use our `get_chat_template` function to get the correct chat template. We support `zephyr, chatml, mistral, llama, alpaca, vicuna, vicuna_old, phi3, llama3` and more." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "id": "LjY75GoYUCB8" }, "outputs": [], "source": [ "from unsloth.chat_templates import get_chat_template\n", "\n", "tokenizer = get_chat_template(\n", " tokenizer,\n", " chat_template = \"llama-3.1\",\n", ")\n", "\n", "def formatting_prompts_func(examples):\n", " convos = examples[\"conversations\"]\n", " texts = [tokenizer.apply_chat_template(convo, tokenize = False, add_generation_prompt = False) for convo in convos]\n", " return { \"text\" : texts, }\n", "pass\n", "\n", "from datasets import load_dataset\n", "dataset = load_dataset(\"mlabonne/FineTome-100k\", split = \"train\") #\"train[:10000]\"" ] }, { "cell_type": "markdown", "metadata": { "id": "K9CBpiISFa6C" }, "source": [ "We now use `standardize_sharegpt` to convert ShareGPT style datasets into HuggingFace's generic format. This changes the dataset from looking like:\n", "```\n", "{\"from\": \"system\", \"value\": \"You are an assistant\"}\n", "{\"from\": \"human\", \"value\": \"What is 2+2?\"}\n", "{\"from\": \"gpt\", \"value\": \"It's 4.\"}\n", "```\n", "to\n", "```\n", "{\"role\": \"system\", \"content\": \"You are an assistant\"}\n", "{\"role\": \"user\", \"content\": \"What is 2+2?\"}\n", "{\"role\": \"assistant\", \"content\": \"It's 4.\"}\n", "```" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 81, "referenced_widgets": [ "039f8b9f542144a08606ec7dd0c94ce8", "a4eebe5d52fc4e78b9d2e6e603a46766", "5086fde5f6ee4c7cb6e2f0062612cb11", "1a407d68e32c47f6acf3c1e034e46ee7", "13891348033343deac25241d312baa78", "3ec772c8e1c9484b93249b2942e7a0c0", "7c1ab1e5f0624e34b9bfc97e32838370", "58396311734f41b3b1acfa61c420680e", "2427429328f84f5b92d6bf95c515a635", "13526476ee3c41c983158a502e824a75", "cac0e01bb5144a199c55f9e6801c62ce", "c6f91eed614c4ea88dfc597115023fa8", "8318e9e5c785478889781734e3b09452", "a8a9e7d1ce7a4989896ce9fedd3b8411", "34678221a3414b6fb95473188735e7fb", "6587b7787ab5482697cb5ddcc26ff3de", "c485116dfe48427ca9d5381a01d44741", "f8a8c69a9a814163864fa3fd1c18035c", "850da0477eb0404084e6bcedcf461c50", "0110c1baa42d4b40834f5962ff22030e", "50be91e8663d4ee3b6a42d47a93c5296", "91a32bb6ca65471f882b843df3f41bab" ] }, "id": "oPXzJZzHEgXe", "outputId": "380203d7-d490-4853-f1d7-8c391a72653b" }, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "Standardizing format: 0%| | 0/10000 [00:00, ? examples/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "039f8b9f542144a08606ec7dd0c94ce8" } }, "metadata": {} }, { "output_type": "display_data", "data": { "text/plain": [ "Map: 0%| | 0/10000 [00:00, ? examples/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "c6f91eed614c4ea88dfc597115023fa8" } }, "metadata": {} } ], "source": [ "from unsloth.chat_templates import standardize_sharegpt\n", "dataset = standardize_sharegpt(dataset)\n", "dataset = dataset.map(formatting_prompts_func, batched = True,)" ] }, { "cell_type": "markdown", "metadata": { "id": "ndDUB23CGAC5" }, "source": [ "We look at how the conversations are structured for item 5:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "background_save": true }, "id": "gGFzmplrEy9I" }, "outputs": [], "source": [ "dataset[5][\"conversations\"]" ] }, { "cell_type": "markdown", "metadata": { "id": "GfzTdMtvGE6w" }, "source": [ "And we see how the chat template transformed these conversations.\n", "\n", "**[Notice]** Llama 3.1 Instruct's default chat template default adds `\"Cutting Knowledge Date: December 2023\\nToday Date: 26 July 2024\"`, so do not be alarmed!" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "background_save": true }, "id": "vhXv0xFMGNKE" }, "outputs": [], "source": [ "dataset[5][\"text\"]" ] }, { "cell_type": "markdown", "metadata": { "id": "idAEIeSQ3xdS" }, "source": [ "\n", "### Train the model\n", "Now let's use Huggingface TRL's `SFTTrainer`! More docs here: [TRL SFT docs](https://huggingface.co/docs/trl/sft_trainer). We do 60 steps to speed things up, but you can set `num_train_epochs=1` for a full run, and turn off `max_steps=None`. We also support TRL's `DPOTrainer`!" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 49, "referenced_widgets": [ "6f1af8d1fc50425eb7aa46db06dd802c", "989ad08775ac4de5bc9be6d44ac45691", "65b3a9c9919245cd975f07c1771b5d35", "5de634c4e9504e5797cf6655a15fbce0", "0ace85934fa34e12b22c9dc1d347ce20", "afb907e8b5a04f5f8111f667c4fbc03c", "a512623a60074f1c8021412a51cf1cdf", "7042b11c6a404ee7b2c3797af9cc52cb", "3ef41b9d980f40e08189ea8c63a34ec6", "32fc8f860eb54e6b8c56c66aa975e074", "0a25c2df5f954b489210d711f275024a" ] }, "id": "95_Nn-89DhsL", "outputId": "a06bfc29-b977-41f7-b3ab-ca510d6607a9" }, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "Generating train split: 0 examples [00:00, ? examples/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "6f1af8d1fc50425eb7aa46db06dd802c" } }, "metadata": {} } ], "source": [ "from trl import SFTTrainer\n", "from transformers import TrainingArguments, DataCollatorForSeq2Seq\n", "from unsloth import is_bfloat16_supported\n", "\n", "# how many epochs will we know how to run?\n", "\n", "trainer = SFTTrainer(\n", " model = model,\n", " tokenizer = tokenizer,\n", " train_dataset = dataset,\n", " dataset_text_field = \"text\",\n", " max_seq_length = max_seq_length,\n", " data_collator = DataCollatorForSeq2Seq(tokenizer = tokenizer),\n", " dataset_num_proc = 2,\n", " packing = True, # Can make training 5x faster for short sequences.\n", " args = TrainingArguments(\n", " per_device_train_batch_size = 8, # old 2\n", " gradient_accumulation_steps = 2,\n", " warmup_steps = 10,\n", " num_train_epochs = 1, # Set this for 1 full training run.\n", " # max_steps = 60,\n", " learning_rate = 2e-4,\n", " fp16 = not is_bfloat16_supported(),\n", " bf16 = is_bfloat16_supported(),\n", " logging_steps = 1,\n", " optim = \"adamw_8bit\",\n", " weight_decay = 0.01,\n", " lr_scheduler_type = \"linear\",\n", " seed = 3407,\n", " output_dir = \"/content/drive/MyDrive/ID2223\", #\"outputs\",\n", " report_to = \"none\", # Use this for WandB etc\n", "\n", " # evaluation_strategy = \"steps\",\n", " logging_dir=\"./logs\",\n", " save_strategy = \"steps\", # Save the model checkpoint every logging step\n", " # eval_steps = 5,\n", " # do_eval = True,\n", " save_steps = 5, # Save every 5 checkpoints\n", " save_total_limit = 2,\n", " ),\n", ")" ] }, { "cell_type": "markdown", "metadata": { "id": "C_sGp5XlG6dq" }, "source": [ "We also use Unsloth's `train_on_completions` method to only train on the assistant outputs and ignore the loss on the user's inputs." ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 49, "referenced_widgets": [ "c25438e9eaab41ad8ebf0f180ec22fed", "90a1ab67ed2240ad91cab336e9df6318", "97b3012cffc34bb3b124cdf8984f1677", "4399cf71925a4ce5b1184c55b59e934d", "c5cc96bb738f48e78b1e9f0eb5f50e52", "da308fef8a6e4e20a6269b3078078f67", "98635efad5674d62ab1c32eb95421a0d", "07eaf1c332394e83bf96fefe9bd61c2c", "3ac6b846dfc54d4b97dcabd9a5003518", "ea8d8596bedf48369dc259b9e2c7a119", "8ea51c024d854c4b97af1ea5049d9ce4" ] }, "id": "juQiExuBG5Bt", "outputId": "8b4307d9-11ac-4d9c-9d6c-73ec2c6c753c" }, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "Map: 0%| | 0/2764 [00:00, ? examples/s]" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "c25438e9eaab41ad8ebf0f180ec22fed" } }, "metadata": {} } ], "source": [ "from unsloth.chat_templates import train_on_responses_only\n", "trainer = train_on_responses_only(\n", " trainer,\n", " instruction_part = \"<|start_header_id|>user<|end_header_id|>\\n\\n\",\n", " response_part = \"<|start_header_id|>assistant<|end_header_id|>\\n\\n\",\n", ")" ] }, { "cell_type": "markdown", "metadata": { "id": "Dv1NBUozV78l" }, "source": [ "We verify masking is actually done:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 143 }, "id": "LtsMVtlkUhja", "outputId": "103cf1d9-cf34-47e2-fdf7-417e989fd02d" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "\". It also handles edge cases where division by zero occurs or the user selects an operation other than division with a second number of zero.<|eot_id|><|eot_id|><|begin_of_text|><|start_header_id|>system<|end_header_id|>\\n\\nCutting Knowledge Date: December 2023\\nToday Date: 26 July 2024\\n\\n<|eot_id|><|start_header_id|>user<|end_header_id|>\\n\\nHow would the mathematical principles evaluate the division operation for an element in a set S = {0}, if it is divided by 0? This inquiry calls for a comprehensive understanding of the principles of division and the ramifications of dividing by 0 on an element in a set.<|eot_id|><|start_header_id|>assistant<|end_header_id|>\\n\\nThe mathematical principles do not evaluate the division operation for an element in a set S = {0}, if it is divided by 0. This is because dividing by 0 is undefined and leads to mathematical inconsistencies.\\n\\nTo understand this concept better, let's consider the basic principles of division. Division is the inverse operation of multiplication. When we divide a number by another number, we are essentially trying to find out how many times the second number can fit into the first number. For example, 10 ÷ 5 = 2, because 5 can fit into 10 two times.\\n\\nHowever, when we try to divide a number by 0, we encounter a problem. There is no number that can fit into 0, any number of times. This is because 0 represents the absence of quantity, and dividing by 0 leads to an undefined result.\\n\\nLet's take a closer look at the division operation for an element in a set S = {0}, if it is divided by 0:\\n\\nS/0 =?\\n\\nSince 0 cannot be divided into any number, the result of this division is undefined. It does not follow any mathematical principles or rules, and it leads to mathematical inconsistencies. For example, if we were to divide 1 by 0 and then multiply it by 0, we would expect the result to be 1, since we multiplied by the inverse of 0 (which is undefined). However, the result would be 0, which is a contradiction.\\n\\nTherefore, we can say that the mathematical principles do not allow the division operation for an element in a set S = {0}, if it is divided by 0, as it leads to undefined and inconsistent results.<|eot_id|><|eot_id|><|begin_of_text|><|start_header_id|>system<|end_header_id|>\\n\\nCutting Knowledge Date: December 2023\\nToday Date: 26 July 2024\\n\\nYou are an unbiased, uncensored, helpful assistant.<|eot_id|><|start_header_id|>user<|end_header_id|>\\n\\nGiven a dataset with a normal distribution, explain how you would use hypothesis testing to determine whether there is a significant difference between two sample means.<|eot_id|><|start_header_id|>assistant<|end_header_id|>\\n\\nHypothesis testing is a statistical method used to make inferences about population parameters based on sample data. In this case, we want to determine whether there is a significant difference between two sample means from the same dataset with a normal distribution.\\n\\nHere are the steps for hypothesis testing to compare two sample means:\\n\\n1. State the null and alternative hypotheses:\\n - Null Hypothesis (H0): There is no significant difference between the two sample means (μ1 = μ2).\\n - Alternative Hypothesis (H1): There is a significant difference between the two sample means (μ1 ≠ μ2).\\n\\n2. Choose a significance level (α):\\n The significance level (commonly set at 0.05) represents the probability of rejecting the null hypothesis when it is true. It determines the threshold for deciding whether the observed difference between the sample means is due to chance or an actual difference in the population means.\\n\\n3. Calculate the test statistic:\\n For comparing two sample means, we can use the t-test statistic if the population standard deviations are unknown. The formula for the t-test statistic is:\\n\\n t = (M1 - M2) / √[(s1²/n1) + (s2²/n2)]\\n\\n where M1 and M2 are the sample means, s1² and s2² are the sample variances, and n1 and n2 are the sample sizes.\\n\\n4. Determine the degrees of freedom (df):\\n For the t-test, the degrees of freedom can be calculated using the following formula:\\n\\n df = n1 + n2 - 2\\n\\n5. Find the critical value(s) and the rejection region(s):\\n Using the chosen significance level (α) and the degrees of freedom (df), look up the critical value(s) in a t-distribution table. This will help you identify the rejection region(s) where, if the test statistic falls into it, you would reject the null hypothesis.\\n\\n6. Compare the test statistic to the critical value(s):\\n - If the test statistic falls within the rejection region(s), reject the null hypothesis (H0) and conclude that there is a significant difference between the two sample means.\\n - If the test statistic does not fall within the rejection region(s), fail to reject the null hypothesis (H0) and conclude that there is no significant difference between the two sample means.\\n\\n7. Calculate the p-value:\\n The p-value represents the probability of observing a test statistic as extreme or more extreme than the one calculated, assuming the null hypothesis is true. You can find the p-value using a t-distribution table or statistical software. If the p-value is less than the chosen significance level (α), reject the null hypothesis.\\n\\n8. Interpret the results:\\n Based on the comparison of the test statistic to the critical value(s) and/or the p-value, make a conclusion about whether there is a significant difference between the two sample means. Remember that failing to reject the null hypothesis does not prove it is true; it only suggests that there is insufficient evidence to support the alternative hypothesis.<|eot_id|><|eot_id|><|begin_of_text|><|start_header_id|>system<|end_header_id|>\\n\\nCutting Knowledge Date: December 2023\\nToday Date: 26 July 2024\\n\\n<|eot_id|><|start_header_id|>user<|end_header_id|>\\n\\nHow can we ensure that the products we create are designed for everyone, regardless of their differences? Explain the concept of inclusive design in a way that a child can understand, and provide examples of how it helps make products better for everyone. Additionally, describe the different tools and methods used in inclusive design that take into account various abilities and needs of users, such as those who may have visual, auditory, or mobility impairments. Give a step-by-step explanation to help children understand the process.<|eot_id|><|start_header_id|>assistant<|end_header_id|>\\n\\nInclusive design means making things that are useful and easy to use for everyone, including people with differences. We want to make sure that no one is left out or feels excluded because they cannot use a product. \\r\\n\\r\\nFor example, when we design a playground, we want to make sure that children of all ages and abilities can play on it. We might add a ramp for someone who uses a wheelchair or make sure the playground equipment is not too tall for younger children. This way, everyone can have fun and play together!\\r\\n\\r\\nThere are many tools and methods used in inclusive design to make sure that everyone's needs are considered. Some examples are:\\r\\n\\r\\n1. Accessibility features: these are features that make it easier for people with disabilities to use a product. For example, closed captioning on a video helps people who are deaf or hard of hearing understand what is being said.\\r\\n\\r\\n2. User testing: this is when we ask people to try out a product and give us feedback. We want to make sure that the product is easy to use for everyone, so we ask people with different abilities to test it.\\r\\n\\r\\n3. Universal design: this is the idea of designing products that can be used by as many people as possible, regardless of their abilities or differences. An example of universal design is a door handle that can be easily opened by someone with a mobility impairment or by someone who is carrying a lot of bags.\\r\\n\\r\\nHere is an example of how inclusive design works:\\r\\n\\r\\nLet's say we are designing a website. We want to make sure that everyone can use it, so we use inclusive design. Here are the steps we take:\\r\\n\\r\\n1. First, we research different abilities and needs that people might have, such as visual or auditory impairments.\\r\\n\\r\\n2. Next, we create different designs for the website that take into account these different abilities and needs. For example, we might create a version of the website with larger text for people who have trouble reading smaller text.\\r\\n\\r\\n3. Then, we ask people to test the different versions of the website and give us feedback.\\r\\n\\r\\n4. Finally, we choose the best design that works well for everyone, regardless of their differences. This way, everyone can use the website easily and without any problems!<|eot_id|><|eot_id|><|begin_of_text|><|start_header_id|>system<|end_header_id|>\\n\\nCutting Knowledge Date: December 2023\\nToday Date: 26 July 2024\\n\\n<|eot_id|><|start_header_id|>user<|end_header_id|>\\n\\nSolve the following math problem step-by-step.\\nSimplify your answer as much as possible. Present your final answer as \\\\boxed{Your Answer}.\\na cylinder with 6 meter radius and 12 meter height is filled to capacity with water. if the content of the cylinder is used to fill several smaller cylinders of 4 meter diameter and 8 meter height, how many smaller cylinders will be filled to capacity?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\\n\\nStep 1: First, let's calculate the volume of the large cylinder. The formula for the volume of a cylinder is V = πr^2h, where r is the radius and h is the height.\\nStep 2: Using the given values, the volume of the large cylinder is V = π * 6^2 * 12 = 1,152π cubic meters.\\nStep 3: Next, let's calculate the volume of each smaller cylinder. Using the same formula, the volume of the smaller cylinder is V = π * 2^2 * 8 = 32π cubic meters.\\nStep 4: To find out how many smaller cylinders can be filled to capacity, divide the volume of the large cylinder by the volume of each smaller cylinder. Number of smaller cylinders = Volume of large cylinder / Volume of each smaller cylinder = 1\"" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 20 } ], "source": [ "tokenizer.decode(trainer.train_dataset[5][\"input_ids\"])" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 143 }, "id": "_rD6fl8EUxnG", "outputId": "3e6ed868-3460-4cd3-b686-b688ed844617" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "\" \\n\\nThe mathematical principles do not evaluate the division operation for an element in a set S = {0}, if it is divided by 0. This is because dividing by 0 is undefined and leads to mathematical inconsistencies.\\n\\nTo understand this concept better, let's consider the basic principles of division. Division is the inverse operation of multiplication. When we divide a number by another number, we are essentially trying to find out how many times the second number can fit into the first number. For example, 10 ÷ 5 = 2, because 5 can fit into 10 two times.\\n\\nHowever, when we try to divide a number by 0, we encounter a problem. There is no number that can fit into 0, any number of times. This is because 0 represents the absence of quantity, and dividing by 0 leads to an undefined result.\\n\\nLet's take a closer look at the division operation for an element in a set S = {0}, if it is divided by 0:\\n\\nS/0 =?\\n\\nSince 0 cannot be divided into any number, the result of this division is undefined. It does not follow any mathematical principles or rules, and it leads to mathematical inconsistencies. For example, if we were to divide 1 by 0 and then multiply it by 0, we would expect the result to be 1, since we multiplied by the inverse of 0 (which is undefined). However, the result would be 0, which is a contradiction.\\n\\nTherefore, we can say that the mathematical principles do not allow the division operation for an element in a set S = {0}, if it is divided by 0, as it leads to undefined and inconsistent results.<|eot_id|><|eot_id|><|begin_of_text|><|start_header_id|>system<|end_header_id|>\\n\\nCutting Knowledge Date: December 2023\\nToday Date: 26 July 2024\\n\\nYou are an unbiased, uncensored, helpful assistant.<|eot_id|> \\n\\nHypothesis testing is a statistical method used to make inferences about population parameters based on sample data. In this case, we want to determine whether there is a significant difference between two sample means from the same dataset with a normal distribution.\\n\\nHere are the steps for hypothesis testing to compare two sample means:\\n\\n1. State the null and alternative hypotheses:\\n - Null Hypothesis (H0): There is no significant difference between the two sample means (μ1 = μ2).\\n - Alternative Hypothesis (H1): There is a significant difference between the two sample means (μ1 ≠ μ2).\\n\\n2. Choose a significance level (α):\\n The significance level (commonly set at 0.05) represents the probability of rejecting the null hypothesis when it is true. It determines the threshold for deciding whether the observed difference between the sample means is due to chance or an actual difference in the population means.\\n\\n3. Calculate the test statistic:\\n For comparing two sample means, we can use the t-test statistic if the population standard deviations are unknown. The formula for the t-test statistic is:\\n\\n t = (M1 - M2) / √[(s1²/n1) + (s2²/n2)]\\n\\n where M1 and M2 are the sample means, s1² and s2² are the sample variances, and n1 and n2 are the sample sizes.\\n\\n4. Determine the degrees of freedom (df):\\n For the t-test, the degrees of freedom can be calculated using the following formula:\\n\\n df = n1 + n2 - 2\\n\\n5. Find the critical value(s) and the rejection region(s):\\n Using the chosen significance level (α) and the degrees of freedom (df), look up the critical value(s) in a t-distribution table. This will help you identify the rejection region(s) where, if the test statistic falls into it, you would reject the null hypothesis.\\n\\n6. Compare the test statistic to the critical value(s):\\n - If the test statistic falls within the rejection region(s), reject the null hypothesis (H0) and conclude that there is a significant difference between the two sample means.\\n - If the test statistic does not fall within the rejection region(s), fail to reject the null hypothesis (H0) and conclude that there is no significant difference between the two sample means.\\n\\n7. Calculate the p-value:\\n The p-value represents the probability of observing a test statistic as extreme or more extreme than the one calculated, assuming the null hypothesis is true. You can find the p-value using a t-distribution table or statistical software. If the p-value is less than the chosen significance level (α), reject the null hypothesis.\\n\\n8. Interpret the results:\\n Based on the comparison of the test statistic to the critical value(s) and/or the p-value, make a conclusion about whether there is a significant difference between the two sample means. Remember that failing to reject the null hypothesis does not prove it is true; it only suggests that there is insufficient evidence to support the alternative hypothesis.<|eot_id|><|eot_id|><|begin_of_text|><|start_header_id|>system<|end_header_id|>\\n\\nCutting Knowledge Date: December 2023\\nToday Date: 26 July 2024\\n\\n<|eot_id|> \\n\\nInclusive design means making things that are useful and easy to use for everyone, including people with differences. We want to make sure that no one is left out or feels excluded because they cannot use a product. \\r\\n\\r\\nFor example, when we design a playground, we want to make sure that children of all ages and abilities can play on it. We might add a ramp for someone who uses a wheelchair or make sure the playground equipment is not too tall for younger children. This way, everyone can have fun and play together!\\r\\n\\r\\nThere are many tools and methods used in inclusive design to make sure that everyone's needs are considered. Some examples are:\\r\\n\\r\\n1. Accessibility features: these are features that make it easier for people with disabilities to use a product. For example, closed captioning on a video helps people who are deaf or hard of hearing understand what is being said.\\r\\n\\r\\n2. User testing: this is when we ask people to try out a product and give us feedback. We want to make sure that the product is easy to use for everyone, so we ask people with different abilities to test it.\\r\\n\\r\\n3. Universal design: this is the idea of designing products that can be used by as many people as possible, regardless of their abilities or differences. An example of universal design is a door handle that can be easily opened by someone with a mobility impairment or by someone who is carrying a lot of bags.\\r\\n\\r\\nHere is an example of how inclusive design works:\\r\\n\\r\\nLet's say we are designing a website. We want to make sure that everyone can use it, so we use inclusive design. Here are the steps we take:\\r\\n\\r\\n1. First, we research different abilities and needs that people might have, such as visual or auditory impairments.\\r\\n\\r\\n2. Next, we create different designs for the website that take into account these different abilities and needs. For example, we might create a version of the website with larger text for people who have trouble reading smaller text.\\r\\n\\r\\n3. Then, we ask people to test the different versions of the website and give us feedback.\\r\\n\\r\\n4. Finally, we choose the best design that works well for everyone, regardless of their differences. This way, everyone can use the website easily and without any problems!<|eot_id|><|eot_id|><|begin_of_text|><|start_header_id|>system<|end_header_id|>\\n\\nCutting Knowledge Date: December 2023\\nToday Date: 26 July 2024\\n\\n<|eot_id|> \\n\\nStep 1: First, let's calculate the volume of the large cylinder. The formula for the volume of a cylinder is V = πr^2h, where r is the radius and h is the height.\\nStep 2: Using the given values, the volume of the large cylinder is V = π * 6^2 * 12 = 1,152π cubic meters.\\nStep 3: Next, let's calculate the volume of each smaller cylinder. Using the same formula, the volume of the smaller cylinder is V = π * 2^2 * 8 = 32π cubic meters.\\nStep 4: To find out how many smaller cylinders can be filled to capacity, divide the volume of the large cylinder by the volume of each smaller cylinder. Number of smaller cylinders = Volume of large cylinder / Volume of each smaller cylinder = 1\"" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" } }, "metadata": {}, "execution_count": 21 } ], "source": [ "space = tokenizer(\" \", add_special_tokens = False).input_ids[0]\n", "tokenizer.decode([space if x == -100 else x for x in trainer.train_dataset[5][\"labels\"]])" ] }, { "cell_type": "markdown", "metadata": { "id": "3enWUM0jV-jV" }, "source": [ "We can see the System and Instruction prompts are successfully masked!" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "2ejIt2xSNKKp", "outputId": "a55aec07-c556-43f4-8d5a-17768e8a031e" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "GPU = Tesla T4. Max memory = 14.748 GB.\n", "3.619 GB of memory reserved.\n" ] } ], "source": [ "#@title Show current memory stats\n", "gpu_stats = torch.cuda.get_device_properties(0)\n", "start_gpu_memory = round(torch.cuda.max_memory_reserved() / 1024 / 1024 / 1024, 3)\n", "max_memory = round(gpu_stats.total_memory / 1024 / 1024 / 1024, 3)\n", "print(f\"GPU = {gpu_stats.name}. Max memory = {max_memory} GB.\")\n", "print(f\"{start_gpu_memory} GB of memory reserved.\")" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 911 }, "id": "yqxqAZ7KJ4oL", "outputId": "b175edf4-1a95-476c-e694-48eaa0a36939" }, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "==((====))== Unsloth - 2x faster free finetuning | Num GPUs = 1\n", " \\\\ /| Num examples = 2,764 | Num Epochs = 1\n", "O^O/ \\_/ \\ Batch size per device = 8 | Gradient Accumulation steps = 4\n", "\\ / Total batch size = 32 | Total steps = 86\n", " \"-____-\" Number of trainable parameters = 11,272,192\n" ] }, { "output_type": "display_data", "data": { "text/plain": [ "Step | \n", "Training Loss | \n", "
---|---|
1 | \n", "0.999500 | \n", "
2 | \n", "1.019900 | \n", "
3 | \n", "1.033200 | \n", "
4 | \n", "0.972300 | \n", "
5 | \n", "0.914400 | \n", "
6 | \n", "0.987300 | \n", "
7 | \n", "0.992800 | \n", "
8 | \n", "0.977100 | \n", "
9 | \n", "1.050300 | \n", "
10 | \n", "0.949200 | \n", "
11 | \n", "0.932900 | \n", "
12 | \n", "0.968300 | \n", "
13 | \n", "0.881700 | \n", "
14 | \n", "1.035500 | \n", "
15 | \n", "0.929700 | \n", "
"
]
},
"metadata": {}
},
{
"output_type": "error",
"ename": "KeyboardInterrupt",
"evalue": "",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m