{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "malpM0sXFn9K" }, "source": [ "Install required packages" ] }, { "cell_type": "code", "execution_count": 82, "metadata": { "id": "bvHV20Q0vGkE" }, "outputs": [], "source": [ "from IPython.display import clear_output\n", "\n", "!pip install -qqq --upgrade bitsandbytes transformers peft accelerate datasets trl flash_attn\n", "!pip install huggingface_hub\n", "!pip install python-dotenv\n", "!pip install absl-py nltk rouge_score\n", "!pip list | grep transformers.\n", "\n", "clear_output()" ] }, { "cell_type": "markdown", "metadata": { "id": "fx_7c7MJoqmW" }, "source": [ "Import packages" ] }, { "cell_type": "code", "execution_count": 83, "metadata": { "id": "Mrn1Z3usdTEG" }, "outputs": [], "source": [ "import numpy as np\n", "import torch\n", "import pandas as pd\n", "from datasets import Dataset, load_metric\n", "from peft import LoraConfig, prepare_model_for_kbit_training, PeftModel, get_peft_model\n", "from transformers import (AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TrainingArguments, set_seed, pipeline)\n", "from trl import SFTTrainer" ] }, { "cell_type": "markdown", "metadata": { "id": "qa80IqnWJL_m" }, "source": [ "Define parameters" ] }, { "cell_type": "code", "execution_count": 84, "metadata": { "id": "Y5dL-Zn6gDk5" }, "outputs": [], "source": [ "# Name of the model to use as parent model\n", "base_model_name = \"microsoft/Phi-3-mini-4k-instruct\"\n", "\n", "# Name of the new model\n", "model_name=\"acorreal/project-management-tutor\"\n", "\n", "# Set the model configuration\n", "use_4bit = True\n", "bnb_4bit_quant_type = \"nf4\"\n", "use_double_quant = True\n", "set_seed(1234)" ] }, { "cell_type": "markdown", "metadata": { "id": "Z3pJIh4h3Usa" }, "source": [ "Connect to Huggingface Hub" ] }, { "cell_type": "code", "execution_count": 85, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "GgZlM-ov461d", "outputId": "f0fe1cf2-3627-43cd-f0c4-4f59cecff75a" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The token has not been saved to the git credentials helper. Pass `add_to_git_credential=True` in this function directly or `--add-to-git-credential` if using via `huggingface-cli` if you want to set the git credential as well.\n", "Token is valid (permission: write).\n", "Your token has been saved to /root/.cache/huggingface/token\n", "Login successful\n" ] } ], "source": [ "from huggingface_hub import login\n", "from google.colab import userdata\n", "\n", "login(token=userdata.get('HF_TOKEN'))" ] }, { "cell_type": "markdown", "metadata": { "id": "HJjE6hP3vt_Z" }, "source": [ "Load the dataset with the instruction set" ] }, { "cell_type": "code", "execution_count": 86, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 293 }, "id": "_Rum2HpfdTEH", "outputId": "33c2d7df-ac76-44ef-ea8b-ff8a1573dee5" }, "outputs": [ { "data": { "application/vnd.google.colaboratory.intrinsic+json": { "summary": "{\n \"name\": \"df\",\n \"rows\": 1042,\n \"fields\": [\n {\n \"column\": \"question\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 807,\n \"samples\": [\n \"How do you ensure project deliverables are accepted by stakeholders?\",\n \"What aspect of word relationships do word embeddings understand better than traditional methods?\",\n \"How does understanding probability help in natural language processing?\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"answer\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 843,\n \"samples\": [\n \"PRINCE2 (Projects IN Controlled Environments) is a process-based project management methodology.\",\n \"It enables developers to accurately analyze data distributions and make informed predictions based on statistical models.\",\n \"A project assumption log is a document that records all project assumptions, tracking their status and impact on the project.\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"instruction\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n \"You are an expert in project management, tasked with helping students master project management principles, including the Unified Process. Provide guidance on planning, executing, and closing projects, covering key concepts like scope, time, cost, quality, risk management, and stakeholder engagement. Use practical examples, case studies, and interactive discussions to enhance their knowledge and application of these skills in real-world scenarios.:\\n\\n\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}", "type": "dataframe", "variable_name": "df" }, "text/html": [ "\n", "
\n", " | question | \n", "answer | \n", "instruction | \n", "
---|---|---|---|
0 | \n", "What is the primary focus of the book \"CogiMes... | \n", "The book focuses on teaching AI model engineer... | \n", "You are an expert in project management, taske... | \n", "
1 | \n", "Who is Aria Gray, and what is her role at Nebu... | \n", "Aria Gray is a fresh graduate in Computational... | \n", "You are an expert in project management, taske... | \n", "
2 | \n", "What is MLflow, and why is it important in AI ... | \n", "MLflow is a platform that manages the machine ... | \n", "You are an expert in project management, taske... | \n", "
3 | \n", "What is MLOps, and how does it relate to AI de... | \n", "MLOps is a practice for collaboration between ... | \n", "You are an expert in project management, taske... | \n", "
4 | \n", "What are the four main components of MLflow? | \n", "The four main components of MLflow are Trackin... | \n", "You are an expert in project management, taske... | \n", "
Epoch | \n", "Training Loss | \n", "Validation Loss | \n", "
---|---|---|
1 | \n", "No log | \n", "No log | \n", "
"
],
"text/plain": [
"