diff --git a/instructlab-tutorial/01-setup.html b/instructlab-tutorial/01-setup.html index dfa61f9..0e9ab45 100644 --- a/instructlab-tutorial/01-setup.html +++ b/instructlab-tutorial/01-setup.html @@ -102,266 +102,61 @@

Setup

Prerequisite CLI tools

-

The following CLI tools are required for running the exercises in this tutorial. -Please have them installed and configured before you get started with any of the tutorial chapters.

+

For this deep dive you need the ilab CLI tool installed. +It handles the main tuning workflow. +Currently, it supports Linux systems and Apple/Silicon Macs (M1/M2/M3), as well as Windows with WSL2.

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ToolmacOSFedorawindows

Git

Download

Download

Download

Docker

Docker for Mac

dnf install docker

Docker for Windows

VirtualBox

Download

Download

Download

Minikube v1.29.0

Download

Download

Download

kubectl v1.26.1

Download

Download

Download

stern

brew install stern

Download

Download

Apache Maven 3.9.0

Download

Download

Download

-
-

The following CLI tools are optional for running the exercises in this tutorial. -Although they are used in the tutorial, you could use others without any problem.

-
- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ToolmacOSFedorawindows

yq v2.4.1

Download

Download

Download

jq v1.6.0

Download

Download

Download

httpie

brew install httpie

dnf install httpie

https://httpie.org/doc#windows-etc

watch

brew install watch

dnf install procps-ng

kubectx and kubens

brew install kubectx

https://github.com/ahmetb/kubectx

hey

brew install hey

Download

Download

-
- -
-

Setup Kubernetes

-
-

The profile my_profile is created to run the tutorial:

+

The installation instructions are different depending on your operative system and/or if you want to use ilab with or without GPU.

-
-
-
    -
  • -

    Minikube

    -
  • -
  • -

    OpenShift

    -
  • -
-
-
-
-

Having minikube installed and in your PATH, then run:

-
-
-

MacOS

-
-
-
-
minikube start --memory=8192 --cpus=3 --kubernetes-version=v1.26.1 --vm-driver=virtualbox -p my_profile
-
+

Moreover, you install InstructLab CLI using Python (as it is the easiest way), and you might use tools like pyenv to isolate the installation.

-

Linux

-
-
-
-
minikube start --memory=8192 --cpus=3 --kubernetes-version=v1.26.1 --vm-driver=kvm2 -p my_profile
-
-
-
-

Windows:

-
-
-
-
minikube start --memory=8192 --cpus=3 --kubernetes-version=v1.26.1 --vm-driver=hyperv -p my_profile
-
-
-
-

And the output must be something similar like:

-
-
-
-
๐Ÿ˜„  [my_profile] minikube v1.20.0 on Darwin 11.3
-โœ…  Created a new profile : my_profile
-โœ…  minikube profile was successfully set to my_profile
-๐Ÿ˜„  [default] minikube v1.29.0 on Darwin 11.3
-โœจ  Selecting 'virtualbox' driver from user configuration (alternates: [hyperkit])
-๐Ÿ”ฅ  Creating virtualbox VM (CPUs=2, Memory=8192MB, Disk=50000MB) ...
-๐Ÿณ  Preparing Kubernetes v1.26.1 on Docker '20.10.6' ...
-    โ–ช apiserver.enable-admission-plugins=LimitRanger,NamespaceExists,NamespaceLifecycle,ResourceQuota,ServiceAccount,DefaultStorageClass,MutatingAdmissionWebhook
-๐Ÿšœ  Pulling images ...
-๐Ÿš€  Launching Kubernetes ...
-โŒ›  Waiting for cluster to come online ...
-๐Ÿ„  Done! kubectl is now configured to use "my_profile"
+

For this reason, we recommend you take a look at Installing ilab and install ilab in the more convenient.

+
+ + + + + +
+ + +At this time you need to use Python 3.10 or 3.11, not any other Python version is supported. +
-

Finally configure to use minikube internal docker as docker host:

+

The following snippet shows the installation in a Apple Mac:

-
eval $(minikube docker-env -p my_profile)
-
-
-
-
-
-

To run OpenShift4, you need to have one provisioned using try.openshift.com or can use any existing OpenShift4 cluster. -Once you have your cluster, you can download the latest OpenShift client(oc) from here and add to your path.

