{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "o6RxqIirisTj" }, "source": [ "Thanks to Unsloth this notebook can run on free Colab T4 instances.\n", "\n", "This notebook is tested on Runpod.\n", "\n", "- Image: `runpod/pytorch\n", ":2.1.0-py3.10-cuda11.8.0-devel-ubuntu22.04`\n", "- GPU: `NVIDIA RTX3090` for $0.26/hr" ] }, { "cell_type": "markdown", "source": [ "Run the next 2 cells to install Unsloth and its dependencies for Runpod, or the one after for Colab." ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git\n", " Cloning https://github.com/unslothai/unsloth.git to /tmp/pip-install-a96gi2s8/unsloth_bbc08fa32528419089350c216e1d50ee\n", " Running command git clone --filter=blob:none --quiet https://github.com/unslothai/unsloth.git /tmp/pip-install-a96gi2s8/unsloth_bbc08fa32528419089350c216e1d50ee\n", " Resolved https://github.com/unslothai/unsloth.git to commit dbba69b085b9d6049b57b48b882af7e9f29df5b2\n", " Installing build dependencies ... \u001B[?25ldone\n", "\u001B[?25h Getting requirements to build wheel ... \u001B[?25ldone\n", "\u001B[?25h Installing backend dependencies ... \u001B[?25ldone\n", "\u001B[?25h Preparing metadata (pyproject.toml) ... \u001B[?25ldone\n", "\u001B[?25hCollecting bitsandbytes (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading bitsandbytes-0.42.0-py3-none-any.whl.metadata (9.9 kB)\n", "Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (23.2)\n", "Collecting ninja (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading ninja-1.11.1.1-py2.py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.whl.metadata (5.3 kB)\n", "Collecting flash-attn (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading flash_attn-2.5.5.tar.gz (2.5 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m2.5/2.5 MB\u001B[0m \u001B[31m15.8 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0ma \u001B[36m0:00:01\u001B[0m\n", "\u001B[?25h Preparing metadata (setup.py) ... \u001B[?25ldone\n", "\u001B[?25hCollecting scipy (from bitsandbytes->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading scipy-1.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m60.4/60.4 kB\u001B[0m \u001B[31m4.3 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hRequirement already satisfied: torch in /usr/local/lib/python3.10/dist-packages (from flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (2.1.0+cu118)\n", "Collecting einops (from flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading einops-0.7.0-py3-none-any.whl.metadata (13 kB)\n", "Collecting xformers@ https://download.pytorch.org/whl/cu118/xformers-0.0.22.post7%2Bcu118-cp310-cp310-manylinux2014_x86_64.whl (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading https://download.pytorch.org/whl/cu118/xformers-0.0.22.post7%2Bcu118-cp310-cp310-manylinux2014_x86_64.whl (211.5 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m211.5/211.5 MB\u001B[0m \u001B[31m21.4 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m00:01\u001B[0m\n", "\u001B[?25hCollecting transformers>=4.38.0 (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading transformers-4.38.1-py3-none-any.whl.metadata (131 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m131.1/131.1 kB\u001B[0m \u001B[31m9.8 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hCollecting datasets (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading datasets-2.17.1-py3-none-any.whl.metadata (20 kB)\n", "Collecting sentencepiece (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading sentencepiece-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (7.7 kB)\n", "Collecting accelerate>=0.26.1 (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading accelerate-0.27.2-py3-none-any.whl.metadata (18 kB)\n", "Collecting trl>=0.7.9 (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading trl-0.7.11-py3-none-any.whl.metadata (10 kB)\n", "Collecting peft>=0.7.1 (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading peft-0.9.0-py3-none-any.whl.metadata (13 kB)\n", "Collecting tqdm (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading tqdm-4.66.2-py3-none-any.whl.metadata (57 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m57.6/57.6 kB\u001B[0m \u001B[31m8.7 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hRequirement already satisfied: psutil in /usr/local/lib/python3.10/dist-packages (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (5.9.6)\n", "Collecting wheel>=0.42.0 (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Using cached wheel-0.42.0-py3-none-any.whl.metadata (2.2 kB)\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (1.24.1)\n", "Requirement already satisfied: pyyaml in /usr/local/lib/python3.10/dist-packages (from accelerate>=0.26.1->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (6.0.1)\n", "Collecting huggingface-hub (from accelerate>=0.26.1->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading huggingface_hub-0.21.2-py3-none-any.whl.metadata (13 kB)\n", "Collecting safetensors>=0.3.1 (from accelerate>=0.26.1->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading safetensors-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.8 kB)\n", "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch->flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (3.9.0)\n", "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from torch->flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (4.4.0)\n", "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch->flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (1.12)\n", "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch->flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (3.0)\n", "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch->flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (3.1.2)\n", "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch->flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (2023.4.0)\n", "Requirement already satisfied: triton==2.1.0 in /usr/local/lib/python3.10/dist-packages (from torch->flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (2.1.0)\n", "Collecting regex!=2019.12.17 (from transformers>=4.38.0->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading regex-2023.12.25-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (40 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m40.9/40.9 kB\u001B[0m \u001B[31m2.9 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hRequirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from transformers>=4.38.0->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (2.31.0)\n", "Collecting tokenizers<0.19,>=0.14 (from transformers>=4.38.0->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading tokenizers-0.15.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.7 kB)\n", "Collecting tyro>=0.5.11 (from trl>=0.7.9->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading tyro-0.7.3-py3-none-any.whl.metadata (7.7 kB)\n", "Collecting pyarrow>=12.0.0 (from datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading pyarrow-15.0.0-cp310-cp310-manylinux_2_28_x86_64.whl.metadata (3.0 kB)\n", "Collecting pyarrow-hotfix (from datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading pyarrow_hotfix-0.6-py3-none-any.whl.metadata (3.6 kB)\n", "Collecting dill<0.3.9,>=0.3.0 (from datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading dill-0.3.8-py3-none-any.whl.metadata (10 kB)\n", "Collecting pandas (from datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading pandas-2.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (19 kB)\n", "Collecting xxhash (from datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading xxhash-3.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (12 kB)\n", "Collecting multiprocess (from datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading multiprocess-0.70.16-py310-none-any.whl.metadata (7.2 kB)\n", "Collecting aiohttp (from datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading aiohttp-3.9.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (7.4 kB)\n", "Collecting aiosignal>=1.1.2 (from aiohttp->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading aiosignal-1.3.1-py3-none-any.whl.metadata (4.0 kB)\n", "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (23.1.0)\n", "Collecting frozenlist>=1.1.1 (from aiohttp->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading frozenlist-1.4.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (12 kB)\n", "Collecting multidict<7.0,>=4.5 (from aiohttp->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading multidict-6.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.2 kB)\n", "Collecting yarl<2.0,>=1.0 (from aiohttp->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading yarl-1.9.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (31 kB)\n", "Collecting async-timeout<5.0,>=4.0 (from aiohttp->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading async_timeout-4.0.3-py3-none-any.whl.metadata (4.2 kB)\n", "INFO: pip is looking at multiple versions of huggingface-hub to determine which version is compatible with other requirements. This could take a while.\n", "Collecting huggingface-hub (from accelerate>=0.26.1->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading huggingface_hub-0.21.1-py3-none-any.whl.metadata (13 kB)\n", " Downloading huggingface_hub-0.21.0-py3-none-any.whl.metadata (13 kB)\n", " Downloading huggingface_hub-0.20.3-py3-none-any.whl.metadata (12 kB)\n", " Downloading huggingface_hub-0.20.2-py3-none-any.whl.metadata (12 kB)\n", " Downloading huggingface_hub-0.20.1-py3-none-any.whl.metadata (12 kB)\n", " Downloading huggingface_hub-0.20.0-py3-none-any.whl.metadata (12 kB)\n", " Downloading huggingface_hub-0.19.4-py3-none-any.whl.metadata (14 kB)\n", "INFO: pip is still looking at multiple versions of huggingface-hub to determine which version is compatible with other requirements. This could take a while.\n", "Collecting fsspec[http]<=2023.10.0,>=2023.1.0 (from datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading fsspec-2023.10.0-py3-none-any.whl.metadata (6.8 kB)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->transformers>=4.38.0->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (2.1.1)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->transformers>=4.38.0->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (3.4)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->transformers>=4.38.0->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (1.26.13)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->transformers>=4.38.0->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (2022.12.7)\n", "Collecting docstring-parser>=0.14.1 (from tyro>=0.5.11->trl>=0.7.9->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading docstring_parser-0.15-py3-none-any.whl.metadata (2.4 kB)\n", "Collecting rich>=11.1.0 (from tyro>=0.5.11->trl>=0.7.9->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading rich-13.7.1-py3-none-any.whl.metadata (18 kB)\n", "Collecting shtab>=1.5.6 (from tyro>=0.5.11->trl>=0.7.9->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading shtab-1.7.0-py3-none-any.whl.metadata (7.3 kB)\n", "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch->flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (2.1.2)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (2.8.2)\n", "Collecting pytz>=2020.1 (from pandas->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading pytz-2024.1-py2.py3-none-any.whl.metadata (22 kB)\n", "Collecting tzdata>=2022.7 (from pandas->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading tzdata-2024.1-py2.py3-none-any.whl.metadata (1.4 kB)\n", "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch->flash-attn->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (1.3.0)\n", "Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.8.2->pandas->datasets->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (1.16.0)\n", "Collecting markdown-it-py>=2.2.0 (from rich>=11.1.0->tyro>=0.5.11->trl>=0.7.9->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading markdown_it_py-3.0.0-py3-none-any.whl.metadata (6.9 kB)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich>=11.1.0->tyro>=0.5.11->trl>=0.7.9->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git) (2.16.1)\n", "Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich>=11.1.0->tyro>=0.5.11->trl>=0.7.9->unsloth[cu118-ampere]@ git+https://github.com/unslothai/unsloth.git)\n", " Downloading mdurl-0.1.2-py3-none-any.whl.metadata (1.6 kB)\n", "Downloading bitsandbytes-0.42.0-py3-none-any.whl (105.0 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m105.0/105.0 MB\u001B[0m \u001B[31m48.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m00:01\u001B[0m\n", "\u001B[?25hDownloading ninja-1.11.1.1-py2.py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.whl (307 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m307.2/307.2 kB\u001B[0m \u001B[31m45.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading accelerate-0.27.2-py3-none-any.whl (279 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m280.0/280.0 kB\u001B[0m \u001B[31m38.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading peft-0.9.0-py3-none-any.whl (190 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m190.9/190.9 kB\u001B[0m \u001B[31m26.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading transformers-4.38.1-py3-none-any.whl (8.5 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m8.5/8.5 MB\u001B[0m \u001B[31m88.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0mta \u001B[36m0:00:01\u001B[0m\n", "\u001B[?25hDownloading tqdm-4.66.2-py3-none-any.whl (78 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m78.3/78.3 kB\u001B[0m \u001B[31m13.3 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading trl-0.7.11-py3-none-any.whl (155 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m155.3/155.3 kB\u001B[0m \u001B[31m26.0 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hUsing cached wheel-0.42.0-py3-none-any.whl (65 kB)\n", "Downloading datasets-2.17.1-py3-none-any.whl (536 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m536.7/536.7 kB\u001B[0m \u001B[31m58.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading einops-0.7.0-py3-none-any.whl (44 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m44.6/44.6 kB\u001B[0m \u001B[31m6.4 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading scipy-1.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (38.4 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m38.4/38.4 MB\u001B[0m \u001B[31m75.3 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m:00:01\u001B[0m00:01\u001B[0m\n", "\u001B[?25hDownloading sentencepiece-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m1.3/1.3 MB\u001B[0m \u001B[31m92.0 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading dill-0.3.8-py3-none-any.whl (116 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m116.3/116.3 kB\u001B[0m \u001B[31m20.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading fsspec-2023.10.0-py3-none-any.whl (166 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m166.4/166.4 kB\u001B[0m \u001B[31m28.7 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading huggingface_hub-0.21.2-py3-none-any.whl (346 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m346.2/346.2 kB\u001B[0m \u001B[31m51.8 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading aiohttp-3.9.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m1.2/1.2 MB\u001B[0m \u001B[31m90.7 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading pyarrow-15.0.0-cp310-cp310-manylinux_2_28_x86_64.whl (38.3 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m38.3/38.3 MB\u001B[0m \u001B[31m59.3 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m00:01\u001B[0m\n", "\u001B[?25hDownloading regex-2023.12.25-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (773 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m774.0/774.0 kB\u001B[0m \u001B[31m71.9 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading safetensors-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m1.3/1.3 MB\u001B[0m \u001B[31m90.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading tokenizers-0.15.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m3.6/3.6 MB\u001B[0m \u001B[31m79.0 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0ma \u001B[36m0:00:01\u001B[0m\n", "\u001B[?25hDownloading tyro-0.7.3-py3-none-any.whl (79 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m79.8/79.8 kB\u001B[0m \u001B[31m12.4 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading multiprocess-0.70.16-py310-none-any.whl (134 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m134.8/134.8 kB\u001B[0m \u001B[31m18.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading pandas-2.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m13.0/13.0 MB\u001B[0m \u001B[31m69.4 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m0:01\u001B[0mm\n", "\u001B[?25hDownloading pyarrow_hotfix-0.6-py3-none-any.whl (7.9 kB)\n", "Downloading xxhash-3.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (194 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m194.1/194.1 kB\u001B[0m \u001B[31m25.0 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)\n", "Downloading async_timeout-4.0.3-py3-none-any.whl (5.7 kB)\n", "Downloading docstring_parser-0.15-py3-none-any.whl (36 kB)\n", "Downloading frozenlist-1.4.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m239.5/239.5 kB\u001B[0m \u001B[31m32.7 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading multidict-6.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (124 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m124.3/124.3 kB\u001B[0m \u001B[31m19.3 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading pytz-2024.1-py2.py3-none-any.whl (505 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m505.5/505.5 kB\u001B[0m \u001B[31m66.9 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading rich-13.7.1-py3-none-any.whl (240 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m240.7/240.7 kB\u001B[0m \u001B[31m34.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading shtab-1.7.0-py3-none-any.whl (14 kB)\n", "Downloading tzdata-2024.1-py2.py3-none-any.whl (345 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m345.4/345.4 kB\u001B[0m \u001B[31m48.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading yarl-1.9.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (301 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m301.6/301.6 kB\u001B[0m \u001B[31m39.8 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading markdown_it_py-3.0.0-py3-none-any.whl (87 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m87.5/87.5 kB\u001B[0m \u001B[31m13.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n", "\u001B[?25hDownloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)\n", "Building wheels for collected packages: flash-attn, unsloth\n", " Building wheel for flash-attn (setup.py) ... \u001B[?25ldone\n", "\u001B[?25h Created wheel for flash-attn: filename=flash_attn-2.5.5-cp310-cp310-linux_x86_64.whl size=121429363 sha256=8faeb1ca29684871e2b44d1bac44863f65fdb5b0a45bf8ff1626add02a047d3b\n", " Stored in directory: /root/.cache/pip/wheels/b2/67/52/8b6d5fcffdd9e1ec868f554cdef8f03eedb4bf4dcac852fca2\n", " Building wheel for unsloth (pyproject.toml) ... \u001B[?25ldone\n", "\u001B[?25h Created wheel for unsloth: filename=unsloth-2024.2-py3-none-any.whl size=82614 sha256=ea94790cdecc529d06a8d548b07b1deecd5d53d3451319c87cedeb71f9aaa5e5\n", " Stored in directory: /tmp/pip-ephem-wheel-cache-3ggoyc4_/wheels/ed/d4/e9/76fb290ee3df0a5fc21ce5c2c788e29e9607a2353d8342fd0d\n", "Successfully built flash-attn unsloth\n", "Installing collected packages: sentencepiece, pytz, ninja, xxhash, wheel, unsloth, tzdata, tqdm, shtab, scipy, safetensors, regex, pyarrow-hotfix, pyarrow, multidict, mdurl, fsspec, frozenlist, einops, docstring-parser, dill, async-timeout, yarl, pandas, multiprocess, markdown-it-py, huggingface-hub, bitsandbytes, aiosignal, xformers, tokenizers, rich, flash-attn, aiohttp, accelerate, tyro, transformers, peft, datasets, trl\n", " Attempting uninstall: wheel\n", " Found existing installation: wheel 0.41.3\n", " Uninstalling wheel-0.41.3:\n", " Successfully uninstalled wheel-0.41.3\n", " Attempting uninstall: fsspec\n", " Found existing installation: fsspec 2023.4.0\n", " Uninstalling fsspec-2023.4.0:\n", " Successfully uninstalled fsspec-2023.4.0\n", "Successfully installed accelerate-0.27.2 aiohttp-3.9.3 aiosignal-1.3.1 async-timeout-4.0.3 bitsandbytes-0.42.0 datasets-2.17.1 dill-0.3.8 docstring-parser-0.15 einops-0.7.0 flash-attn-2.5.5 frozenlist-1.4.1 fsspec-2023.10.0 huggingface-hub-0.21.2 markdown-it-py-3.0.0 mdurl-0.1.2 multidict-6.0.5 multiprocess-0.70.16 ninja-1.11.1.1 pandas-2.2.1 peft-0.9.0 pyarrow-15.0.0 pyarrow-hotfix-0.6 pytz-2024.1 regex-2023.12.25 rich-13.7.1 safetensors-0.4.2 scipy-1.12.0 sentencepiece-0.2.0 shtab-1.7.0 tokenizers-0.15.2 tqdm-4.66.2 transformers-4.38.1 trl-0.7.11 tyro-0.7.3 tzdata-2024.1 unsloth-2024.2 wheel-0.42.0 xformers-0.0.22.post7+cu118 xxhash-3.4.1 yarl-1.9.4\n", "\u001B[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001B[0m\u001B[33m\n", "\u001B[0m\n", "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m23.3.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m24.0\u001B[0m\n", "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpython -m pip install --upgrade pip\u001B[0m\n" ] } ], "source": [ "!pip install \"unsloth[cu118-ampere] @ git+https://github.com/unslothai/unsloth.git\"" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting protobuf\n", " Downloading protobuf-4.25.3-cp37-abi3-manylinux2014_x86_64.whl.metadata (541 bytes)\n", "Downloading protobuf-4.25.3-cp37-abi3-manylinux2014_x86_64.whl (294 kB)\n", "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m294.6/294.6 kB\u001B[0m \u001B[31m3.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0ma \u001B[36m0:00:01\u001B[0m\n", "\u001B[?25hInstalling collected packages: protobuf\n", "Successfully installed protobuf-4.25.3\n", "\u001B[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001B[0m\u001B[33m\n", "\u001B[0m\n", "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m23.3.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m24.0\u001B[0m\n", "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpython -m pip install --upgrade pip\u001B[0m\n" ] } ], "source": [ "!pip install protobuf" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "id": "2eSvM9zX_2d3" }, "outputs": [], "source": [ "## For Colab, use this cell instead of the above 2 cells\n", "%%capture\n", "import torch\n", "major_version, minor_version = torch.cuda.get_device_capability()\n", "if major_version >= 8:\n", " # Use this for new GPUs like Ampere, Hopper GPUs (RTX 30xx, RTX 40xx, A100, H100, L40)\n", " !pip install \"unsloth[colab-ampere] @ git+https://github.com/unslothai/unsloth.git\"\n", "else:\n", " # Use this for older GPUs (V100, Tesla T4, RTX 20xx)\n", " !pip install \"unsloth[colab] @ git+https://github.com/unslothai/unsloth.git\"\n", "pass" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "E8-BWi7MzkRz", "outputId": "3c2ac545-fdf6-41ab-8f25-f7c0b1a6b7df" }, "outputs": [], "source": [ "# One must patch the DPO Trainer first!\n", "from unsloth import PatchDPOTrainer\n", "PatchDPOTrainer()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# This done to save model download time in Runpod\n", "import os\n", "os.environ['TRANSFORMERS_CACHE']=\"/workspace/cache\"" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 383, "referenced_widgets": [ "15a973259d4b44fb927ab6f90558a67b", "e50bab4535214a33876e82fc723aba36", "e440224790d84f9a970e24e09677b358", "126b051df9a94212a3eb795da94202b9", "44275ae9daf54ae7912cf624e4072988", "43ec90294d174b55ac9125570e67390b", "5558e381bcf14c85800a9f6a60db245f", "c5b88871eb594318a242bd2cacac3ebf", "7bd55b67cbc74517ae7c8963734dd4ec", "0cc00b9da0844590a03178c433f80546", "e0d3a2ca3b624df39f49e5b68c624ffc", "0f5f3245e7e84b78bfd694c8598bbc0d", "7cf09a9e07f84a0b8e14ababea33397f", "0cfe63f655c2462abaf5f63b71c10999", "8af545abdca14e5ea7e8ea1f0cb912c3", "99dcfb9374464eb9a0eb70b3309ac135", "28c22816c978415c923f362faf4b337a", "99946db965b94adfa9985deabf7c0df3", "0e72bd2777174f1c9e4e875446078b93", "dcf840ac14664da68560209fbd70ee89", "b47efe2277ac4e0da48e9b2b413462af", "a9b982a7b601457388726a733c4f6ff4", "3d8f3fc569d44c51a99b3038518ca8e2", "70c1d7567da549209ab9ae2edf1f9281", "518e4e76da204ee9b788f5b55fe45481", "97543f8e3fbc47209fdfcb6277b70d69", "6994b71a1a8f4b69a8c4067ed724a614", "f61f781a6f1b4a64869dd9ec8ca535c6", "e576602d281a4fafabcb75f2b1982cc8", "95b08ac9a6f34ae9a751baae30a0d157", "ad5e7439882446318106548f16ae9ecc", "b11f2f32d6a7491ca66cb55cea8415f5", "2569b25a50e04c0ca75a412d70fe427e", "bf98441686744c69ba87d8971df488dc", "3cc5ee93be08486b8c0d3cdf539339bc", "c8c2bbfeab4543b8b56d9b5ea3fc6ef7", "14ba3e2104464f3b95382a9e19e0b33e", "9b8f527a2a99480db59633bf914e53da", "68d2acc803c34054bc364c59ac6e711d", "677f568c77c84fe8946c56370e1b9604", "7e189a2138a64260a583cb038110619f", "3fa4f343f18a42f1b4fb97e6a39a118d", "718b82c54f7142739742a203e86597a1", "0d05591bfe244c60bc04a9ab7a2efe3c", "336128f9ff7948d3aa47f4b3d260427e", "6ef14c55233f4decafa572788420fc63", "3ca46749427c40f88606776d5209be2a", "850e1e3ef2584991a437ab26de692683", "6473291994474e3383440ff2f7363c83", "2babdc60af7542ae888558824d87c18a", "8e8daeb77627417a95cb4b1e85c11404", "f2acf2cfcc5245a7b2e963156a3118e8", "b81da86fd9b34ffabe63328b47ce0e7c", "1365c26a079c401982eb8f018bdb0f72", "b70da8ff49ff48adb78981672e1547c9", "0b7e7d3ad8c04a27afb8a00ab9ae5558", "9a07d893edc44b17bfc0dba84dc5fadd", "d01b8dd3dd4442fbbb66607dbe28eeb5", "993f4c1df40444e39e9b1637e7df8fc5", "3186909fbe404aa79d97f9536819d099", "c638a317c20c41718512200c49e08a16", "117f7f951659466c83f71074a85d9e9e", "bb756c5fdb884b7b926ffc43b01da118", "20515c5e2e994baeaebd3ca51fbba943", "cc15bb8ed82e4bf4ac24a8e6428de56c", "700681f8ce7f49c4aa03290c47cd7257", "69ea74f7b6ea499f8acd2cd1b2f77177", "d8e65af631d6429b90d46686276a3a5a", "a869800400d2458189fe24c3695f4c66", "b4b0a29ded2544ebbe6aff3f4a364e7a", "6e7aa23ab2e24b7fbfa12620d1c6c80b", "7fe1735402964808b2d68ee8e5c80041", "392cbbfaea12496e84f5fdcf76194048", "6b2b437dadd54e8bb074caedd109030a", "44b88386034f437aa10faaf75cefa0ef", "d7466ce6b14b4271b49aa423eaa7daa1", "e2d106264b864342b6180909e5c71747" ] }, "id": "QmUBVEnvCDJv", "outputId": "be54f502-375b-41ba-82a9-8b1b20466e56" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "==((====))== Unsloth: Fast Mistral patching release 2024.2\n", " \\\\ /| GPU: NVIDIA GeForce RTX 3090. Max memory: 23.691 GB. Platform = Linux.\n", "O^O/ \\_/ \\ Pytorch: 2.1.0+cu118. CUDA = 8.6. CUDA Toolkit = 11.8.\n", "\\ / Bfloat16 = TRUE. Xformers = 0.0.22.post7+cu118. FA = True.\n", " \"-____-\" Free Apache license: http://github.com/unslothai/unsloth\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ba3e645227204343b86d9c0f4fd36bb9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Loading checkpoint shards: 0%| | 0/2 [00:00, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n", "Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n" ] } ], "source": [ "from unsloth import FastLanguageModel\n", "import torch\n", "max_seq_length = 1024 # Unsloth supports RoPE Scaling so this can be anything. The original\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 but you will probably immediately OOM on anything but A100 80G. DPO takes a lot of memory!\n", "\n", "model, tokenizer = FastLanguageModel.from_pretrained(\n", " model_name = \"teknium/OpenHermes-2.5-Mistral-7B\", # Choose ANY! eg mistralai/Mistral-7B-Instruct-v0.2\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": 5, "metadata": { "cellView": "form", "id": "AqkY_wHdKyOl" }, "outputs": [], "source": [ "#@title Alignment Handbook utils\n", "import os\n", "import re\n", "from typing import List, Literal, Optional\n", "\n", "from datasets import DatasetDict, concatenate_datasets, load_dataset, load_from_disk\n", "from datasets.builder import DatasetGenerationError\n", "\n", "\n", "DEFAULT_CHAT_TEMPLATE = \"{% for message in messages %}\\n{% if message['role'] == 'user' %}\\n{{ '<|user|>\\n' + message['content'] + eos_token }}\\n{% elif message['role'] == 'system' %}\\n{{ '<|system|>\\n' + message['content'] + eos_token }}\\n{% elif message['role'] == 'assistant' %}\\n{{ '<|assistant|>\\n' + message['content'] + eos_token }}\\n{% endif %}\\n{% if loop.last and add_generation_prompt %}\\n{{ '<|assistant|>' }}\\n{% endif %}\\n{% endfor %}\"\n", "\n", "\n", "def apply_chat_template(\n", " example, tokenizer, task: Literal[\"sft\", \"generation\", \"rm\", \"dpo\"] = \"sft\", assistant_prefix=\"<|assistant|>\\n\"\n", "):\n", " def _strip_prefix(s, pattern):\n", " # Use re.escape to escape any special characters in the pattern\n", " return re.sub(f\"^{re.escape(pattern)}\", \"\", s)\n", "\n", " if task in [\"sft\", \"generation\"]:\n", " messages = example[\"messages\"]\n", " # We add an empty system message if there is none\n", " if messages[0][\"role\"] != \"system\":\n", " messages.insert(0, {\"role\": \"system\", \"content\": \"\"})\n", " example[\"text\"] = tokenizer.apply_chat_template(\n", " messages, tokenize=False, add_generation_prompt=True if task == \"generation\" else False\n", " )\n", " elif task == \"rm\":\n", " if all(k in example.keys() for k in (\"chosen\", \"rejected\")):\n", " chosen_messages = example[\"chosen\"]\n", " rejected_messages = example[\"rejected\"]\n", " # We add an empty system message if there is none\n", " if chosen_messages[0][\"role\"] != \"system\":\n", " chosen_messages.insert(0, {\"role\": \"system\", \"content\": \"\"})\n", " if rejected_messages[0][\"role\"] != \"system\":\n", " rejected_messages.insert(0, {\"role\": \"system\", \"content\": \"\"})\n", " example[\"text_chosen\"] = tokenizer.apply_chat_template(chosen_messages, tokenize=False)\n", " example[\"text_rejected\"] = tokenizer.apply_chat_template(rejected_messages, tokenize=False)\n", " else:\n", " raise ValueError(\n", " f\"Could not format example as dialogue for `rm` task! Require `[chosen, rejected]` keys but found {list(example.keys())}\"\n", " )\n", " elif task == \"dpo\":\n", " if all(k in example.keys() for k in (\"chosen\", \"rejected\")):\n", " # Compared to reward modeling, we filter out the prompt, so the text is everything after the last assistant token\n", " prompt_messages = [[msg for msg in example[\"chosen\"] if msg[\"role\"] == \"user\"][0]]\n", " # Insert system message\n", " if example[\"chosen\"][0][\"role\"] != \"system\":\n", " prompt_messages.insert(0, {\"role\": \"system\", \"content\": \"\"})\n", " else:\n", " prompt_messages.insert(0, example[\"chosen\"][0])\n", " # TODO: handle case where chosen/rejected also have system messages\n", " chosen_messages = example[\"chosen\"][1:]\n", " rejected_messages = example[\"rejected\"][1:]\n", " example[\"text_chosen\"] = tokenizer.apply_chat_template(chosen_messages, tokenize=False)\n", " example[\"text_rejected\"] = tokenizer.apply_chat_template(rejected_messages, tokenize=False)\n", " example[\"text_prompt\"] = tokenizer.apply_chat_template(\n", " prompt_messages, tokenize=False, add_generation_prompt=True\n", " )\n", " example[\"text_chosen\"] = _strip_prefix(example[\"text_chosen\"], assistant_prefix)\n", " example[\"text_rejected\"] = _strip_prefix(example[\"text_rejected\"], assistant_prefix)\n", " else:\n", " raise ValueError(\n", " f\"Could not format example as dialogue for `dpo` task! Require `[chosen, rejected]` keys but found {list(example.keys())}\"\n", " )\n", " else:\n", " raise ValueError(\n", " f\"Task {task} not supported, please ensure that the provided task is one of {['sft', 'generation', 'rm', 'dpo']}\"\n", " )\n", " return example\n", "\n", "\n", "def get_datasets(\n", " data_config: dict,\n", " splits: List[str] = [\"train\", \"test\"],\n", " shuffle: bool = True,\n", ") -> DatasetDict:\n", " \"\"\"\n", " Loads one or more datasets with varying training set proportions.\n", "\n", " Args:\n", " data_config (`DataArguments` or `dict`):\n", " Dataset configuration and split proportions.\n", " splits (`List[str]`, *optional*, defaults to `['train', 'test']`):\n", " Dataset splits to load and mix. Assumes the splits exist in all datasets and have a `train_` or `test_` prefix.\n", " shuffle (`bool`, *optional*, defaults to `True`):\n", " Whether to shuffle the training and testing/validation data.\n", "\n", " Returns\n", " [`DatasetDict`]: The dataset dictionary containing the loaded datasets.\n", " \"\"\"\n", "\n", " if type(data_config) is dict:\n", " # Structure of the input is:\n", " # dataset_mixer = {\n", " # \"dataset1\": 0.5,\n", " # \"dataset1\": 0.3,\n", " # \"dataset1\": 0.2,\n", " # }\n", " dataset_mixer = data_config\n", " else:\n", " raise ValueError(f\"Data config {data_config} not recognized.\")\n", "\n", " raw_datasets = mix_datasets(dataset_mixer, splits=splits, shuffle=shuffle)\n", " return raw_datasets\n", "\n", "\n", "def mix_datasets(dataset_mixer: dict, splits: Optional[List[str]] = None, shuffle=True) -> DatasetDict:\n", " \"\"\"\n", " Loads and mixes datasets according to proportions specified in `dataset_mixer`.\n", "\n", " Args:\n", " dataset_mixer (`dict`):\n", " Dictionary containing the dataset names and their training proportions. By default, all test proportions are 1.\n", " splits (Optional[List[str]], *optional*, defaults to `None`):\n", " Dataset splits to load and mix. Assumes the splits exist in all datasets and have a `train_` or `test_` prefix.\n", " shuffle (`bool`, *optional*, defaults to `True`):\n", " Whether to shuffle the training and testing/validation data.\n", " \"\"\"\n", " raw_datasets = DatasetDict()\n", " raw_train_datasets = []\n", " raw_val_datasets = []\n", " fracs = []\n", " for ds, frac in dataset_mixer.items():\n", " fracs.append(frac)\n", " for split in splits:\n", " try:\n", " # Try first if dataset on a Hub repo\n", " dataset = load_dataset(ds, split=split)\n", " except DatasetGenerationError:\n", " # If not, check local dataset\n", " dataset = load_from_disk(os.path.join(ds, split))\n", "\n", " if \"train\" in split:\n", " raw_train_datasets.append(dataset)\n", " elif \"test\" in split:\n", " raw_val_datasets.append(dataset)\n", " else:\n", " raise ValueError(f\"Split type {split} not recognized as one of test or train.\")\n", "\n", " if any(frac < 0 for frac in fracs):\n", " raise ValueError(\"Dataset fractions cannot be negative.\")\n", "\n", " if len(raw_train_datasets) > 0:\n", " train_subsets = []\n", " for dataset, frac in zip(raw_train_datasets, fracs):\n", " train_subset = dataset.select(range(int(frac * len(dataset))))\n", " train_subsets.append(train_subset)\n", " if shuffle:\n", " raw_datasets[\"train\"] = concatenate_datasets(train_subsets).shuffle(seed=42)\n", " else:\n", " raw_datasets[\"train\"] = concatenate_datasets(train_subsets)\n", " # No subsampling for test datasets to enable fair comparison across models\n", " if len(raw_val_datasets) > 0:\n", " if shuffle:\n", " raw_datasets[\"test\"] = concatenate_datasets(raw_val_datasets).shuffle(seed=42)\n", " else:\n", " raw_datasets[\"test\"] = concatenate_datasets(raw_val_datasets)\n", "\n", " if len(raw_datasets) == 0:\n", " raise ValueError(\n", " f\"Dataset {dataset_mixer} not recognized with split {split}. Check the dataset has been correctly formatted.\"\n", " )\n", "\n", " return raw_datasets" ] }, { "cell_type": "markdown", "metadata": { "id": "EQ-Cp2V6kDcr" }, "source": [ "\n", "### Data Prep\n", "We follow Huggingface's [Alignment Handbook](https://github.com/huggingface/alignment-handbook)." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 241, "referenced_widgets": [ "d901e138176b41ddbad5fdb5316c0863", "10d759b4b1bc4c2ea68dea8ab8647dda", "2fc7943f9dc8406c93f8bc4d99c7fa02", "8aa90a0e55c8435ba34857f357ae43c0", "a6485ae6ca3340a29c598b70155357bc", "e99ca0fa87ff41319dfad7fbd21980e2", "329f6c3e39184f7e86c4b7258bcb1394", "76037e249ebd406a951cab72e13deb6e", "41fc0c318b4b458f82aa8e6d22749416", "b471d282aaa143c4833cdf8aa6d79605", "df00d987b1ef432f86ecec36b9da1d6f", "310f49804ac54410b4d5b6544750ca0f", "c49b57f385514a80852a49b2063d58fa", "1bdf8bcb30964a69b032af040c64277c", "eff8110e11a34285bfb430c4d77fbfac", "4b3cd96bd26842b180d784f73c4474ad", "798a6888cd85403bb9f4499cb94bdf5e", "6e415e65b6954bc48126b10755d53305", "ed3d498b49354e9abaedfb5a0a058af1", "1ce9c65b2dc6487c988daad38d435a37", "c6a776d9fa6b49e49d0628adf583c6b2", "81e18304f8a34c24918ac144f9aae009", "73ec85a1f8e9404d9370aed85d10f271", "b52aaf3f11804913bc670c31630de6ec", "f4aafe0b85034f59a3c6059526c1000b", "c7811eeb616e431eb5e084bb9910d8f4", "5ca844fcfc294150b142a03eb43198f9", "cf216e9f1b034bbdbc1cf3fcf0e92db9", "b44c4067ecf04c3ab2a71b88dbe08b62", "bb282552158740e2b80c257a5a32b3c9", "cfbd166f0fbb48449e607cb4a2062c46", "3cab34d140594b08a13c29a6b6ae0823", "9103a72fd8c44301b6f25f0d3b557db6", "6b4fe0d31a0f4241a5434c24b87982a1", "979d707b6b744dd5afa9403c7644243f", "83b05de4ee6b410ab868a6d00c1c54f2", "957596e7359b4568b1ec1ecd0f62ed16", "3d1195a0c5fc402ca0caa60af2ebe9fb", "875d19302b51491e93971ff962167dce", "ba3362b426644df1adec99ed7e0409c0", "ba16b71a0aeb4967af22835e16af714a", "3bbd5a9c16e74d66a33a5d8af31f3aa5", "c0e556a7a16047b3b3b59b7e5f3ed844", "192ab4a14d21407d87e6456f6d67a039", "f4308a80acc0467a8f59580d6fff3d3f", "97ea18a097294cc79a149ab6d1452a97", "fe8555e19277403699add8894564047c", "187bca0dd81b47bdbb9ff3bbe0c7b4ec", "401a6f7d0b83489c8a7e10f1a6183446", "eeea816e2b8b4b7cafe7c8128cbcfaf2", "a380a4890c9149c38155903067b619ed", "693d23f5576248ba935a290dd0370f74", "393f612767e3432291e02e697f39baad", "1eea4a30bc8c4eac807e54c0807ad8e0", "c7e918b86d9440e5b5b86251b705748a", "926934ae2aad48328021e3a1eb1fa73e", "e40ab7e886014768bc0addcf518befd4", "d89eb869ceec4e2aa9d8404981a10f86", "1b29060d0a374dd2a88c5dad6887b0b7", "69ae5076109447be9b7f44901cbce61d", "bc53fa375def4423899a4fe8a309acda", "aff94722fd074c538d64541762b64bb6", "ab7b17b7063d4bac9863fdb3fa8e93d3", "41df1c965c5d4e43ab744b1b32746f01", "088e28c1b7ff4fe487dcfdaf75816854", "76897587840441f6bdd47da9c6628c97", "88285ee707f246f5b2d7863970a3833b", "35c6646626d148edbacaf54bc5626186", "c73b2d4224d340f6bfd1b2a227cfe558", "96aad1f018474e5583e28a3b8f95c54c", "64e2cc232eaf46eb803365c3c3557efd", "21de2cd6324344989dbe49043fc84f09", "f3713ee3330042eb90f7765addb8f141", "a5fe587e51324907bfdec469a84c6b55", "ea112eccf16643c2a7cb01f6046d0051", "2729037657a7456f852c397b07401666", "bfccd42c89f64e61a0ca095047393ad6" ] }, "id": "r6bUnxe6N3pf", "outputId": "689b8e8d-bbe0-4205-8b77-3331a93926e9" }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ee502fb8d5304ba38586d15fe28e2f42", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading readme: 0%| | 0.00/606 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "60948fa152d64108a264528deffa431c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/2.98M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f5e9ab65dca04e37a6c708653f9fa7a8", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading data: 0%| | 0.00/337k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "72ff8746cf99455eb3eea0cc1a6355ae", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating train split: 0%| | 0/8250 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "05973b0f6da6447ea49361ebb077bdf6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Generating test split: 0%| | 0/921 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3a82ed36a40e4977bd9744780ab345bb", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Formatting comparisons with prompt template (num_proc=12): 0%| | 0/8250 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "99394ef7887441e0839fafe9b4b65d53", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Formatting comparisons with prompt template (num_proc=12): 0%| | 0/921 [00:00, ? examples/s]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "raw_datasets = get_datasets(\n", " {\"cnbeining/sentence-segmentation-dpo\" : 1}, # 0.5% sampled\n", " splits = [\"train\", \"test\"],\n", ")\n", "column_names = list(raw_datasets[\"train\"].features)\n", "\n", "raw_datasets = raw_datasets.map(\n", " apply_chat_template,\n", " fn_kwargs = {\"tokenizer\": tokenizer, \"task\": \"dpo\"},\n", " num_proc = 12,\n", " remove_columns = column_names,\n", " desc = \"Formatting comparisons with prompt template\",\n", ")\n", "\n", "# Replace column names with what TRL needs, text_chosen -> chosen and text_rejected -> rejected\n", "for split in [\"train\", \"test\"]:\n", " raw_datasets[split] = raw_datasets[split].rename_columns(\n", " {\"text_prompt\": \"prompt\", \"text_chosen\": \"chosen\", \"text_rejected\": \"rejected\"}\n", " )" ] }, { "cell_type": "markdown", "metadata": { "id": "7AxUmeAGkjDd" }, "source": [ "We shall print a random item from the dataset" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "oF63zQqNlNJC", "outputId": "74bb4c47-85f3-4b8d-aa1a-912a9c6b2df2" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "('<|im_start|>system\\n'\n", " 'Segment:<|im_end|>\\n'\n", " '<|im_start|>user\\n'\n", " '```yaml\\n'\n", " '\"input\":\\n'\n", " ' \"sentence\":\\n'\n", " ' \"segment\":\\n'\n", " ' - \"word\": \"Shere,\"\\n'\n", " ' - \"word\": \"in\"\\n'\n", " ' - \"word\": \"your\"\\n'\n", " ' - \"word\": \"report\"\\n'\n", " ' - \"word\": \"on\"\\n'\n", " ' - \"word\": \"female\"\\n'\n", " ' - \"word\": \"sexuality,\"\\n'\n", " ' - \"word\": \"men\"\\n'\n", " ' - \"word\": \"were\"\\n'\n", " ' - \"word\": \"staggered\"\\n'\n", " ' - \"word\": \"to\"\\n'\n", " ' - \"word\": \"learn\"\\n'\n", " ' - \"word\": \"that\"\\n'\n", " ' - \"word\": \"clitoral\"\\n'\n", " ' - \"word\": \"stimulation\"\\n'\n", " ' - \"word\": \"was\"\\n'\n", " ' - \"word\": \"much\"\\n'\n", " ' - \"word\": \"more\"\\n'\n", " ' - \"word\": \"important\"\\n'\n", " ' - \"word\": \"than\"\\n'\n", " ' - \"word\": \"penetration.\"\\n'\n", " '\\n'\n", " '```<|im_end|>\\n'\n", " '<|im_start|>assistant\\n')\n", "('<|im_start|>user\\n'\n", " '```yaml\\n'\n", " '\"input\":\\n'\n", " ' \"sentence\":\\n'\n", " ' \"segment\":\\n'\n", " ' - \"word\": \"Shere,\"\\n'\n", " ' - \"word\": \"in\"\\n'\n", " ' - \"word\": \"your\"\\n'\n", " ' - \"word\": \"report\"\\n'\n", " ' - \"word\": \"on\"\\n'\n", " ' - \"word\": \"female\"\\n'\n", " ' - \"word\": \"sexuality,\"\\n'\n", " ' - \"word\": \"men\"\\n'\n", " ' - \"word\": \"were\"\\n'\n", " ' - \"word\": \"staggered\"\\n'\n", " ' - \"word\": \"to\"\\n'\n", " ' - \"word\": \"learn\"\\n'\n", " ' - \"word\": \"that\"\\n'\n", " ' - \"word\": \"clitoral\"\\n'\n", " ' - \"word\": \"stimulation\"\\n'\n", " ' - \"word\": \"was\"\\n'\n", " ' - \"word\": \"much\"\\n'\n", " ' - \"word\": \"more\"\\n'\n", " ' - \"word\": \"important\"\\n'\n", " ' - \"word\": \"than\"\\n'\n", " ' - \"word\": \"penetration.\"\\n'\n", " '\\n'\n", " '```<|im_end|>\\n'\n", " '<|im_start|>assistant\\n'\n", " '```yaml\\n'\n", " '\"output\":\\n'\n", " '- \"sentence\":\\n'\n", " ' - \"segment\":\\n'\n", " ' - \"word\": \"Shere,\"\\n'\n", " ' - \"word\": \"in\"\\n'\n", " ' - \"word\": \"your\"\\n'\n", " ' - \"word\": \"report\"\\n'\n", " ' - \"word\": \"\\'on\\'\"\\n'\n", " ' - \"word\": \"female\"\\n'\n", " ' - \"word\": \"sexuality,\"\\n'\n", " ' - \"segment\":\\n'\n", " ' - \"word\": \"men\"\\n'\n", " ' - \"word\": \"were\"\\n'\n", " ' - \"word\": \"staggered\"\\n'\n", " ' - \"word\": \"to\"\\n'\n", " ' - \"word\": \"learn\"\\n'\n", " ' - \"word\": \"that\"\\n'\n", " ' - \"word\": \"clitoral\"\\n'\n", " ' - \"word\": \"stimulation\"\\n'\n", " ' - \"segment\":\\n'\n", " ' - \"word\": \"was\"\\n'\n", " ' - \"word\": \"much\"\\n'\n", " ' - \"word\": \"more\"\\n'\n", " ' - \"word\": \"important\"\\n'\n", " ' - \"word\": \"than\"\\n'\n", " ' - \"word\": \"penetration.\"\\n'\n", " '\\n'\n", " '```<|im_end|>\\n')\n", "('<|im_start|>user\\n'\n", " '```yaml\\n'\n", " '\"input\":\\n'\n", " ' \"sentence\":\\n'\n", " ' \"segment\":\\n'\n", " ' - \"word\": \"Shere,\"\\n'\n", " ' - \"word\": \"in\"\\n'\n", " ' - \"word\": \"your\"\\n'\n", " ' - \"word\": \"report\"\\n'\n", " ' - \"word\": \"on\"\\n'\n", " ' - \"word\": \"female\"\\n'\n", " ' - \"word\": \"sexuality,\"\\n'\n", " ' - \"word\": \"men\"\\n'\n", " ' - \"word\": \"were\"\\n'\n", " ' - \"word\": \"staggered\"\\n'\n", " ' - \"word\": \"to\"\\n'\n", " ' - \"word\": \"learn\"\\n'\n", " ' - \"word\": \"that\"\\n'\n", " ' - \"word\": \"clitoral\"\\n'\n", " ' - \"word\": \"stimulation\"\\n'\n", " ' - \"word\": \"was\"\\n'\n", " ' - \"word\": \"much\"\\n'\n", " ' - \"word\": \"more\"\\n'\n", " ' - \"word\": \"important\"\\n'\n", " ' - \"word\": \"than\"\\n'\n", " ' - \"word\": \"penetration.\"\\n'\n", " '\\n'\n", " '```<|im_end|>\\n'\n", " '<|im_start|>assistant\\n'\n", " '```yaml\\n'\n", " '\"input\":\\n'\n", " ' \"sentence\":\\n'\n", " ' \"segment\":\\n'\n", " ' - \"word\": \"Shere,\"\\n'\n", " ' - \"word\": \"in\"\\n'\n", " ' - \"word\": \"your\"\\n'\n", " ' - \"word\": \"report\"\\n'\n", " ' - \"word\": \"on\"\\n'\n", " ' - \"word\": \"female\"\\n'\n", " ' - \"word\": \"sexuality,\"\\n'\n", " ' - \"word\": \"men\"\\n'\n", " ' - \"word\": \"were\"\\n'\n", " ' - \"word\": \"staggered\"\\n'\n", " ' - \"word\": \"to\"\\n'\n", " ' - \"word\": \"learn\"\\n'\n", " ' - \"word\": \"that\"\\n'\n", " ' - \"word\": \"clitoral\"\\n'\n", " ' - \"word\": \"stimulation\"\\n'\n", " ' - \"word\": \"was\"\\n'\n", " ' - \"word\": \"much\"\\n'\n", " ' - \"word\": \"more\"\\n'\n", " ' - \"word\": \"important\"\\n'\n", " ' - \"word\": \"than\"\\n'\n", " ' - \"word\": \"penetration.\"\\n'\n", " '\\n'\n", " '```<|im_end|>\\n')\n" ] } ], "source": [ "import pprint\n", "row = raw_datasets[\"train\"][8]\n", "pprint.pprint(row[\"prompt\"])\n", "pprint.pprint(row[\"chosen\"])\n", "pprint.pprint(row[\"rejected\"])" ] }, { "cell_type": "markdown", "metadata": { "id": "86wyNoeMj-Ph" }, "source": [ "We now add LoRA adapters so we only need to update 1 to 10% of all parameters!" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "6bZsfBuZDeCL", "outputId": "2941d5d9-6de3-48a4-a039-3d5c6cf809ef" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Unsloth 2024.2 patched 32 layers with 32 QKV layers, 32 O layers and 32 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, # Currently only supports dropout = 0\n", " bias = \"none\", # Currently only supports bias = \"none\"\n", " use_gradient_checkpointing = True,\n", " random_state = 3407,\n", " use_rslora = False, # We support rank stabilized LoRA\n", " loftq_config = None, # And LoftQ\n", ")" ] }, { "cell_type": "markdown", "metadata": { "id": "-kyd_iyz7DUM" }, "source": [ "\n", "### Train the DPO model\n", "\n", "Parameters are borrowed from [here](https://freedium.cfd/https://towardsdatascience.com/fine-tune-a-mistral-7b-model-with-direct-preference-optimization-708042745aac?gi=9eb916bb6d8d) but we use a smaller learning rate and warmup steps.\n", "\n", "It takes ~12 hours on a single RTX 3090 to run this config. Max VRAM is ~15GB." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "id": "v-2BFpDWzo1K" }, "outputs": [], "source": [ "# One must patch the DPO Trainer first!\n", "from unsloth import PatchDPOTrainer\n", "PatchDPOTrainer()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 104, "referenced_widgets": [ "c86b2607a677411cabb088a67af2b4ef", "5b2e5edfc16f4098bf657eadc3822c35", "806eed72cad64e93b0dd7536877c87c8", "77a19ee389ad47a8b0170eaa8562b76e", "7a5eeef2a863406cb2404c5f9b5e469e", "4f3dd8d3c99940eb9d6f5b5531a1f51b", "2c879d1ca0dc4051a8675786994c3e98", "9f88fc44294b4c35ae32b799cabcc81b", "e1eb177b1d424c91b1eb673013203e20", "0b36054150d9427193289aecc7354b9f", "f6a35143024d4d2897056bc6a2b2cd82" ] }, "id": "QtoqUw80QDV0", "outputId": "cf014d38-3960-4dc7-a322-f10dc8fe397b" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.10/dist-packages/trl/trainer/dpo_trainer.py:328: UserWarning: When using DPODataCollatorWithPadding, you should set `remove_unused_columns=False` in your TrainingArguments we have set it for you, but you should do it yourself in the future.\n", " warnings.warn(\n" ] } ], "source": [ "from transformers import TrainingArguments\n", "from trl import DPOTrainer\n", "\n", "dpo_trainer = DPOTrainer(\n", " model = model,\n", " ref_model = None,\n", " args = TrainingArguments(\n", " per_device_train_batch_size = 4, # change me to 1 for T4 to avoid OOM. 4 goes to 15GB VRAM.\n", " gradient_accumulation_steps = 8,\n", " #warmup_ratio = 0.1,\n", " #num_train_epochs = 3,\n", " warmup_steps = 50,\n", " max_steps = 200,\n", " learning_rate = 5e-6,\n", " fp16 = not torch.cuda.is_bf16_supported(),\n", " bf16 = torch.cuda.is_bf16_supported(),\n", " logging_steps = 1,\n", " optim = \"adamw_8bit\",\n", " weight_decay = 0.0,\n", " lr_scheduler_type = \"linear\",\n", " seed = 42,\n", " output_dir = \"outputs\",\n", " ),\n", " beta = 0.1,\n", " train_dataset = raw_datasets[\"train\"],\n", " # eval_dataset = raw_datasets[\"test\"],\n", " tokenizer = tokenizer,\n", " max_length = 1024,\n", " max_prompt_length = 512,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 515 }, "id": "EWGFqAo5Q2me", "outputId": "4a3e644b-020f-4c2a-d5b8-247ecfd7f8e4" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "==((====))== Unsloth - 2x faster free finetuning | Num GPUs = 1\n", " \\\\ /| Num examples = 8,250 | Num Epochs = 1\n", "O^O/ \\_/ \\ Batch size per device = 4 | Gradient Accumulation steps = 8\n", "\\ / Total batch size = 32 | Total steps = 200\n", " \"-____-\" Number of trainable parameters = 41,943,040\n" ] }, { "data": { "text/html": [ "\n", "
Step | \n", "Training Loss | \n", "rewards / chosen | \n", "rewards / rejected | \n", "rewards / accuracies | \n", "rewards / margins | \n", "logps / rejected | \n", "logps / chosen | \n", "logits / rejected | \n", "logits / chosen | \n", "
---|---|---|---|---|---|---|---|---|---|
1 | \n", "0.692500 | \n", "0.009931 | \n", "0.008267 | \n", "0.437500 | \n", "0.001664 | \n", "-65.225388 | \n", "-101.532379 | \n", "-1.887149 | \n", "-1.941751 | \n", "
2 | \n", "0.694300 | \n", "0.001475 | \n", "0.002985 | \n", "0.468750 | \n", "-0.001510 | \n", "-61.391518 | \n", "-103.492035 | \n", "-1.946624 | \n", "-2.016978 | \n", "
3 | \n", "0.688400 | \n", "0.022894 | \n", "0.012900 | \n", "0.531250 | \n", "0.009994 | \n", "-63.438393 | \n", "-102.275764 | \n", "-1.874705 | \n", "-1.928362 | \n", "
4 | \n", "0.694400 | \n", "-0.005765 | \n", "-0.004249 | \n", "0.468750 | \n", "-0.001515 | \n", "-73.846512 | \n", "-113.181061 | \n", "-1.914331 | \n", "-1.969258 | \n", "
5 | \n", "0.687200 | \n", "0.026846 | \n", "0.014403 | \n", "0.656250 | \n", "0.012443 | \n", "-66.318810 | \n", "-101.976959 | \n", "-1.877555 | \n", "-1.921344 | \n", "
6 | \n", "0.700900 | \n", "-0.004023 | \n", "0.010963 | \n", "0.312500 | \n", "-0.014986 | \n", "-64.160797 | \n", "-103.950340 | \n", "-1.880763 | \n", "-1.940524 | \n", "
7 | \n", "0.690200 | \n", "0.011923 | \n", "0.005527 | \n", "0.500000 | \n", "0.006397 | \n", "-60.049065 | \n", "-99.933624 | \n", "-1.923996 | \n", "-1.987151 | \n", "
8 | \n", "0.687000 | \n", "-0.012407 | \n", "-0.025644 | \n", "0.593750 | \n", "0.013237 | \n", "-62.400936 | \n", "-105.044968 | \n", "-1.857906 | \n", "-1.922159 | \n", "
9 | \n", "0.683500 | \n", "0.026266 | \n", "0.006360 | \n", "0.687500 | \n", "0.019907 | \n", "-63.879200 | \n", "-99.804367 | \n", "-1.876602 | \n", "-1.926666 | \n", "
10 | \n", "0.667100 | \n", "0.050956 | \n", "-0.002668 | \n", "0.781250 | \n", "0.053624 | \n", "-61.041092 | \n", "-100.755806 | \n", "-1.896852 | \n", "-1.953525 | \n", "
11 | \n", "0.655500 | \n", "0.111606 | \n", "0.033584 | \n", "0.750000 | \n", "0.078022 | \n", "-61.884716 | \n", "-102.103668 | \n", "-1.900634 | \n", "-1.962237 | \n", "
12 | \n", "0.643800 | \n", "0.149035 | \n", "0.046527 | \n", "0.875000 | \n", "0.102507 | \n", "-64.979950 | \n", "-104.774536 | \n", "-1.891555 | \n", "-1.960934 | \n", "
13 | \n", "0.634800 | \n", "0.144701 | \n", "0.023337 | \n", "0.937500 | \n", "0.121364 | \n", "-63.798531 | \n", "-103.742249 | \n", "-1.778855 | \n", "-1.833693 | \n", "
14 | \n", "0.621500 | \n", "0.182954 | \n", "0.031697 | \n", "0.875000 | \n", "0.151258 | \n", "-71.333099 | \n", "-109.079803 | \n", "-1.901324 | \n", "-1.977052 | \n", "
15 | \n", "0.610800 | \n", "0.232755 | \n", "0.057179 | \n", "0.937500 | \n", "0.175576 | \n", "-66.366852 | \n", "-101.796547 | \n", "-1.892416 | \n", "-1.948260 | \n", "
16 | \n", "0.572500 | \n", "0.341622 | \n", "0.079258 | \n", "1.000000 | \n", "0.262364 | \n", "-61.240749 | \n", "-102.240089 | \n", "-1.840552 | \n", "-1.915109 | \n", "
17 | \n", "0.566900 | \n", "0.365034 | \n", "0.086816 | \n", "0.906250 | \n", "0.278218 | \n", "-64.686630 | \n", "-99.750885 | \n", "-1.856691 | \n", "-1.899691 | \n", "
18 | \n", "0.543800 | \n", "0.458547 | \n", "0.120786 | \n", "0.875000 | \n", "0.337762 | \n", "-68.870506 | \n", "-102.014709 | \n", "-1.921505 | \n", "-1.973164 | \n", "
19 | \n", "0.536000 | \n", "0.453414 | \n", "0.093966 | \n", "0.843750 | \n", "0.359447 | \n", "-72.129517 | \n", "-104.179985 | \n", "-1.899905 | \n", "-1.952941 | \n", "
20 | \n", "0.468500 | \n", "0.689614 | \n", "0.160546 | \n", "1.000000 | \n", "0.529067 | \n", "-60.327698 | \n", "-95.464592 | \n", "-1.875398 | \n", "-1.949434 | \n", "
21 | \n", "0.486100 | \n", "0.583776 | \n", "0.086889 | \n", "1.000000 | \n", "0.496888 | \n", "-58.430485 | \n", "-94.424088 | \n", "-1.891454 | \n", "-1.949621 | \n", "
22 | \n", "0.419300 | \n", "0.848659 | \n", "0.163429 | \n", "1.000000 | \n", "0.685230 | \n", "-59.735069 | \n", "-95.625793 | \n", "-1.883978 | \n", "-1.953738 | \n", "
23 | \n", "0.368100 | \n", "1.064526 | \n", "0.223643 | \n", "0.968750 | \n", "0.840883 | \n", "-65.426880 | \n", "-99.163666 | \n", "-1.880917 | \n", "-1.953981 | \n", "
24 | \n", "0.429500 | \n", "0.857422 | \n", "0.191689 | \n", "0.937500 | \n", "0.665733 | \n", "-63.500526 | \n", "-97.119232 | \n", "-1.882411 | \n", "-1.937384 | \n", "
25 | \n", "0.359500 | \n", "1.051884 | \n", "0.171019 | \n", "1.000000 | \n", "0.880866 | \n", "-59.690598 | \n", "-93.825394 | \n", "-1.876372 | \n", "-1.940306 | \n", "
26 | \n", "0.369400 | \n", "1.030587 | \n", "0.163402 | \n", "0.937500 | \n", "0.867185 | \n", "-66.781578 | \n", "-99.858658 | \n", "-1.902385 | \n", "-1.956554 | \n", "
27 | \n", "0.402800 | \n", "0.890681 | \n", "0.114508 | \n", "0.906250 | \n", "0.776173 | \n", "-71.715210 | \n", "-100.529358 | \n", "-1.888062 | \n", "-1.939180 | \n", "
28 | \n", "0.373200 | \n", "0.953555 | \n", "0.070599 | \n", "0.875000 | \n", "0.882955 | \n", "-70.100090 | \n", "-96.930428 | \n", "-1.893912 | \n", "-1.941720 | \n", "
29 | \n", "0.287400 | \n", "1.220423 | \n", "0.063830 | \n", "1.000000 | \n", "1.156593 | \n", "-60.500408 | \n", "-92.004044 | \n", "-1.910934 | \n", "-1.980496 | \n", "
30 | \n", "0.272000 | \n", "1.310052 | \n", "0.062345 | \n", "0.937500 | \n", "1.247708 | \n", "-79.165314 | \n", "-108.299950 | \n", "-1.822885 | \n", "-1.884399 | \n", "
31 | \n", "0.206100 | \n", "1.520700 | \n", "-0.005452 | \n", "1.000000 | \n", "1.526153 | \n", "-63.071144 | \n", "-91.908241 | \n", "-1.785687 | \n", "-1.854471 | \n", "
32 | \n", "0.203000 | \n", "1.592522 | \n", "-0.031915 | \n", "0.968750 | \n", "1.624437 | \n", "-65.479233 | \n", "-91.025398 | \n", "-1.922925 | \n", "-1.986865 | \n", "
33 | \n", "0.220900 | \n", "1.533269 | \n", "-0.099248 | \n", "0.906250 | \n", "1.632518 | \n", "-74.588127 | \n", "-99.629623 | \n", "-1.902008 | \n", "-1.964205 | \n", "
34 | \n", "0.229700 | \n", "1.466858 | \n", "-0.181946 | \n", "0.906250 | \n", "1.648804 | \n", "-76.335480 | \n", "-95.496765 | \n", "-1.834822 | \n", "-1.879345 | \n", "
35 | \n", "0.214000 | \n", "1.487525 | \n", "-0.307055 | \n", "0.906250 | \n", "1.794579 | \n", "-75.319336 | \n", "-93.538475 | \n", "-1.918821 | \n", "-1.972670 | \n", "
36 | \n", "0.099800 | \n", "1.994153 | \n", "-0.513482 | \n", "1.000000 | \n", "2.507635 | \n", "-66.908455 | \n", "-86.157974 | \n", "-1.878010 | \n", "-1.946506 | \n", "
37 | \n", "0.077200 | \n", "2.184178 | \n", "-0.574726 | \n", "1.000000 | \n", "2.758904 | \n", "-68.408157 | \n", "-85.516212 | \n", "-1.835259 | \n", "-1.906821 | \n", "
38 | \n", "0.085500 | \n", "2.106439 | \n", "-0.752738 | \n", "0.968750 | \n", "2.859177 | \n", "-71.303757 | \n", "-82.281708 | \n", "-1.944694 | \n", "-2.010727 | \n", "
39 | \n", "0.061900 | \n", "2.199690 | \n", "-1.022853 | \n", "1.000000 | \n", "3.222543 | \n", "-71.377663 | \n", "-81.943062 | \n", "-1.852974 | \n", "-1.922352 | \n", "
40 | \n", "0.057000 | \n", "2.325701 | \n", "-1.298665 | \n", "0.968750 | \n", "3.624366 | \n", "-77.034576 | \n", "-83.035263 | \n", "-1.916527 | \n", "-1.989293 | \n", "
41 | \n", "0.054100 | \n", "2.345055 | \n", "-1.445602 | \n", "0.968750 | \n", "3.790657 | \n", "-79.867455 | \n", "-83.643631 | \n", "-1.856608 | \n", "-1.905395 | \n", "
42 | \n", "0.046100 | \n", "2.493526 | \n", "-1.773150 | \n", "0.968750 | \n", "4.266676 | \n", "-87.937729 | \n", "-88.179108 | \n", "-1.886164 | \n", "-1.950880 | \n", "
43 | \n", "0.047200 | \n", "2.312751 | \n", "-2.050373 | \n", "0.968750 | \n", "4.363124 | \n", "-87.161430 | \n", "-86.129944 | \n", "-1.855935 | \n", "-1.925613 | \n", "
44 | \n", "0.068700 | \n", "2.223296 | \n", "-2.149679 | \n", "0.937500 | \n", "4.372974 | \n", "-86.375252 | \n", "-80.280624 | \n", "-1.891995 | \n", "-1.953149 | \n", "
45 | \n", "0.042700 | \n", "2.247630 | \n", "-2.533532 | \n", "0.968750 | \n", "4.781161 | \n", "-90.727478 | \n", "-81.450562 | \n", "-1.793966 | \n", "-1.851126 | \n", "
46 | \n", "0.053800 | \n", "2.464459 | \n", "-2.954240 | \n", "0.937500 | \n", "5.418699 | \n", "-96.708618 | \n", "-80.554291 | \n", "-1.842345 | \n", "-1.908538 | \n", "
47 | \n", "0.032700 | \n", "2.468843 | \n", "-3.229654 | \n", "0.968750 | \n", "5.698498 | \n", "-95.002190 | \n", "-79.113609 | \n", "-1.858419 | \n", "-1.917609 | \n", "
48 | \n", "0.117500 | \n", "2.093840 | \n", "-3.124513 | \n", "0.843750 | \n", "5.218353 | \n", "-101.185349 | \n", "-82.650948 | \n", "-1.802338 | \n", "-1.846435 | \n", "
49 | \n", "0.030000 | \n", "2.447959 | \n", "-3.934424 | \n", "0.968750 | \n", "6.382382 | \n", "-104.642136 | \n", "-82.287971 | \n", "-1.859661 | \n", "-1.925090 | \n", "
50 | \n", "0.025200 | \n", "2.349972 | \n", "-4.316091 | \n", "0.968750 | \n", "6.666064 | \n", "-106.073097 | \n", "-80.433182 | \n", "-1.842398 | \n", "-1.911368 | \n", "
51 | \n", "0.006500 | \n", "2.351074 | \n", "-4.687556 | \n", "1.000000 | \n", "7.038630 | \n", "-107.932602 | \n", "-79.370636 | \n", "-1.878582 | \n", "-1.935707 | \n", "
52 | \n", "0.001600 | \n", "2.463594 | \n", "-5.362265 | \n", "1.000000 | \n", "7.825859 | \n", "-116.103485 | \n", "-80.034363 | \n", "-1.795781 | \n", "-1.862844 | \n", "
53 | \n", "0.004000 | \n", "2.131287 | \n", "-5.419191 | \n", "1.000000 | \n", "7.550478 | \n", "-115.462906 | \n", "-80.987839 | \n", "-1.850861 | \n", "-1.905600 | \n", "
54 | \n", "0.003200 | \n", "2.197679 | \n", "-5.805073 | \n", "1.000000 | \n", "8.002752 | \n", "-118.687881 | \n", "-79.826187 | \n", "-1.925845 | \n", "-1.993290 | \n", "
55 | \n", "0.023100 | \n", "2.277760 | \n", "-6.006099 | \n", "0.968750 | \n", "8.283859 | \n", "-127.820969 | \n", "-88.483589 | \n", "-1.847210 | \n", "-1.917872 | \n", "
56 | \n", "0.044200 | \n", "2.045557 | \n", "-6.169188 | \n", "0.937500 | \n", "8.214745 | \n", "-124.659477 | \n", "-84.166031 | \n", "-1.855102 | \n", "-1.916062 | \n", "
57 | \n", "0.043800 | \n", "2.398190 | \n", "-6.592159 | \n", "0.937500 | \n", "8.990349 | \n", "-139.529144 | \n", "-90.947296 | \n", "-1.846677 | \n", "-1.928034 | \n", "
58 | \n", "0.023100 | \n", "1.774500 | \n", "-6.694506 | \n", "0.968750 | \n", "8.469006 | \n", "-131.312759 | \n", "-86.181992 | \n", "-1.925915 | \n", "-1.977345 | \n", "
59 | \n", "0.022400 | \n", "1.838212 | \n", "-7.260215 | \n", "0.968750 | \n", "9.098426 | \n", "-141.422379 | \n", "-91.776863 | \n", "-1.849625 | \n", "-1.904955 | \n", "
60 | \n", "0.043900 | \n", "1.845384 | \n", "-7.266408 | \n", "0.937500 | \n", "9.111793 | \n", "-141.614639 | \n", "-88.987274 | \n", "-1.840355 | \n", "-1.906916 | \n", "
61 | \n", "0.044800 | \n", "1.478810 | \n", "-6.819289 | \n", "0.937500 | \n", "8.298099 | \n", "-132.690399 | \n", "-88.374329 | \n", "-1.919538 | \n", "-1.969639 | \n", "
62 | \n", "0.022100 | \n", "1.899460 | \n", "-8.140540 | \n", "0.968750 | \n", "10.039999 | \n", "-145.743271 | \n", "-90.252388 | \n", "-1.857570 | \n", "-1.919511 | \n", "
63 | \n", "0.000200 | \n", "2.026294 | \n", "-8.438683 | \n", "1.000000 | \n", "10.464976 | \n", "-147.020706 | \n", "-87.274490 | \n", "-1.827286 | \n", "-1.887730 | \n", "
64 | \n", "0.022200 | \n", "1.510540 | \n", "-8.273267 | \n", "0.968750 | \n", "9.783808 | \n", "-145.323395 | \n", "-88.450317 | \n", "-1.925784 | \n", "-1.984003 | \n", "
65 | \n", "0.043600 | \n", "1.535126 | \n", "-8.492983 | \n", "0.937500 | \n", "10.028109 | \n", "-150.402832 | \n", "-92.309814 | \n", "-1.912131 | \n", "-1.956778 | \n", "
66 | \n", "0.000500 | \n", "1.214515 | \n", "-9.012184 | \n", "1.000000 | \n", "10.226698 | \n", "-150.540588 | \n", "-88.528961 | \n", "-1.890113 | \n", "-1.947372 | \n", "
67 | \n", "0.000100 | \n", "1.796210 | \n", "-9.429188 | \n", "1.000000 | \n", "11.225397 | \n", "-156.939789 | \n", "-87.245361 | \n", "-1.984745 | \n", "-2.063085 | \n", "
68 | \n", "0.065300 | \n", "1.064941 | \n", "-8.560112 | \n", "0.906250 | \n", "9.625053 | \n", "-155.757919 | \n", "-97.472366 | \n", "-1.907721 | \n", "-1.961506 | \n", "
69 | \n", "0.065200 | \n", "0.993425 | \n", "-8.375295 | \n", "0.906250 | \n", "9.368720 | \n", "-150.670074 | \n", "-93.864662 | \n", "-1.852926 | \n", "-1.895516 | \n", "
70 | \n", "0.021800 | \n", "1.755924 | \n", "-9.264212 | \n", "0.968750 | \n", "11.020137 | \n", "-163.759888 | \n", "-94.422531 | \n", "-1.884260 | \n", "-1.949026 | \n", "
71 | \n", "0.043600 | \n", "1.407461 | \n", "-9.270432 | \n", "0.937500 | \n", "10.677893 | \n", "-156.794220 | \n", "-90.694122 | \n", "-1.962400 | \n", "-2.025506 | \n", "
72 | \n", "0.021800 | \n", "1.515018 | \n", "-10.059039 | \n", "0.968750 | \n", "11.574058 | \n", "-164.633789 | \n", "-90.771729 | \n", "-1.889076 | \n", "-1.959179 | \n", "
73 | \n", "0.021900 | \n", "0.972740 | \n", "-9.585093 | \n", "0.968750 | \n", "10.557834 | \n", "-161.972061 | \n", "-96.145828 | \n", "-1.844425 | \n", "-1.892524 | \n", "
74 | \n", "0.086800 | \n", "0.914522 | \n", "-8.792732 | \n", "0.875000 | \n", "9.707254 | \n", "-165.594879 | \n", "-107.097473 | \n", "-1.890044 | \n", "-1.930513 | \n", "
75 | \n", "0.021700 | \n", "1.005203 | \n", "-9.988317 | \n", "0.968750 | \n", "10.993520 | \n", "-167.207214 | \n", "-97.347313 | \n", "-1.853193 | \n", "-1.899400 | \n", "
76 | \n", "0.043400 | \n", "1.073524 | \n", "-9.750250 | \n", "0.937500 | \n", "10.823773 | \n", "-162.604950 | \n", "-94.317307 | \n", "-1.930668 | \n", "-1.986013 | \n", "
77 | \n", "0.000700 | \n", "1.120011 | \n", "-10.201104 | \n", "1.000000 | \n", "11.321115 | \n", "-162.052475 | \n", "-89.903503 | \n", "-1.890304 | \n", "-1.941276 | \n", "
78 | \n", "0.021700 | \n", "1.237938 | \n", "-10.656733 | \n", "0.968750 | \n", "11.894670 | \n", "-172.641373 | \n", "-97.203491 | \n", "-1.823810 | \n", "-1.876656 | \n", "
79 | \n", "0.021700 | \n", "1.378800 | \n", "-10.745403 | \n", "0.968750 | \n", "12.124205 | \n", "-175.867447 | \n", "-96.711655 | \n", "-1.866561 | \n", "-1.930430 | \n", "
80 | \n", "0.000300 | \n", "0.815344 | \n", "-10.559508 | \n", "1.000000 | \n", "11.374853 | \n", "-165.476654 | \n", "-93.585762 | \n", "-1.911207 | \n", "-1.972837 | \n", "
81 | \n", "0.021800 | \n", "1.333638 | \n", "-10.598663 | \n", "0.968750 | \n", "11.932303 | \n", "-170.322357 | \n", "-92.381172 | \n", "-1.820395 | \n", "-1.882859 | \n", "
82 | \n", "0.065000 | \n", "0.988857 | \n", "-9.934489 | \n", "0.906250 | \n", "10.923346 | \n", "-177.054352 | \n", "-106.560127 | \n", "-1.867344 | \n", "-1.924058 | \n", "
83 | \n", "0.043500 | \n", "1.027610 | \n", "-10.391800 | \n", "0.937500 | \n", "11.419410 | \n", "-175.208740 | \n", "-102.094643 | \n", "-1.809247 | \n", "-1.866203 | \n", "
84 | \n", "0.021700 | \n", "0.683302 | \n", "-10.983616 | \n", "0.968750 | \n", "11.666917 | \n", "-173.502335 | \n", "-98.309151 | \n", "-1.950875 | \n", "-2.006760 | \n", "
85 | \n", "0.086700 | \n", "0.578787 | \n", "-9.707729 | \n", "0.875000 | \n", "10.286515 | \n", "-179.424118 | \n", "-111.117203 | \n", "-1.860974 | \n", "-1.897847 | \n", "
86 | \n", "0.047900 | \n", "0.936778 | \n", "-10.527672 | \n", "0.937500 | \n", "11.464449 | \n", "-180.852005 | \n", "-102.993217 | \n", "-1.848799 | \n", "-1.890695 | \n", "
87 | \n", "0.065200 | \n", "0.425789 | \n", "-9.822309 | \n", "0.906250 | \n", "10.248099 | \n", "-170.416809 | \n", "-101.552681 | \n", "-1.931349 | \n", "-1.980755 | \n", "
88 | \n", "0.000000 | \n", "1.175534 | \n", "-11.875732 | \n", "1.000000 | \n", "13.051266 | \n", "-180.803360 | \n", "-96.029663 | \n", "-1.903106 | \n", "-1.976819 | \n", "
89 | \n", "0.086700 | \n", "1.005983 | \n", "-9.917144 | \n", "0.875000 | \n", "10.923127 | \n", "-169.909607 | \n", "-98.544983 | \n", "-1.883621 | \n", "-1.938490 | \n", "
90 | \n", "0.000100 | \n", "0.709654 | \n", "-11.357013 | \n", "1.000000 | \n", "12.066666 | \n", "-173.706055 | \n", "-93.608917 | \n", "-1.915069 | \n", "-1.976762 | \n", "
91 | \n", "0.043500 | \n", "0.477264 | \n", "-10.736551 | \n", "0.937500 | \n", "11.213816 | \n", "-181.218826 | \n", "-108.760612 | \n", "-1.802605 | \n", "-1.844357 | \n", "
92 | \n", "0.086700 | \n", "0.583126 | \n", "-10.044876 | \n", "0.875000 | \n", "10.628002 | \n", "-167.350479 | \n", "-99.650597 | \n", "-1.886728 | \n", "-1.933193 | \n", "
93 | \n", "0.021700 | \n", "0.945670 | \n", "-11.775242 | \n", "0.968750 | \n", "12.720912 | \n", "-184.069229 | \n", "-98.403450 | \n", "-1.906602 | \n", "-1.973187 | \n", "
94 | \n", "0.043400 | \n", "0.612050 | \n", "-11.059619 | \n", "0.937500 | \n", "11.671669 | \n", "-187.280777 | \n", "-109.401169 | \n", "-1.826414 | \n", "-1.877087 | \n", "
95 | \n", "0.021700 | \n", "0.675427 | \n", "-11.450605 | \n", "0.968750 | \n", "12.126032 | \n", "-179.981110 | \n", "-100.109367 | \n", "-1.898841 | \n", "-1.953507 | \n", "
96 | \n", "0.021700 | \n", "0.708127 | \n", "-11.350842 | \n", "0.968750 | \n", "12.058968 | \n", "-177.232513 | \n", "-96.715340 | \n", "-1.847462 | \n", "-1.901900 | \n", "
97 | \n", "0.021700 | \n", "0.780336 | \n", "-11.284028 | \n", "0.968750 | \n", "12.064363 | \n", "-177.068573 | \n", "-96.441353 | \n", "-1.877259 | \n", "-1.912176 | \n", "
98 | \n", "0.043400 | \n", "0.778137 | \n", "-11.053716 | \n", "0.937500 | \n", "11.831852 | \n", "-184.003098 | \n", "-103.773109 | \n", "-1.870908 | \n", "-1.925162 | \n", "
99 | \n", "0.021700 | \n", "1.028205 | \n", "-11.553902 | \n", "0.968750 | \n", "12.582107 | \n", "-184.400208 | \n", "-100.089447 | \n", "-1.841471 | \n", "-1.905019 | \n", "
100 | \n", "0.021700 | \n", "0.353516 | \n", "-11.466562 | \n", "0.968750 | \n", "11.820077 | \n", "-183.305206 | \n", "-108.120209 | \n", "-1.876938 | \n", "-1.923044 | \n", "
101 | \n", "0.043400 | \n", "0.740837 | \n", "-11.065711 | \n", "0.937500 | \n", "11.806547 | \n", "-176.933624 | \n", "-97.440826 | \n", "-1.891777 | \n", "-1.920361 | \n", "
102 | \n", "0.047900 | \n", "0.593949 | \n", "-10.992206 | \n", "0.937500 | \n", "11.586155 | \n", "-175.206146 | \n", "-99.258972 | \n", "-1.911206 | \n", "-1.973414 | \n", "
103 | \n", "0.043400 | \n", "0.795841 | \n", "-11.449154 | \n", "0.937500 | \n", "12.244997 | \n", "-180.477692 | \n", "-98.055847 | \n", "-1.866122 | \n", "-1.917832 | \n", "
104 | \n", "0.043300 | \n", "0.777340 | \n", "-11.309653 | \n", "0.937500 | \n", "12.086990 | \n", "-182.164825 | \n", "-101.963196 | \n", "-1.882121 | \n", "-1.934470 | \n", "
105 | \n", "0.005000 | \n", "0.510335 | \n", "-11.900553 | \n", "1.000000 | \n", "12.410889 | \n", "-180.442368 | \n", "-98.240570 | \n", "-1.899688 | \n", "-1.961613 | \n", "
106 | \n", "0.065000 | \n", "0.755192 | \n", "-10.990764 | \n", "0.906250 | \n", "11.745956 | \n", "-190.304184 | \n", "-109.865013 | \n", "-1.858015 | \n", "-1.916487 | \n", "
107 | \n", "0.000000 | \n", "1.065331 | \n", "-12.421230 | \n", "1.000000 | \n", "13.486561 | \n", "-187.107025 | \n", "-98.055679 | \n", "-1.826416 | \n", "-1.885132 | \n", "
108 | \n", "0.000300 | \n", "0.820586 | \n", "-12.120082 | \n", "1.000000 | \n", "12.940668 | \n", "-183.174011 | \n", "-97.344032 | \n", "-1.837826 | \n", "-1.892154 | \n", "
109 | \n", "0.021700 | \n", "0.767417 | \n", "-12.461954 | \n", "0.968750 | \n", "13.229372 | \n", "-187.908081 | \n", "-100.196686 | \n", "-1.864809 | \n", "-1.928480 | \n", "
110 | \n", "0.108300 | \n", "0.333127 | \n", "-10.206629 | \n", "0.843750 | \n", "10.539757 | \n", "-189.532654 | \n", "-120.679733 | \n", "-1.939532 | \n", "-1.981758 | \n", "
111 | \n", "0.000000 | \n", "0.608623 | \n", "-12.230461 | \n", "1.000000 | \n", "12.839085 | \n", "-184.431778 | \n", "-97.517464 | \n", "-1.851851 | \n", "-1.908893 | \n", "
112 | \n", "0.043300 | \n", "0.947884 | \n", "-11.738710 | \n", "0.937500 | \n", "12.686596 | \n", "-188.261505 | \n", "-103.694641 | \n", "-1.801392 | \n", "-1.858541 | \n", "
113 | \n", "0.000000 | \n", "0.559098 | \n", "-12.441487 | \n", "1.000000 | \n", "13.000585 | \n", "-185.031815 | \n", "-95.259071 | \n", "-1.903439 | \n", "-1.963459 | \n", "
114 | \n", "0.043400 | \n", "0.555237 | \n", "-11.790924 | \n", "0.937500 | \n", "12.346161 | \n", "-185.853561 | \n", "-101.292900 | \n", "-1.846780 | \n", "-1.895535 | \n", "
115 | \n", "0.000100 | \n", "0.125599 | \n", "-12.235446 | \n", "1.000000 | \n", "12.361044 | \n", "-182.614731 | \n", "-100.348648 | \n", "-1.934710 | \n", "-1.989699 | \n", "
116 | \n", "0.021700 | \n", "0.642555 | \n", "-12.526094 | \n", "0.968750 | \n", "13.168651 | \n", "-189.841354 | \n", "-103.052399 | \n", "-1.879100 | \n", "-1.914975 | \n", "
117 | \n", "0.043400 | \n", "0.494508 | \n", "-11.364244 | \n", "0.937500 | \n", "11.858752 | \n", "-177.777603 | \n", "-97.124687 | \n", "-1.902839 | \n", "-1.956126 | \n", "
118 | \n", "0.086700 | \n", "0.205861 | \n", "-10.769080 | \n", "0.875000 | \n", "10.974942 | \n", "-178.435059 | \n", "-101.801300 | \n", "-1.822839 | \n", "-1.848876 | \n", "
119 | \n", "0.043300 | \n", "0.934836 | \n", "-12.007523 | \n", "0.937500 | \n", "12.942357 | \n", "-193.854340 | \n", "-108.625793 | \n", "-1.908241 | \n", "-1.976539 | \n", "
120 | \n", "0.043300 | \n", "0.825328 | \n", "-11.798796 | \n", "0.937500 | \n", "12.624125 | \n", "-183.718018 | \n", "-98.565102 | \n", "-1.834815 | \n", "-1.896412 | \n", "
121 | \n", "0.000000 | \n", "0.570292 | \n", "-12.685442 | \n", "1.000000 | \n", "13.255734 | \n", "-188.874359 | \n", "-100.744064 | \n", "-1.840728 | \n", "-1.892937 | \n", "
122 | \n", "0.022000 | \n", "0.273457 | \n", "-12.448065 | \n", "0.968750 | \n", "12.721522 | \n", "-191.319000 | \n", "-103.234337 | \n", "-1.869669 | \n", "-1.924867 | \n", "
123 | \n", "0.000000 | \n", "0.739589 | \n", "-12.444386 | \n", "1.000000 | \n", "13.183975 | \n", "-185.396912 | \n", "-97.543709 | \n", "-1.947350 | \n", "-2.009423 | \n", "
124 | \n", "0.043300 | \n", "0.471773 | \n", "-11.571946 | \n", "0.937500 | \n", "12.043719 | \n", "-185.468109 | \n", "-104.019699 | \n", "-1.850385 | \n", "-1.897007 | \n", "
125 | \n", "0.022300 | \n", "0.531008 | \n", "-11.633378 | \n", "0.968750 | \n", "12.164387 | \n", "-186.837265 | \n", "-103.420105 | \n", "-1.890191 | \n", "-1.948269 | \n", "
126 | \n", "0.065000 | \n", "0.459482 | \n", "-11.528692 | \n", "0.906250 | \n", "11.988175 | \n", "-190.393616 | \n", "-108.979614 | \n", "-1.813566 | \n", "-1.865598 | \n", "
127 | \n", "0.021700 | \n", "0.423156 | \n", "-12.373567 | \n", "0.968750 | \n", "12.796722 | \n", "-190.750916 | \n", "-109.170578 | \n", "-1.897676 | \n", "-1.958830 | \n", "
128 | \n", "0.065000 | \n", "0.275080 | \n", "-11.602432 | \n", "0.906250 | \n", "11.877512 | \n", "-193.196503 | \n", "-111.813087 | \n", "-1.807271 | \n", "-1.854911 | \n", "
129 | \n", "0.065000 | \n", "0.678916 | \n", "-11.713902 | \n", "0.906250 | \n", "12.392818 | \n", "-185.736496 | \n", "-101.049683 | \n", "-1.784050 | \n", "-1.826826 | \n", "
130 | \n", "0.022000 | \n", "0.559590 | \n", "-12.308511 | \n", "0.968750 | \n", "12.868102 | \n", "-184.687592 | \n", "-98.314713 | \n", "-1.856018 | \n", "-1.913242 | \n", "
131 | \n", "0.043400 | \n", "0.097012 | \n", "-11.926088 | \n", "0.937500 | \n", "12.023101 | \n", "-188.560669 | \n", "-105.093018 | \n", "-1.851667 | \n", "-1.904052 | \n", "
132 | \n", "0.022300 | \n", "0.631916 | \n", "-12.291891 | \n", "0.968750 | \n", "12.923808 | \n", "-188.667206 | \n", "-97.602272 | \n", "-1.806342 | \n", "-1.856767 | \n", "
133 | \n", "0.000000 | \n", "0.044295 | \n", "-12.732799 | \n", "1.000000 | \n", "12.777093 | \n", "-187.832306 | \n", "-100.222107 | \n", "-1.891387 | \n", "-1.941179 | \n", "
134 | \n", "0.000000 | \n", "0.164928 | \n", "-12.651648 | \n", "1.000000 | \n", "12.816574 | \n", "-187.047821 | \n", "-98.899582 | \n", "-1.874540 | \n", "-1.929160 | \n", "
135 | \n", "0.065000 | \n", "0.464494 | \n", "-11.582067 | \n", "0.906250 | \n", "12.046560 | \n", "-189.952942 | \n", "-108.556725 | \n", "-1.867593 | \n", "-1.907906 | \n", "
136 | \n", "0.021700 | \n", "0.643924 | \n", "-12.101431 | \n", "0.968750 | \n", "12.745355 | \n", "-185.185471 | \n", "-98.936203 | \n", "-1.871088 | \n", "-1.915239 | \n", "
137 | \n", "0.000000 | \n", "0.903751 | \n", "-13.132103 | \n", "1.000000 | \n", "14.035853 | \n", "-194.401794 | \n", "-100.999130 | \n", "-1.854176 | \n", "-1.924202 | \n", "
138 | \n", "0.021700 | \n", "0.220121 | \n", "-12.084657 | \n", "0.968750 | \n", "12.304777 | \n", "-183.585602 | \n", "-103.130791 | \n", "-1.924400 | \n", "-1.970213 | \n", "
139 | \n", "0.043300 | \n", "0.702169 | \n", "-12.528625 | \n", "0.937500 | \n", "13.230795 | \n", "-191.237183 | \n", "-99.048164 | \n", "-1.875030 | \n", "-1.935427 | \n", "
140 | \n", "0.021700 | \n", "0.188731 | \n", "-12.251818 | \n", "0.968750 | \n", "12.440548 | \n", "-182.995895 | \n", "-100.707130 | \n", "-1.856969 | \n", "-1.898762 | \n", "
141 | \n", "0.021700 | \n", "0.410915 | \n", "-12.602050 | \n", "0.968750 | \n", "13.012966 | \n", "-191.560379 | \n", "-102.686310 | \n", "-1.854935 | \n", "-1.909470 | \n", "
142 | \n", "0.021700 | \n", "0.217397 | \n", "-12.414885 | \n", "0.968750 | \n", "12.632282 | \n", "-190.334549 | \n", "-103.550301 | \n", "-1.847357 | \n", "-1.893018 | \n", "
143 | \n", "0.043400 | \n", "0.188853 | \n", "-12.007719 | \n", "0.937500 | \n", "12.196571 | \n", "-189.096664 | \n", "-107.576408 | \n", "-1.886003 | \n", "-1.934517 | \n", "
144 | \n", "0.000200 | \n", "0.041079 | \n", "-12.729925 | \n", "1.000000 | \n", "12.771004 | \n", "-187.678024 | \n", "-102.643410 | \n", "-1.855476 | \n", "-1.908435 | \n", "
145 | \n", "0.000200 | \n", "0.173133 | \n", "-13.049847 | \n", "1.000000 | \n", "13.222980 | \n", "-190.878754 | \n", "-100.978210 | \n", "-1.942114 | \n", "-1.991033 | \n", "
146 | \n", "0.021700 | \n", "0.385140 | \n", "-12.866081 | \n", "0.968750 | \n", "13.251221 | \n", "-193.286530 | \n", "-102.303047 | \n", "-1.845515 | \n", "-1.901057 | \n", "
147 | \n", "0.021700 | \n", "0.698989 | \n", "-12.833589 | \n", "0.968750 | \n", "13.532578 | \n", "-195.435760 | \n", "-101.922058 | \n", "-1.862593 | \n", "-1.925970 | \n", "
148 | \n", "0.021700 | \n", "0.047423 | \n", "-12.806502 | \n", "0.968750 | \n", "12.853926 | \n", "-190.005981 | \n", "-102.509384 | \n", "-1.928422 | \n", "-1.979353 | \n", "
149 | \n", "0.021700 | \n", "0.114320 | \n", "-12.714529 | \n", "0.968750 | \n", "12.828848 | \n", "-192.607773 | \n", "-104.419044 | \n", "-1.884816 | \n", "-1.930242 | \n", "
150 | \n", "0.021700 | \n", "0.589908 | \n", "-13.166811 | \n", "0.968750 | \n", "13.756720 | \n", "-196.869293 | \n", "-101.493034 | \n", "-1.864991 | \n", "-1.928835 | \n", "
151 | \n", "0.021700 | \n", "0.591138 | \n", "-12.835053 | \n", "0.968750 | \n", "13.426191 | \n", "-197.652100 | \n", "-104.080139 | \n", "-1.834763 | \n", "-1.896774 | \n", "
152 | \n", "0.021700 | \n", "0.310052 | \n", "-13.003990 | \n", "0.968750 | \n", "13.314042 | \n", "-192.777863 | \n", "-103.133842 | \n", "-1.862719 | \n", "-1.927921 | \n", "
153 | \n", "0.043300 | \n", "0.520161 | \n", "-12.309970 | \n", "0.937500 | \n", "12.830130 | \n", "-187.454056 | \n", "-99.989044 | \n", "-1.925316 | \n", "-1.975242 | \n", "
154 | \n", "0.021700 | \n", "0.421074 | \n", "-12.678178 | \n", "0.968750 | \n", "13.099251 | \n", "-200.323975 | \n", "-108.994141 | \n", "-1.800578 | \n", "-1.845382 | \n", "
155 | \n", "0.000000 | \n", "0.322216 | \n", "-13.534782 | \n", "1.000000 | \n", "13.856998 | \n", "-197.107590 | \n", "-101.961754 | \n", "-1.834417 | \n", "-1.891570 | \n", "
156 | \n", "0.108400 | \n", "0.463126 | \n", "-11.175941 | \n", "0.843750 | \n", "11.639068 | \n", "-192.982330 | \n", "-113.173698 | \n", "-1.873569 | \n", "-1.923092 | \n", "
157 | \n", "0.021700 | \n", "0.320651 | \n", "-13.012464 | \n", "0.968750 | \n", "13.333115 | \n", "-193.609802 | \n", "-101.025909 | \n", "-1.886778 | \n", "-1.941732 | \n", "
158 | \n", "0.021700 | \n", "-0.053605 | \n", "-12.809851 | \n", "0.968750 | \n", "12.756245 | \n", "-190.638290 | \n", "-103.844734 | \n", "-1.896181 | \n", "-1.946830 | \n", "
159 | \n", "0.043300 | \n", "0.467275 | \n", "-12.603289 | \n", "0.937500 | \n", "13.070563 | \n", "-195.226746 | \n", "-106.574730 | \n", "-1.899510 | \n", "-1.969057 | \n", "
160 | \n", "0.021900 | \n", "0.472549 | \n", "-13.025349 | \n", "0.968750 | \n", "13.497898 | \n", "-201.843353 | \n", "-109.387970 | \n", "-1.904034 | \n", "-1.945622 | \n", "
161 | \n", "0.000000 | \n", "0.385234 | \n", "-13.326250 | \n", "1.000000 | \n", "13.711485 | \n", "-193.756165 | \n", "-97.907196 | \n", "-1.822776 | \n", "-1.882171 | \n", "
162 | \n", "0.021700 | \n", "0.529081 | \n", "-12.984616 | \n", "0.968750 | \n", "13.513697 | \n", "-192.312454 | \n", "-100.750130 | \n", "-1.870952 | \n", "-1.934668 | \n", "
163 | \n", "0.021700 | \n", "0.331054 | \n", "-12.972366 | \n", "0.968750 | \n", "13.303420 | \n", "-200.855682 | \n", "-108.632874 | \n", "-1.873858 | \n", "-1.921691 | \n", "
164 | \n", "0.021700 | \n", "0.493049 | \n", "-12.684418 | \n", "0.968750 | \n", "13.177465 | \n", "-187.966919 | \n", "-95.420746 | \n", "-1.864515 | \n", "-1.917675 | \n", "
165 | \n", "0.021700 | \n", "0.420934 | \n", "-12.589132 | \n", "0.968750 | \n", "13.010067 | \n", "-188.447311 | \n", "-97.481064 | \n", "-1.849078 | \n", "-1.897848 | \n", "
166 | \n", "0.000000 | \n", "0.676847 | \n", "-12.927957 | \n", "1.000000 | \n", "13.604802 | \n", "-192.431091 | \n", "-100.556358 | \n", "-1.914310 | \n", "-1.972500 | \n", "
167 | \n", "0.021700 | \n", "0.715845 | \n", "-12.764927 | \n", "0.968750 | \n", "13.480774 | \n", "-194.916611 | \n", "-99.511650 | \n", "-1.867445 | \n", "-1.924852 | \n", "
"
],
"text/plain": [
"