sahilsuneja commited on
Commit
aa19f45
1 Parent(s): 6b0f3c2

Update README.md

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