-
-
-
-
oc version
+
mkdir instructlab && cd instructlab
+
+python3 -m venv --upgrade-deps venv
+source venv/bin/activate
+
+pip cache remove llama_cpp_python
+
+pip install 'instructlab[mps]==0.19.3'
-

You can check the OpenShift version using:

+

To check if ilab is installed correctly run the following command:

-
oc version
-
+
ilab --version
-
-

The output should show oc version >=4.7:

-
Client Version: 4.7.0-202102130115.p0-c66c03f
-Kubernetes Version: v1.26.1
+
ilab, version 0.19.3
-

Then login into the OpenShift cluster using oc login

-
-
-
-
-
-

And then you are ready for start using Kubernetes:

-
-
-
-kubelogo -
-
-
-
-
-

Get tutorial sources

-
-
-

Before we start setting up the environment, letโ€™s clone the tutorial sources and set the TUTORIAL_HOME environment variable to point to the root directory of the tutorial:

-
- -
-
-
export TUTORIAL_HOME="$(pwd)/my_folder"
-
-
-
-
-
cd $TUTORIAL_HOME
-
+

You should see the ilab version printed, at this time version 0.19.3.

diff --git a/instructlab-tutorial/02-deploy.html b/instructlab-tutorial/02-deploy.html index a6bf273..2218476 100644 --- a/instructlab-tutorial/02-deploy.html +++ b/instructlab-tutorial/02-deploy.html @@ -3,7 +3,7 @@ - Deploy Service :: InstructLab Tutorial + Serving Models :: InstructLab Tutorial @@ -96,81 +96,177 @@

-

Deploy Service

+

Serving Models

-

The Service

+

Initializing InstructLab

-

The code:

+

With ilab installed, we can initialize our tuning environment with the ilab config init command. +This will download the Taxonomy repository which contains a default configuration file and community-provided knowledge as examples to train the model.

-
+
-
public class Main {
-
-    public static void main(String[] args) {
-
-    }
-
-}
-
-./mvnw compile
+
ilab config init
+
+
+
+ + + + + +
+ + +You could scaffold your taxonomy repository with your organization defaults, but for now, we’ll stick with the default one. +
+
+
+
+
Welcome to InstructLab CLI. This guide will help you to setup your environment.
+Please provide the following values to initiate the environment [press Enter for defaults]:
+Path to taxonomy repo [/Users/asotobue/.local/share/instructlab/taxonomy]:
+./taxonomy seems to not exist or is empty. Should I clone https://github.com/instructlab/taxonomy.git for you? [Y/n]:
+Cloning https://github.com/instructlab/taxonomy.git...
+Path to your model [/Users/asotobue/.cache/instructlab/models/merlinite-7b-lab-Q4_K_M.gguf]:
+Generating `/Users/asotobue/.config/instructlab/config.yaml`
+Please choose a train profile to use.
+Train profiles assist with the complexity of configuring InstructLab training for specific GPU hardware.
+You can still take advantage of hardware acceleration for training even if your hardware is not listed.
+[0] No profile (CPU, Apple Metal, AMD ROCm)
+[1] Nvidia A100/H100 x2 (A100_H100_x2.yaml)
+[2] Nvidia A100/H100 x4 (A100_H100_x4.yaml)
+[3] Nvidia A100/H100 x8 (A100_H100_x8.yaml)
+[4] Nvidia L40 x4 (L40_x4.yaml)
+[5] Nvidia L40 x8 (L40_x8.yaml)
+[6] Nvidia L4 x8 (L4_x8.yaml)
+...
+
+
+

The most important file there is the configuration file, which defines the foundational model weโ€™ll be training and includes defaults such as parameters for training and serving. +File is placed by default at <home>/.config/instructlab/config.yaml.

+
+
+

In this example, we use merlinite-7b as a model, but you could use Granite, Mistral, Llama, or any other supported model (gguf format).

-

Packaging the Service

+

Downloading, serving, and testing a model with InstructLab

+
+

Downlaoding a model

-

You can package the next bash script:

+

Before fine-tuning the model, let’s test the model with default training. +To get started, download Merlinite pre-trained & quantized model with the ilab model download command.

