JRosenkranz
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,165 @@
|
|
1 |
---
|
2 |
license: llama2
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: llama2
|
3 |
---
|
4 |
+
|
5 |
+
## Installation from source
|
6 |
+
|
7 |
+
```bash
|
8 |
+
git clone https://github.com/foundation-model-stack/fms-extras
|
9 |
+
cd fms-extras
|
10 |
+
pip install -e .
|
11 |
+
```
|
12 |
+
|
13 |
+
|
14 |
+
## Description
|
15 |
+
|
16 |
+
This model is intended to be used as an accelerator for [granite 7B (instruct lab)](https://huggingface.co/instructlab/granite-7b-lab) and takes inspiration
|
17 |
+
from the Medusa speculative decoding architecture. This accelerator modifies the MLP into a multi-stage MLP, where each stage predicts
|
18 |
+
a single token in the draft based on both a state vector and sampled token
|
19 |
+
from the prior stage (the base model can be considered stage 0).
|
20 |
+
The state vector from the base model provides contextual information to the accelerator,
|
21 |
+
while conditioning on prior sampled tokens allows it to produce higher-quality draft n-grams.
|
22 |
+
|
23 |
+
Note: The underlying MLP speculator is a generic architecture that can be trained with any generative model to accelerate inference.
|
24 |
+
Training is light-weight and can be completed in only a few days depending on base model size and speed.
|
25 |
+
|
26 |
+
## Repository Links
|
27 |
+
|
28 |
+
1. [Paged Attention KV-Cache / Speculator](https://github.com/foundation-model-stack/fms-extras)
|
29 |
+
2. [Production Server with speculative decoding](https://github.com/IBM/text-generation-inference.git)
|
30 |
+
3. [Speculator training](https://github.com/foundation-model-stack/fms-fsdp/pull/35)
|
31 |
+
|
32 |
+
## Samples
|
33 |
+
|
34 |
+
_Note: For all samples, your environment must have access to cuda_
|
35 |
+
|
36 |
+
### Production Server Sample
|
37 |
+
|
38 |
+
*To try this out running in a production-like environment, please use the pre-built docker image:*
|
39 |
+
|
40 |
+
#### Setup
|
41 |
+
|
42 |
+
```bash
|
43 |
+
HF_HUB_CACHE=/hf_hub_cache
|
44 |
+
chmod a+w $HF_HUB_CACHE
|
45 |
+
HF_HUB_TOKEN="your huggingface hub token"
|
46 |
+
TGIS_IMAGE=quay.io/wxpe/text-gen-server:main.ee927a4
|
47 |
+
|
48 |
+
docker pull $TGIS_IMAGE
|
49 |
+
|
50 |
+
# optionally download granite-7b-lab if the weights do not already exist
|
51 |
+
docker run --rm \
|
52 |
+
-v $HF_HUB_CACHE:/models \
|
53 |
+
-e HF_HUB_CACHE=/models \
|
54 |
+
-e TRANSFORMERS_CACHE=/models \
|
55 |
+
$TGIS_IMAGE \
|
56 |
+
text-generation-server download-weights \
|
57 |
+
instructlab/granite-7b-lab \
|
58 |
+
--token $HF_HUB_TOKEN
|
59 |
+
|
60 |
+
# optionally download the speculator model if the weights do not already exist
|
61 |
+
docker run --rm \
|
62 |
+
-v $HF_HUB_CACHE:/models \
|
63 |
+
-e HF_HUB_CACHE=/models \
|
64 |
+
-e TRANSFORMERS_CACHE=/models \
|
65 |
+
$TGIS_IMAGE \
|
66 |
+
text-generation-server download-weights \
|
67 |
+
ibm/granite-7b-lab-accelerator \
|
68 |
+
--token $HF_HUB_TOKEN
|
69 |
+
|
70 |
+
# note: if the weights were downloaded separately (not with the above commands), please place them in the HF_HUB_CACHE directoy and refer to them with /models/<model_name>
|
71 |
+
docker run -d --rm --gpus all \
|
72 |
+
--name my-tgis-server \
|
73 |
+
-p 8033:8033 \
|
74 |
+
-v $HF_HUB_CACHE:/models \
|
75 |
+
-e HF_HUB_CACHE=/models \
|
76 |
+
-e TRANSFORMERS_CACHE=/models \
|
77 |
+
-e MODEL_NAME=instructlab/granite-7b-lab \
|
78 |
+
-e SPECULATOR_NAME=ibm/granite-7b-lab-accelerator \
|
79 |
+
-e FLASH_ATTENTION=true \
|
80 |
+
-e PAGED_ATTENTION=true \
|
81 |
+
-e DTYPE=float16 \
|
82 |
+
$TGIS_IMAGE
|
83 |
+
|
84 |
+
# check logs and wait for "gRPC server started on port 8033" and "HTTP server started on port 3000"
|
85 |
+
docker logs my-tgis-server -f
|
86 |
+
|
87 |
+
# get the client sample (Note: The first prompt will take longer as there is a warmup time)
|
88 |
+
conda create -n tgis-client-env python=3.11
|
89 |
+
conda activate tgis-client-env
|
90 |
+
git clone --branch main --single-branch https://github.com/IBM/text-generation-inference.git
|
91 |
+
cd text-generation-inference/integration_tests
|
92 |
+
make gen-client
|
93 |
+
pip install . --no-cache-dir
|
94 |
+
```
|
95 |
+
|
96 |
+
#### Run Sample
|
97 |
+
|
98 |
+
```bash
|
99 |
+
python sample_client.py
|
100 |
+
```
|
101 |
+
|
102 |
+
_Note: first prompt may be slower as there is a slight warmup time_
|
103 |
+
|
104 |
+
### Minimal Sample
|
105 |
+
|
106 |
+
*To try this out with the fms-native compiled model, please execute the following:*
|
107 |
+
|
108 |
+
#### Install
|
109 |
+
|
110 |
+
```bash
|
111 |
+
git clone --branch ibm_7b_instruct_lab_variant --single-branch https://github.com/JRosenkranz/fms-extras.git
|
112 |
+
(cd fms-extras && pip install -e .)
|
113 |
+
pip install transformers==4.35.0 sentencepiece numpy
|
114 |
+
```
|
115 |
+
|
116 |
+
#### Run Sample
|
117 |
+
|
118 |
+
##### batch_size=1 (compile + cudagraphs)
|
119 |
+
|
120 |
+
```bash
|
121 |
+
MODEL_PATH=/path/to/instructlab/granite-7b-lab
|
122 |
+
python fms-extras/scripts/paged_speculative_inference.py \
|
123 |
+
--variant=ibm.7b_instruct_lab \
|
124 |
+
--model_path=$MODEL_PATH \
|
125 |
+
--model_source=hf \
|
126 |
+
--tokenizer=$MODEL_PATH \
|
127 |
+
--speculator_path=ibm/granite-7b-lab-accelerator \
|
128 |
+
--speculator_source=hf \
|
129 |
+
--top_k_tokens_per_head=4,3,2,2,2 \
|
130 |
+
--compile \
|
131 |
+
--compile_mode=reduce-overhead
|
132 |
+
```
|
133 |
+
|
134 |
+
##### batch_size=1 (compile)
|
135 |
+
|
136 |
+
```bash
|
137 |
+
MODEL_PATH=/path/to/instructlab/granite-7b-lab
|
138 |
+
python fms-extras/scripts/paged_speculative_inference.py \
|
139 |
+
--variant=ibm.7b_instruct_lab \
|
140 |
+
--model_path=$MODEL_PATH \
|
141 |
+
--model_source=hf \
|
142 |
+
--tokenizer=$MODEL_PATH \
|
143 |
+
--speculator_path=ibm/granite-7b-lab-accelerator \
|
144 |
+
--speculator_source=hf \
|
145 |
+
--top_k_tokens_per_head=4,3,2,2,2 \
|
146 |
+
--compile \
|
147 |
+
```
|
148 |
+
|
149 |
+
##### batch_size=4 (compile)
|
150 |
+
|
151 |
+
```bash
|
152 |
+
MODEL_PATH=/path/to/instructlab/granite-7b-lab
|
153 |
+
python fms-extras/scripts/paged_speculative_inference.py \
|
154 |
+
--variant=ibm.7b_instruct_lab \
|
155 |
+
--model_path=$MODEL_PATH \
|
156 |
+
--model_source=hf \
|
157 |
+
--tokenizer=$MODEL_PATH \
|
158 |
+
--speculator_path=ibm/granite-7b-lab-accelerator \
|
159 |
+
--speculator_source=hf \
|
160 |
+
--top_k_tokens_per_head=4,3,2,2,2 \
|
161 |
+
--batch_input \
|
162 |
+
--compile \
|
163 |
+
```
|
164 |
+
|
165 |
+
Sample code can be found [here](https://github.com/foundation-model-stack/fms-extras/blob/main/scripts/paged_speculative_inference.py)
|