|
| 1 | +# Quick Start Guide |
| 2 | + |
| 3 | +## Table of contents |
| 4 | +1. [Install ilab](#install-ilab) |
| 5 | +2. [Initialize ilab](#%EF%B8%8F-initialize-ilab) |
| 6 | +3. [Download the model](#-download-the-model) |
| 7 | +4. [Serving the model](#-serving-the-model) |
| 8 | +5. [Train the model](#%EF%B8%8F-training-and-interacting-with-the-model) |
| 9 | + |
| 10 | +This Quick Start Guide will help you get InstructLab |
| 11 | +working on your laptop or machine and is expected to take approximately XX minutes. If you'd like more details on this process, see [the Taxonomy README](https://github.com/instructlab/taxonomy/blob/main/README.md) or if you'd like more information on the `cli`, please see [the ilab CLI README](https://github.com/instructlab/instructlab/blob/main/README.md) |
| 12 | + |
| 13 | + |
| 14 | +### Install `ilab` |
| 15 | + |
| 16 | +## 📋 Requirements |
| 17 | + |
| 18 | +- **🍎 Apple M1/M2/M3 Mac or 🐧 Linux system** (tested on Fedora). We anticipate support for more operating systems in the future. |
| 19 | +- C++ compiler |
| 20 | +- Python 3.9+ |
| 21 | +- Approximately 60GB disk space (entire process) |
| 22 | + |
| 23 | + |
| 24 | +## ✅ Getting started |
| 25 | + |
| 26 | +### 🧰 Installing `ilab` |
| 27 | + |
| 28 | +1. If you are on Fedora Linux, install C++, Python 3.9+, and other necessary tools by running the following command: |
| 29 | + |
| 30 | + ```bash |
| 31 | + sudo dnf install g++ gcc make pip python3 python3-devel python3-GitPython |
| 32 | + ``` |
| 33 | + |
| 34 | + Optional: If g++ is not found, try 'gcc-c++' by running the following command: |
| 35 | + |
| 36 | + ```bash |
| 37 | + sudo dnf install gcc-c++ gcc make pip python3 python3-devel python3-GitPython |
| 38 | + ``` |
| 39 | + |
| 40 | +2. Create a new directory called `instructlab` to store the files the `ilab` CLI needs when running and CD into the directory by running the following command: |
| 41 | + |
| 42 | + ```bash |
| 43 | + mkdir instructlab |
| 44 | + cd instructlab |
| 45 | + ``` |
| 46 | + > **NOTE:** The following steps in this document use [Python venv](https://docs.python.org/3/library/venv.html) for virtual environments. However, if you use another tool such as [pyenv](https://github.com/pyenv/pyenv) or [Miniforge](https://github.com/conda-forge/miniforge) for managing Python environments on your machine continue to use that tool instead. Otherwise, you may have issues with packages that are installed but not found in `venv`. |
| 47 | + |
| 48 | +3. Install and activate your `venv` environment by running the following command: |
| 49 | + |
| 50 | + ```bash |
| 51 | + python3 -m venv venv |
| 52 | + source venv/bin/activate |
| 53 | + pip install https://github.com/instructlab/instructlab.git@stable |
| 54 | + ``` |
| 55 | + > **NOTE**: ⏳ `pip install` may take some time, depending on your internet connection. |
| 56 | + |
| 57 | +4. From your `venv` environment, verify `ilab` is installed correctly, by running the `ilab` command. |
| 58 | + |
| 59 | + ```bash |
| 60 | + ilab |
| 61 | + ``` |
| 62 | + |
| 63 | + #### Example output: |
| 64 | + ``` |
| 65 | + (venv) $ ilab |
| 66 | + Usage: ilab [OPTIONS] COMMAND [ARGS]... |
| 67 | +
|
| 68 | + CLI for interacting with InstructLab. |
| 69 | +
|
| 70 | + If this is your first time running `ilab`, it's best to start with `ilab init` |
| 71 | + to create the environment |
| 72 | +
|
| 73 | + Options: |
| 74 | + --config PATH Path to a configuration file. [default: config.yaml] |
| 75 | + --help Show this message and exit. |
| 76 | +
|
| 77 | + Commands: |
| 78 | + chat Run a chat using the modified model |
| 79 | + check Check that taxonomy is valid |
| 80 | + convert Converts model to GGUF |
| 81 | + download Download the model(s) to train |
| 82 | + generate Generates synthetic data to enhance your example data |
| 83 | + init Initializes environment for InstructLab |
| 84 | + list Lists taxonomy files that have changed since a reference commit (default origin/main) |
| 85 | + serve Start a local server |
| 86 | + test Runs basic test to ensure model correctness |
| 87 | + train Takes synthetic data generated locally with `ilab generate`... |
| 88 | + ``` |
| 89 | +
|
| 90 | + > **IMPORTANT:** every `ilab` command needs to be run from within your Python virtual environment. To enter the Python environment, run the following command: |
| 91 | +
|
| 92 | + ```bash |
| 93 | + source venv/bin/activate |
| 94 | + ``` |
| 95 | +
|
| 96 | +### 🏗️ Initialize `ilab` |
| 97 | +
|
| 98 | +1. Initialize `ilab` by running the following command: |
| 99 | +
|
| 100 | + ```bash |
| 101 | + ilab init |
| 102 | + ``` |
| 103 | +
|
| 104 | +
|
| 105 | + #### Example output: |
| 106 | +
|
| 107 | + ```bash |
| 108 | + Welcome to InstructLab CLI. This guide will help you set up your environment. |
| 109 | + Please provide the following values to initiate the environment [press Enter for defaults]: |
| 110 | + Path to taxonomy repo [taxonomy]: <ENTER> |
| 111 | + ``` |
| 112 | +
|
| 113 | +2. When prompted by the interface, press **Enter** to add a new default `config.yaml` file. |
| 114 | +
|
| 115 | +3. When prompted, clone the `[email protected]:instructlab/taxonomy.git` repository into the current directory by typing **y**. |
| 116 | +
|
| 117 | + **Optional**: If you want to point to an existing local clone of the `taxonomy` repository, you can pass the path interactively or alternatively with the `--taxonomy-path` flag. |
| 118 | +
|
| 119 | + #### Example output: |
| 120 | +
|
| 121 | + ```bash |
| 122 | + (venv) $ ilab init |
| 123 | + Welcome to InstructLab CLI. This guide will help you set up your environment. |
| 124 | + Please provide the following values to initiate the environment [press Enter for defaults]: |
| 125 | + Path to taxonomy repo [taxonomy]: <ENTER> |
| 126 | + `taxonomy` seems to not exists or is empty. Should I clone [email protected]:instructlab/taxonomy.git for you? [y/N]: y |
| 127 | + Cloning [email protected]:instructlab/taxonomy.git... |
| 128 | + Generating `config.yaml` in the current directory... |
| 129 | + Initialization completed successfully, you're ready to start using `lab`. Enjoy! |
| 130 | + ``` |
| 131 | + `ilab` will use the default configuration file unless otherwise specified. You can override this behavior with the `--config` parameter for any `ilab` command. |
| 132 | + |
| 133 | +### 📥 Download the model |
| 134 | + |
| 135 | +* Run the `ilab download`command. |
| 136 | + |
| 137 | + ```bash |
| 138 | + ilab download |
| 139 | + ``` |
| 140 | + |
| 141 | + `ilab download` will download a pre-trained [model](https://huggingface.co/ibm/) (~4.4G) from HuggingFace and store it in a `models` directory: |
| 142 | + |
| 143 | + ```bash |
| 144 | + (venv) $ ilab download |
| 145 | + Downloading model from ibm/merlinite-7b-GGUF@main to models... |
| 146 | + (venv) $ ls models |
| 147 | + merlinite-7b-Q4_K_M.gguf |
| 148 | + ``` |
| 149 | + |
| 150 | + > **NOTE** ⏳ This command can take few minutes or immediately depending on your internet connection or model is cached. If you have issues connecting to Hugging Face, refer to the [Hugging Face discussion forum](https://discuss.huggingface.co/) for more details. |
| 151 | + |
| 152 | +### 🍴 Serving the model |
| 153 | + |
| 154 | +* Serve the model by running the following command: |
| 155 | + |
| 156 | + ```bash |
| 157 | + ilab serve |
| 158 | + ``` |
| 159 | + |
| 160 | + Once the model is served and ready, you'll see the following output: |
| 161 | +
|
| 162 | + ```bash |
| 163 | + (venv) $ ilab serve |
| 164 | + INFO 2024-03-02 02:21:11,352 lab.py:201 Using model 'models/ggml-merlinite-7b-0302-Q4_K_M.gguf' with -1 gpu-layers and 4096 max context size. |
| 165 | + Starting server process |
| 166 | + After application startup complete see http://127.0.0.1:8000/docs for API. |
| 167 | + Press CTRL+C to shut down the server. |
| 168 | + ``` |
| 169 | +
|
| 170 | + > **NOTE:** If multiple `ilab` clients try to connect to the same ilab server at the same time, the 1st will connect to the server while the others will start their own temporary server. This will require additional resources on the host machine. |
| 171 | +
|
| 172 | +### 📣 Chat with the model |
| 173 | +
|
| 174 | +Because you're serving the model in one terminal window, you will have to create a new window and re-activate your Python virtual environment to run `ilab chat` command: |
| 175 | + |
| 176 | + ```bash |
| 177 | + source venv/bin/activate |
| 178 | + ilab chat |
| 179 | + ``` |
| 180 | + |
| 181 | +### 🏋️ Training and interacting with the model |
| 182 | + |
| 183 | +Now that you have a working environment, you should see how we need to give it new knowledge. |
| 184 | + |
| 185 | +Ask it a question (the default downloaded model (from `ilab download` and `ilab chat`) gets this wrong, see https://github.com/instructlab/taxonomy/pull/659): |
| 186 | + |
| 187 | +> When was the first British women's softball league established? |
| 188 | +
|
| 189 | +The answer may be incorrect, so lets add knowledge that teaches the model the correct year (1953) |
| 190 | +
|
| 191 | +1. Verify you have the `taxonomy` directory in the working directory you are in. |
| 192 | +
|
| 193 | + ```bash |
| 194 | + ls -al taxonomy |
| 195 | + ``` |
| 196 | +
|
| 197 | +1. Create the directory for softball |
| 198 | +
|
| 199 | + ```bash |
| 200 | + mkdir -p taxonomy/knowledge/sports/overview/softball |
| 201 | + ``` |
| 202 | +
|
| 203 | +1. Pull down the example `qna.yaml` from the repository, and put it in `/tmp/` or the like: |
| 204 | +
|
| 205 | + ```bash |
| 206 | + wget -O /tmp/qna.yaml https://raw.githubusercontent.com/instructlab/taxonomy/62feaf54a2fbcd122f2dea419952090378ccb487/knowledge/sports/overview/softball/qna.yaml |
| 207 | + wget -O /tmp/attribution.txt https://raw.githubusercontent.com/instructlab/taxonomy/62feaf54a2fbcd122f2dea419952090378ccb487/knowledge/sports/overview/softball/attribution.txt |
| 208 | + head /tmp/qna.yaml |
| 209 | + head /tmp/attribution.txt |
| 210 | + ``` |
| 211 | +
|
| 212 | +1. Copy the file into the new directory: |
| 213 | +
|
| 214 | + ```bash |
| 215 | + cp /tmp/qna.yaml taxonomy/knowledge/sports/overview/softball/ |
| 216 | + cp /tmp/attribution.txt taxonomy/knowledge/sports/overview/softball/ |
| 217 | + ``` |
| 218 | +
|
| 219 | +1. Verify the 1953 is in the file: |
| 220 | +
|
| 221 | + ```bash |
| 222 | + grep -B1 -A3 1953 taxonomy/knowledge/sports/overview/softball/qna.yaml |
| 223 | + ``` |
| 224 | +
|
| 225 | +1. Verify that the `yaml` file is correctly formatted and `ilab` can see that it's been changed. |
| 226 | + |
| 227 | + ```bash |
| 228 | + ilab diff |
| 229 | + ``` |
| 230 | + |
| 231 | +1. Create some generated questions from the `qna.yaml` file, **Note**: Depending on the computer you are running this can take some time. ☕x(3 or 4) |
| 232 | + |
| 233 | + ```bash |
| 234 | + time ilab generate |
| 235 | + ``` |
| 236 | + |
| 237 | +1. Take a look at the generated questions, see what the model has come up with (TODO LINK) |
| 238 | + |
| 239 | +1. Now is the actual training time! |
| 240 | +**Note**: If you are running on a CPU run the following command. If you want to leverage your GPU, run the `--help` to configure it. Depending on the computer you are running this can take some time. ☕x(a lot) |
| 241 | + |
| 242 | + ```bash |
| 243 | + time ilab train |
| 244 | + # or |
| 245 | + ilab train --help |
| 246 | + ``` |
| 247 | + |
| 248 | +### Converting the trained model and serving it |
| 249 | + |
| 250 | +- Convert the model to the `gguf` so you can serve it with `ilab serve`: |
| 251 | + |
| 252 | +**Note**: this is only needed if you are on an M Mac, Linux you don't need this step. |
| 253 | +
|
| 254 | + ```bash |
| 255 | + time ilab convert |
| 256 | + ``` |
| 257 | +
|
| 258 | +- Serve your trained model! |
| 259 | +
|
| 260 | + ```bash |
| 261 | + # Kill your previous model, Ctrl-C or something the original window otherwise you'll won't be using your new model. |
| 262 | + ilab serve --model-path ibm-merlinite-7b-mlx-q-fused-pt/ggml-model-Q4_K_M.gguf |
| 263 | + ``` |
| 264 | +
|
| 265 | +- Start up another chat session with it: |
| 266 | +
|
| 267 | + ```bash |
| 268 | + ilab chat |
| 269 | + ``` |
| 270 | +- Ask the original questions again: |
| 271 | +
|
| 272 | +> When was the first British women's softball league established? |
| 273 | + |
| 274 | +The answer should be 1953! |
| 275 | + |
| 276 | +## Conclusion |
| 277 | + |
| 278 | +So you've successfully got `ilab` up and running. SUCCESS! Breathe in for a bit. We're proud of you, and I dare say you're an AI Engineer now. |
| 279 | +You're probably wondering what the next steps are, and frankly your guess is as good as mine but let me give you some suggestions. |
| 280 | + |
| 281 | +- Start playing with knowledge additions. This is to give something "new" to the model. You give it a chunk of data, something it doesn't know about and then train it on that. It's the same workflow as above with a few more steps. |
| 282 | +- Host your model someplace and ask it questions remotely. No reason to just run this on your laptop, set up a server and host it remotely, you can even use your iPhone! [Check this out](https://github.com/AugustDev/enchanted) |
| 283 | +- PRs accepted for other suggestions! |
| 284 | + |
| 285 | +### So do I need to do all of these steps every time? |
| 286 | + |
| 287 | +No, you don't. Lets talk about the actual workflow here. This was a "quick start guide" to get you going, but this isn't the actual workflow you'd |
| 288 | +use in real life. After getting `ilab` up and running the only thing you'll have to engage with is more or less these following commands: |
| 289 | + |
| 290 | +```bash |
| 291 | +# Create a new qna.yaml file and put it the correct place, like the /softball/ directory in the taxonomy tree |
| 292 | +ilab diff |
| 293 | +ilab generate |
| 294 | +ilab train |
| 295 | +ilab serve --model-path ibm-merlinite-7b-mlx-q-fused-pt/ggml-model-Q4_K_M.gguf |
| 296 | +ilab chat |
| 297 | +``` |
| 298 | + |
| 299 | +As you can see after setting it up, it's pretty straight forward and most of the time will be creating the new taxonomy content and waiting for |
| 300 | +the `ilab train` to finish. |
| 301 | +
|
| 302 | +Again, we're so happy you made it this far, and remember if you have questions we are here to help, and are excited to see what you come up with! |
0 commit comments