-
+
-
#!/bin/sh
-echo "Hello World"
+
ilab model download
+
+
+
Downloading model from instructlab/merlinite-7b-lab-GGUF@main to models...
+Downloading 'merlinite-7b-lab-Q4_K_M.gguf' to 'models/.huggingface/download/merlinite-7b-lab-Q4_K_M.gguf.9ca044d727db34750e1aeb04e3b18c3cf4a8c064a9ac96cf00448c506631d16c.incomplete'
+INFO 2024-06-11 23:21:23,255 file_download.py:1877 Downloading 'merlinite-7b-lab-Q4_K_M.gguf' to 'models/.huggingface/download/merlinite-7b-lab-Q4_K_M.gguf.9ca044d727db34750e1aeb04e3b18c3cf4a8c064a9ac96cf00448c506631d16c.incomplete'
+merlinite-7b-lab-Q4_K_M.gguf:   2%|โ–Š       | 105M/4.37G [01:23<57:18, 1.24MB/s]
-
-

Deploy the Service

-
-

And then you can deploy the service and execute commands inside:

+

Now, letโ€™s serve the model to be inferenced from your local machine.

+
+
+

Serving a model

-

Check that the pod is up and running:

+

To serve a model with InstructLab, use the ilab model serve command.

-
+
-
kubectl get pods
+
ilab model serve
-
NAME                        READY   STATUS    RESTARTS   AGE
-apps   1/1     Running   0          5s
+
INFO 2024-06-11 23:27:21,994 lab.py:340 Using model 'models/merlinite-7b-lab-Q4_K_M.gguf' with -1 gpu-layers and 4096 max context size.
+INFO 2024-06-11 23:27:40,984 server.py:206 Starting server process, press CTRL+C to shutdown server...
+INFO 2024-06-11 23:27:40,984 server.py:207 After application startup complete see http://127.0.0.1:8000/docs for API.
+
+
+
+

Now, model is deployed locally and you can interact with it. +You have three options:

+
+
+
    +
  • +

    InstructLab exposes the model using OpenAI API, so you can develop an application using for example LangChain, and interact with it.

    +
  • +
  • +

    Navigate to http://127.0.0.1:8000/docs to visit the Swagger UI of the model and interact with it.

    +
  • +
  • +

    Use ilab model chat command.

    +
  • +
+
+

Testing a model

-

Then let’s go into the running pod to execute some commands:

+

Let’s use the later approach to interact with the model.

+
+
+

Open a new terminal window, and navigate to your InstructLab directory, and enter your virtual environment again by running source venv/bin/activate.

+
+
+

Then run ilab model chat to enter a simple interface for conversing with the LLM.

-
kubectl exec -ti apps /bin/bash
+
source venv/bin/activate
+
+ilab model chat
-
- - - - - -
- - -Change the pod name with your pod name. -
+
+
+
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
+โ”‚ Welcome to InstructLab Chat w/ MODELS/MERLINITE-7B-LAB-Q4_K_M.GGUF (type /h for help)                                โ”‚
+โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
+>>> What languages are spoken in Canada?
+โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ models/merlinite-7b-lab-Q4_K_M.gguf
+โ”‚ Canadian society is multilingual, with English and French being the two official languages recognized at the federal level.
+
+
+
+

But then query the following question: what is the price of a new Flux capacitor for DeLorean car. +You’ll receive a polite answer saying that has no knowledge to answe this question.

+
+
+
+
What is the price of a new Flux capacitor for DeLorean car?
+
+
+
+
+
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
+โ”‚ I understand that you re asking about the cost of a flux capacitor for a specific model
+....
+
+
+
+

So, obviously we need to fine-tuning our model to have the konwledge about the Back To the Future movie and De-Lorean car.

+
+
+

Then, type exit to stop the interactive chat window. +Also, stop serving the model by typing Ctrl+C to stop the process.

+
+
+

Let’s move to the next section to learn how to fine-tune a model.

+
diff --git a/instructlab-tutorial/03-train.html b/instructlab-tutorial/03-train.html new file mode 100644 index 0000000..54b2c88 --- /dev/null +++ b/instructlab-tutorial/03-train.html @@ -0,0 +1,305 @@ + + + + + + Model alignment and training :: InstructLab Tutorial + + + + + +
+ +
+
+ +
+ +
+
+

Model alignment and training

+
+
+
+

Large Language Models, while impressive in their ability to conversate and recall training information, sometimes they arenโ€™t aware of specific details due to their large training set of data.

