sahilsuneja
commited on
Commit
•
6f14bfd
1
Parent(s):
bf38850
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,123 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
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-34b-code-instruct](https://huggingface.co/ibm-granite/granite-34b-code-instruct) 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 |
+
### Use in IBM Production TGIS
|
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.ddc56ee
|
47 |
+
|
48 |
+
docker pull $TGIS_IMAGE
|
49 |
+
|
50 |
+
# optionally download granite-34b-code-instruct 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 |
+
ibm-granite/granite-34b-code-instruct \
|
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/granite-34b-code-instruct-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 directory 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=ibm-granite/granite-34b-code-instruct \
|
78 |
+
-e SPECULATOR_NAME=ibm-granite/granite-34b-code-instruct-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 |
+
### Use in Huggingface TGI
|
105 |
+
|
106 |
+
#### start the server
|
107 |
+
|
108 |
+
```bash
|
109 |
+
model=ibm-granite/granite-34b-code-instruct-accelerator
|
110 |
+
volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run
|
111 |
+
docker run --gpus all --shm-size 1g -p 8080:80 -v $volume:/data ghcr.io/huggingface/text-generation-inference:latest --model-id $model
|
112 |
+
```
|
113 |
+
|
114 |
+
_note: for tensor parallel, add --num-shard_
|
115 |
+
|
116 |
+
#### make a request
|
117 |
+
|
118 |
+
```bash
|
119 |
+
curl 127.0.0.1:8080/generate_stream \
|
120 |
+
-X POST \
|
121 |
+
-d '{"inputs":"Write a bubble sort in python","parameters":{"max_new_tokens":100}}' \
|
122 |
+
-H 'Content-Type: application/json'
|
123 |
+
```
|