sahilsuneja
commited on
Commit
•
3f4497e
1
Parent(s):
b3c9ab2
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,124 @@
|
|
1 |
-
---
|
2 |
-
license: llama2
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: llama2
|
3 |
+
---
|
4 |
+
|
5 |
+
|
6 |
+
## Installation from source
|
7 |
+
|
8 |
+
```bash
|
9 |
+
git clone https://github.com/foundation-model-stack/fms-extras
|
10 |
+
cd fms-extras
|
11 |
+
pip install -e .
|
12 |
+
```
|
13 |
+
|
14 |
+
|
15 |
+
## Description
|
16 |
+
|
17 |
+
This model is intended to be used as an accelerator for [llama 34B (code)](https://huggingface.co/codellama/CodeLlama-34b-Instruct-hf) and takes inspiration
|
18 |
+
from the Medusa speculative decoding architecture. This accelerator modifies the MLP into a multi-stage MLP, where each stage predicts
|
19 |
+
a single token in the draft based on both a state vector and sampled token
|
20 |
+
from the prior stage (the base model can be considered stage 0).
|
21 |
+
The state vector from the base model provides contextual information to the accelerator,
|
22 |
+
while conditioning on prior sampled tokens allows it to produce higher-quality draft n-grams.
|
23 |
+
|
24 |
+
Note: The underlying MLP speculator is a generic architecture that can be trained with any generative model to accelerate inference.
|
25 |
+
Training is light-weight and can be completed in only a few days depending on base model size and speed.
|
26 |
+
|
27 |
+
## Repository Links
|
28 |
+
|
29 |
+
1. [Paged Attention KV-Cache / Speculator](https://github.com/foundation-model-stack/fms-extras)
|
30 |
+
2. [Production Server with speculative decoding](https://github.com/IBM/text-generation-inference.git)
|
31 |
+
3. [Speculator training](https://github.com/foundation-model-stack/fms-fsdp/pull/35)
|
32 |
+
|
33 |
+
## Samples
|
34 |
+
|
35 |
+
_Note: For all samples, your environment must have access to cuda_
|
36 |
+
|
37 |
+
### Use in IBM Production TGIS
|
38 |
+
|
39 |
+
*To try this out running in a production-like environment, please use the pre-built docker image:*
|
40 |
+
|
41 |
+
#### Setup
|
42 |
+
|
43 |
+
```bash
|
44 |
+
HF_HUB_CACHE=/hf_hub_cache
|
45 |
+
chmod a+w $HF_HUB_CACHE
|
46 |
+
HF_HUB_TOKEN="your huggingface hub token"
|
47 |
+
TGIS_IMAGE=quay.io/wxpe/text-gen-server:main.ddc56ee
|
48 |
+
|
49 |
+
docker pull $TGIS_IMAGE
|
50 |
+
|
51 |
+
# optionally download CodeLlama-34b-Instruct-hf if the weights do not already exist
|
52 |
+
docker run --rm \
|
53 |
+
-v $HF_HUB_CACHE:/models \
|
54 |
+
-e HF_HUB_CACHE=/models \
|
55 |
+
-e TRANSFORMERS_CACHE=/models \
|
56 |
+
$TGIS_IMAGE \
|
57 |
+
text-generation-server download-weights \
|
58 |
+
codellama/CodeLlama-13b-Instruct-hf \
|
59 |
+
--token $HF_HUB_TOKEN
|
60 |
+
|
61 |
+
# optionally download the speculator model if the weights do not already exist
|
62 |
+
docker run --rm \
|
63 |
+
-v $HF_HUB_CACHE:/models \
|
64 |
+
-e HF_HUB_CACHE=/models \
|
65 |
+
-e TRANSFORMERS_CACHE=/models \
|
66 |
+
$TGIS_IMAGE \
|
67 |
+
text-generation-server download-weights \
|
68 |
+
ibm-fms/codellama-34b-accelerator \
|
69 |
+
--token $HF_HUB_TOKEN
|
70 |
+
|
71 |
+
# 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>
|
72 |
+
docker run -d --rm --gpus all \
|
73 |
+
--name my-tgis-server \
|
74 |
+
-p 8033:8033 \
|
75 |
+
-v $HF_HUB_CACHE:/models \
|
76 |
+
-e HF_HUB_CACHE=/models \
|
77 |
+
-e TRANSFORMERS_CACHE=/models \
|
78 |
+
-e MODEL_NAME=codellama/CodeLlama-13b-Instruct-hf \
|
79 |
+
-e SPECULATOR_NAME=ibm-fms/codellama-34b-accelerator \
|
80 |
+
-e FLASH_ATTENTION=true \
|
81 |
+
-e PAGED_ATTENTION=true \
|
82 |
+
-e DTYPE=float16 \
|
83 |
+
$TGIS_IMAGE
|
84 |
+
|
85 |
+
# check logs and wait for "gRPC server started on port 8033" and "HTTP server started on port 3000"
|
86 |
+
docker logs my-tgis-server -f
|
87 |
+
|
88 |
+
# get the client sample (Note: The first prompt will take longer as there is a warmup time)
|
89 |
+
conda create -n tgis-client-env python=3.11
|
90 |
+
conda activate tgis-client-env
|
91 |
+
git clone --branch main --single-branch https://github.com/IBM/text-generation-inference.git
|
92 |
+
cd text-generation-inference/integration_tests
|
93 |
+
make gen-client
|
94 |
+
pip install . --no-cache-dir
|
95 |
+
```
|
96 |
+
|
97 |
+
#### Run Sample
|
98 |
+
|
99 |
+
```bash
|
100 |
+
python sample_client.py
|
101 |
+
```
|
102 |
+
|
103 |
+
_Note: first prompt may be slower as there is a slight warmup time_
|
104 |
+
|
105 |
+
### Use in Huggingface TGI
|
106 |
+
|
107 |
+
#### start the server
|
108 |
+
|
109 |
+
```bash
|
110 |
+
model=ibm-fms/codellama-34b-accelerator
|
111 |
+
volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run
|
112 |
+
docker run --gpus all --shm-size 1g -p 8080:80 -v $volume:/data ghcr.io/huggingface/text-generation-inference:latest --model-id $model
|
113 |
+
```
|
114 |
+
|
115 |
+
_note: for tensor parallel, add --num-shard_
|
116 |
+
|
117 |
+
#### make a request
|
118 |
+
|
119 |
+
```bash
|
120 |
+
curl 127.0.0.1:8080/generate_stream \
|
121 |
+
-X POST \
|
122 |
+
-d '{"inputs":"Write a bubble sort in python","parameters":{"max_new_tokens":100}}' \
|
123 |
+
-H 'Content-Type: application/json'
|
124 |
+
```
|