+
+
+

Letโ€™s learn how to contribute the correct information to this model using InstructLab!

+
+
+
+
+

Adding knowledge and skills to an LLM

+
+
+

In a new terminal window, navigate to the taxonomy directory (<home>/.local/share/instructlab/taxonomy) that was cloned during the initialization step. +Here, you’ll find two main subdirectories: knowledge and skills. +As the names suggest, knowledge refers to factual information you want to add to the model, while skills involve teaching the model to perform specific tasks or follow certain formats.

+
+
+

Let’s say we want to add knowledge about the Back to the Future movie, which would be considered an addition of knowledge to the model.

+
+
+

Create a new subfolder in taxonomy directory and a qna.yaml (questions & answers) file to hold example question-answer pairs related to DeLorean car.

+
+
+
+
cd knowledge
+
+mkdir -p trivia/delorean
+cd trivia/delorean
+
+
+
+

And create the qna.yaml file inside this new directory. +The file structure is not complicated, first it contains some metadata, then you can add some Q&A pairs that can be included in the fine-tuning process. +There is also a link to a public repository for additional data points from which InstructLab will generate additional question-and-answer pairs. +This additional data will be used to generate synthetic question-answer pairs during the next step.

+
+
+
qna.yaml
+
+
version: 3
+domain: time_travel
+created_by: RH Developers
+seed_examples:
+  - context: |
+      The DeLorean DMC-12 is a sports car manufactured by John DeLorean's DeLorean Motor Company
+      for the American market from 1981 to 1983. The car features gull-wing doors and a stainless-steel body.
+      It gained fame for its appearance as the time machine in the "Back to the Future" film trilogy.
+    questions_and_answers:
+      - question: |
+          When was the DeLorean manufactured?
+        answer: |
+          The DeLorean was manufactured from 1981 to 1983.
+      - question: |
+          Who manufactured the DeLorean DMC-12?
+        answer: |
+          The DeLorean Motor Company manufactured the DeLorean DMC-12.
+      - question: |
+          What type of doors does the DeLorean DMC-12 have?
+        answer: |
+          Gull-wing doors.
+  - context: |
+      An engine rebuild costs between $5,000 to $7,000. A transmission rebuild costs between $2,500 to $4,000.
+      A brake system overhaul costs between $1,000 to $1,500.
+      Suspension work costs between $800 to $1,200.
+      Electrical system repairs costs between $600 to $1,000.
+      Stainless stell panel work costs between $1,200 to $2,000.
+      A gull-wing door mechanism costs between $500 to $800.
+      Repairing an air conditioner costs between $300 and $600.
+      General maintenance is between $200 and $500 per service.
+      A Flux capacitor costs $10,000,000 to repair.
+    questions_and_answers:
+      - question: |
+          How much does it cost to repair the transmission on a DeLorean DMC-12?
+        answer: |
+          Transmission Repair costs between $2,500 and $4,000 for the Delorean DMC-12.
+      - question: How much does it cost to repair the supension on a DeLorean DMC-12?
+        answer: |
+          It costs between $800 and $1200 to repair the suspension on a DeLorean DMC-12.
+      - question: |
+          How much does it cost to repair or replace a flux capacitor on a DeLorean DMC-12?
+        answer: |
+          It costs $10,000,000 to repair a flux capacitor.
+  - context: |
+      Production Years: 1981โ€“1983
+      Body Style: 2-door coupe
+      Engine: 2.85 L V6 PRV engine
+      Transmission 5-speed manual or 3-speed automatic
+      Horsepower 130 hp
+      153 lb-ft
+      Approximately 8.8 seconds
+      110 mph
+      2,712 lb (1,230 kg)
+      Flux capacitor fitted for time travel and costs $10,000,000
+    questions_and_answers:
+      - question: What was the production years of the DeLorean DMC-12?
+        answer: |
+          The car was in production from 1981 to 1983.
+      - question: |
+          How much horsepower does the DeLorean have?
+        answer: |
+          It has 130 horsepower.
+      - question: |
+          What is the flux capacitor used for in a Delorean DMC-12?
+        answer: |
+          The flux capacitor is used for time travel capabilities and costs $10,000,000.
+  - context: |
+      Here is a maintenance schedule.
+      Regular Oil Changes should be done every 3,000 miles or 3 months.
+      Brake Fluid should be changed every 2 years.
+      Transmission Fluid should be changed every 30,000 miles.
+      Coolant should be changed every 2 years
+      You should regularly check the battery for corrosion and proper connection.
+      You should add new fluid to the flux capacitor on a regular basis.
+    questions_and_answers:
+      - question: How often should you change the oil on a DeLorean DMC-12?
+        answer: |
+          You should change the oil ever 3,000 miles or every 3 months. Whichever comes first.
+      - question: |
+          How often should changed the blake fluid on a DeLorean DMC-12?
+        answer: |
+          You should change the blake fluid every two years.
+      - question: |
+          What should you check on a Delorean DMC-12 as part of a regular maintenance schedule?
+        answer: |
+          You should consider regular oil changes, blake fluid replacement, transmission fluid, battery,
+          flux capacitor and collant.
+  - context: |
+      Here are some fun facts about the DeLorean DMC-12:
+      The DeLorean DMC-12 was originally intended to have a mid-engine layout, but this was later changed
+      to a rear-engine layout due to design and cost constraints.
+      The DeLorean time machine special edition can time travel by accelerating to 88 miles per hour.
+      The flux capacitor, which enables time travel, costs $10,000,000 dollars.
+    questions_and_answers:
+      - question: |
+          How much does it cost to repair a flux capacitor on a Delorean DMC-12?
+        answer: |
+          It costs $10,000,000 to repair or replace a flux capacitor.
+      - question: |
+          How fast do you need to be going to enable time travel on a DeLorean DMC-12?
+        answer: |
+          88 miles per hour.
+      - question: |
+          What type of layout does a Delorean DMC-12 have?
+        answer: |
+          It has a rear-engine layout.
+document_outline: |
+  Details and repair costs on a DeLorean DMC-12 car.
+document:
+  repo: https://github.com/gshipley/backToTheFuture.git
+  commit: 8bd9220c616afe24b9673d94ec1adce85320809c
+  patterns:
+    - data.md
+
+
+
+

Then run the following command to verify the new data is valid in the terminal window where you’ve been running ilab in the previous steps. +This is important to run it in the same virtual environment created at the beginning of the deep dive.

+
+
+
+
ilab taxonomy diff
+
+
+
+
+
knowledge/trivia/delorean/qna.yaml
+
+Taxonomy in ... is valid :)
+
+
+
+
+
+

Generating synthetic data for model training

+
+
+

So we’ve added some task-specific knowledgeโ€”now what? T

+
+
+

he next step is to use InstructLab’s synthetic data generation pipeline to create a large training set from the examples.

+
+
+

The key insight behind InstructLab’s LAB method is that we can use the base model itself to massively expand a small set of human-provided examples. +By prompting the model to generate completions conditioned on your examples, we can produce a synthetic dataset that’s much larger and more diverse than what you could feasibly write by hand.

+
+
+

We can run the ilab data generate command to begin generating synthetic data (by default, 100 data points). Remember, we still need to be serving the model with ilab model serve in another terminal instance.

+
+
+
+
+ +
+
+
+
+

-

Welcome to Template Tutorial

+

Welcome to InstructLab Tutorial

-

Publish Services to Kubernetes

+

Getting started with InstructLab

-

A Kubernetes tutorial to show how you can deploy a Java service to a Kubernetes cluster as it was a child game.

+

InstructLab provides tools to enhance LLMs with additional knowledge and skills using a novel approach called LAB

diff --git a/sitemap.xml b/sitemap.xml index 898eee4..ce8feb9 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,14 +2,18 @@ https://redhat-scholars.github.io/instructlab-deep-dive/instructlab-tutorial/01-setup.html -2024-10-04T10:55:54.051Z +2024-10-11T16:12:57.119Z https://redhat-scholars.github.io/instructlab-deep-dive/instructlab-tutorial/02-deploy.html -2024-10-04T10:55:54.051Z +2024-10-11T16:12:57.119Z + + +https://redhat-scholars.github.io/instructlab-deep-dive/instructlab-tutorial/03-train.html +2024-10-11T16:12:57.119Z https://redhat-scholars.github.io/instructlab-deep-dive/instructlab-tutorial/index.html -2024-10-04T10:55:54.051Z +2024-10-11T16:12:57.119Z