File size: 15,537 Bytes
8cf2f51
 
24579e8
 
 
 
 
 
 
 
 
8cf2f51
 
 
 
 
 
 
70b93f5
8cf2f51
5a151e8
 
8cf2f51
 
 
 
70b93f5
8cf2f51
 
 
 
4c6424c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8cf2f51
 
 
 
 
 
 
 
 
 
 
 
 
 
5a151e8
8cf2f51
5a151e8
 
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
5a151e8
8cf2f51
 
 
 
 
 
 
 
 
 
 
 
 
70b93f5
 
 
8cf2f51
 
 
 
70b93f5
 
 
 
8cf2f51
 
 
 
 
 
70b93f5
8cf2f51
 
 
 
 
70b93f5
8cf2f51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70b93f5
8cf2f51
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# Introduction\n",
    "The purpose of this notebook is to give you some tips on TGI and to get it running in this notebook."
   ],
   "id": "2572084a0dd24246"
  },
  {
   "cell_type": "markdown",
   "id": "fe3c1d07-73d2-4906-97c4-2877f42a5fd7",
   "metadata": {},
   "source": [
    "Here we can see the different settings for TGI. Be sure to read through them and decide which settings are most important for your use-case.\n",
    "\n",
    "Here are some of the most important ones:\n",
    "- `--model-id`\n",
    "- `--quantize` Quantization saves memory, but does not always improve speed\n",
    "- `--max-input-tokens` \n",
    "- `--max-total-tokens` \n",
    "- `--max-batch-size` \n",
    "- `--max-batch-total-tokens`\n",
    "\n",
    "These are changed because we are on spaces, and dont want to conflict with the spaces server:\n",
    "- `--hostname`\n",
    "- `--port`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1db2b5d1-337c-4b17-95f9-431cd3e631f2",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "text-generation-launcher 2.0.2\n"
     ]
    }
   ],
   "source": [
    "!text-generation-launcher --version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8be5895f-a548-488e-8e5c-dc9ba429a960",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Text Generation Launcher\n",
      "\n",
      "\u001B[1m\u001B[4mUsage:\u001B[0m \u001B[1mtext-generation-launcher\u001B[0m [OPTIONS]\n",
      "\n",
      "\u001B[1m\u001B[4mOptions:\u001B[0m\n",
      "      \u001B[1m--model-id\u001B[0m <MODEL_ID>\n",
      "          The name of the model to load. Can be a MODEL_ID as listed on <https://hf.co/models> like `gpt2` or `OpenAssistant/oasst-sft-1-pythia-12b`. Or it can be a local directory containing the necessary files as saved by `save_pretrained(...)` methods of transformers [env: MODEL_ID=] [default: bigscience/bloom-560m]\n",
      "      \u001B[1m--revision\u001B[0m <REVISION>\n",
      "          The actual revision of the model if you're referring to a model on the hub. You can use a specific commit id or a branch like `refs/pr/2` [env: REVISION=]\n",
      "      \u001B[1m--validation-workers\u001B[0m <VALIDATION_WORKERS>\n",
      "          The number of tokenizer workers used for payload validation and truncation inside the router [env: VALIDATION_WORKERS=] [default: 2]\n",
      "      \u001B[1m--sharded\u001B[0m <SHARDED>\n",
      "          Whether to shard the model across multiple GPUs By default text-generation-inference will use all available GPUs to run the model. Setting it to `false` deactivates `num_shard` [env: SHARDED=] [possible values: true, false]\n",
      "      \u001B[1m--num-shard\u001B[0m <NUM_SHARD>\n",
      "          The number of shards to use if you don't want to use all GPUs on a given machine. You can use `CUDA_VISIBLE_DEVICES=0,1 text-generation-launcher... --num_shard 2` and `CUDA_VISIBLE_DEVICES=2,3 text-generation-launcher... --num_shard 2` to launch 2 copies with 2 shard each on a given machine with 4 GPUs for instance [env: NUM_SHARD=]\n",
      "      \u001B[1m--quantize\u001B[0m <QUANTIZE>\n",
      "          Whether you want the model to be quantized [env: QUANTIZE=] [possible values: awq, eetq, gptq, bitsandbytes, bitsandbytes-nf4, bitsandbytes-fp4, fp8]\n",
      "      \u001B[1m--speculate\u001B[0m <SPECULATE>\n",
      "          The number of input_ids to speculate on If using a medusa model, the heads will be picked up automatically Other wise, it will use n-gram speculation which is relatively free in terms of compute, but the speedup heavily depends on the task [env: SPECULATE=]\n",
      "      \u001B[1m--dtype\u001B[0m <DTYPE>\n",
      "          The dtype to be forced upon the model. This option cannot be used with `--quantize` [env: DTYPE=] [possible values: float16, bfloat16]\n",
      "      \u001B[1m--trust-remote-code\u001B[0m\n",
      "          Whether you want to execute hub modelling code. Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision [env: TRUST_REMOTE_CODE=]\n",
      "      \u001B[1m--max-concurrent-requests\u001B[0m <MAX_CONCURRENT_REQUESTS>\n",
      "          The maximum amount of concurrent requests for this particular deployment. Having a low limit will refuse clients requests instead of having them wait for too long and is usually good to handle backpressure correctly [env: MAX_CONCURRENT_REQUESTS=] [default: 128]\n",
      "      \u001B[1m--max-best-of\u001B[0m <MAX_BEST_OF>\n",
      "          This is the maximum allowed value for clients to set `best_of`. Best of makes `n` generations at the same time, and return the best in terms of overall log probability over the entire generated sequence [env: MAX_BEST_OF=] [default: 2]\n",
      "      \u001B[1m--max-stop-sequences\u001B[0m <MAX_STOP_SEQUENCES>\n",
      "          This is the maximum allowed value for clients to set `stop_sequences`. Stop sequences are used to allow the model to stop on more than just the EOS token, and enable more complex \"prompting\" where users can preprompt the model in a specific way and define their \"own\" stop token aligned with their prompt [env: MAX_STOP_SEQUENCES=] [default: 4]\n",
      "      \u001B[1m--max-top-n-tokens\u001B[0m <MAX_TOP_N_TOKENS>\n",
      "          This is the maximum allowed value for clients to set `top_n_tokens`. `top_n_tokens is used to return information about the the `n` most likely tokens at each generation step, instead of just the sampled token. This information can be used for downstream tasks like for classification or ranking [env: MAX_TOP_N_TOKENS=] [default: 5]\n",
      "      \u001B[1m--max-input-tokens\u001B[0m <MAX_INPUT_TOKENS>\n",
      "          This is the maximum allowed input length (expressed in number of tokens) for users. The larger this value, the longer prompt users can send which can impact the overall memory required to handle the load. Please note that some models have a finite range of sequence they can handle. Default to min(max_position_embeddings - 1, 4095) [env: MAX_INPUT_TOKENS=]\n",
      "      \u001B[1m--max-input-length\u001B[0m <MAX_INPUT_LENGTH>\n",
      "          Legacy version of [`Args::max_input_tokens`] [env: MAX_INPUT_LENGTH=]\n",
      "      \u001B[1m--max-total-tokens\u001B[0m <MAX_TOTAL_TOKENS>\n",
      "          This is the most important value to set as it defines the \"memory budget\" of running clients requests. Clients will send input sequences and ask to generate `max_new_tokens` on top. with a value of `1512` users can send either a prompt of `1000` and ask for `512` new tokens, or send a prompt of `1` and ask for `1511` max_new_tokens. The larger this value, the larger amount each request will be in your RAM and the less effective batching can be. Default to min(max_position_embeddings, 4096) [env: MAX_TOTAL_TOKENS=]\n",
      "      \u001B[1m--waiting-served-ratio\u001B[0m <WAITING_SERVED_RATIO>\n",
      "          This represents the ratio of waiting queries vs running queries where you want to start considering pausing the running queries to include the waiting ones into the same batch. `waiting_served_ratio=1.2` Means when 12 queries are waiting and there's only 10 queries left in the current batch we check if we can fit those 12 waiting queries into the batching strategy, and if yes, then batching happens delaying the 10 running queries by a `prefill` run [env: WAITING_SERVED_RATIO=] [default: 1.2]\n",
      "      \u001B[1m--max-batch-prefill-tokens\u001B[0m <MAX_BATCH_PREFILL_TOKENS>\n",
      "          Limits the number of tokens for the prefill operation. Since this operation take the most memory and is compute bound, it is interesting to limit the number of requests that can be sent. Default to `max_input_tokens + 50` to give a bit of room [env: MAX_BATCH_PREFILL_TOKENS=]\n",
      "      \u001B[1m--max-batch-total-tokens\u001B[0m <MAX_BATCH_TOTAL_TOKENS>\n",
      "          **IMPORTANT** This is one critical control to allow maximum usage of the available hardware [env: MAX_BATCH_TOTAL_TOKENS=]\n",
      "      \u001B[1m--max-waiting-tokens\u001B[0m <MAX_WAITING_TOKENS>\n",
      "          This setting defines how many tokens can be passed before forcing the waiting queries to be put on the batch (if the size of the batch allows for it). New queries require 1 `prefill` forward, which is different from `decode` and therefore you need to pause the running batch in order to run `prefill` to create the correct values for the waiting queries to be able to join the batch [env: MAX_WAITING_TOKENS=] [default: 20]\n",
      "      \u001B[1m--max-batch-size\u001B[0m <MAX_BATCH_SIZE>\n",
      "          Enforce a maximum number of requests per batch Specific flag for hardware targets that do not support unpadded inference [env: MAX_BATCH_SIZE=]\n",
      "      \u001B[1m--cuda-graphs\u001B[0m <CUDA_GRAPHS>\n",
      "          Specify the batch sizes to compute cuda graphs for. Use \"0\" to disable. Default = \"1,2,4,8,16,32\" [env: CUDA_GRAPHS=]\n",
      "      \u001B[1m--hostname\u001B[0m <HOSTNAME>\n",
      "          The IP address to listen on [env: HOSTNAME=r-derek-thomas-tgi-benchmark-space-kiwh48a6-ee7f8-q0926] [default: 0.0.0.0]\n",
      "  \u001B[1m-p\u001B[0m, \u001B[1m--port\u001B[0m <PORT>\n",
      "          The port to listen on [env: PORT=80] [default: 3000]\n",
      "      \u001B[1m--shard-uds-path\u001B[0m <SHARD_UDS_PATH>\n",
      "          The name of the socket for gRPC communication between the webserver and the shards [env: SHARD_UDS_PATH=] [default: /tmp/text-generation-server]\n",
      "      \u001B[1m--master-addr\u001B[0m <MASTER_ADDR>\n",
      "          The address the master shard will listen on. (setting used by torch distributed) [env: MASTER_ADDR=] [default: localhost]\n",
      "      \u001B[1m--master-port\u001B[0m <MASTER_PORT>\n",
      "          The address the master port will listen on. (setting used by torch distributed) [env: MASTER_PORT=] [default: 29500]\n",
      "      \u001B[1m--huggingface-hub-cache\u001B[0m <HUGGINGFACE_HUB_CACHE>\n",
      "          The location of the huggingface hub cache. Used to override the location if you want to provide a mounted disk for instance [env: HUGGINGFACE_HUB_CACHE=/data]\n",
      "      \u001B[1m--weights-cache-override\u001B[0m <WEIGHTS_CACHE_OVERRIDE>\n",
      "          The location of the huggingface hub cache. Used to override the location if you want to provide a mounted disk for instance [env: WEIGHTS_CACHE_OVERRIDE=]\n",
      "      \u001B[1m--disable-custom-kernels\u001B[0m\n",
      "          For some models (like bloom), text-generation-inference implemented custom cuda kernels to speed up inference. Those kernels were only tested on A100. Use this flag to disable them if you're running on different hardware and encounter issues [env: DISABLE_CUSTOM_KERNELS=]\n",
      "      \u001B[1m--cuda-memory-fraction\u001B[0m <CUDA_MEMORY_FRACTION>\n",
      "          Limit the CUDA available memory. The allowed value equals the total visible memory multiplied by cuda-memory-fraction [env: CUDA_MEMORY_FRACTION=] [default: 1.0]\n",
      "      \u001B[1m--rope-scaling\u001B[0m <ROPE_SCALING>\n",
      "          Rope scaling will only be used for RoPE models and allow rescaling the position rotary to accomodate for larger prompts [env: ROPE_SCALING=] [possible values: linear, dynamic]\n",
      "      \u001B[1m--rope-factor\u001B[0m <ROPE_FACTOR>\n",
      "          Rope scaling will only be used for RoPE models See `rope_scaling` [env: ROPE_FACTOR=]\n",
      "      \u001B[1m--json-output\u001B[0m\n",
      "          Outputs the logs in JSON format (useful for telemetry) [env: JSON_OUTPUT=]\n",
      "      \u001B[1m--otlp-endpoint\u001B[0m <OTLP_ENDPOINT>\n",
      "          [env: OTLP_ENDPOINT=]\n",
      "      \u001B[1m--cors-allow-origin\u001B[0m <CORS_ALLOW_ORIGIN>\n",
      "          [env: CORS_ALLOW_ORIGIN=]\n",
      "      \u001B[1m--watermark-gamma\u001B[0m <WATERMARK_GAMMA>\n",
      "          [env: WATERMARK_GAMMA=]\n",
      "      \u001B[1m--watermark-delta\u001B[0m <WATERMARK_DELTA>\n",
      "          [env: WATERMARK_DELTA=]\n",
      "      \u001B[1m--ngrok\u001B[0m\n",
      "          Enable ngrok tunneling [env: NGROK=]\n",
      "      \u001B[1m--ngrok-authtoken\u001B[0m <NGROK_AUTHTOKEN>\n",
      "          ngrok authentication token [env: NGROK_AUTHTOKEN=]\n",
      "      \u001B[1m--ngrok-edge\u001B[0m <NGROK_EDGE>\n",
      "          ngrok edge [env: NGROK_EDGE=]\n",
      "      \u001B[1m--tokenizer-config-path\u001B[0m <TOKENIZER_CONFIG_PATH>\n",
      "          The path to the tokenizer config file. This path is used to load the tokenizer configuration which may include a `chat_template`. If not provided, the default config will be used from the model hub [env: TOKENIZER_CONFIG_PATH=]\n",
      "      \u001B[1m--disable-grammar-support\u001B[0m\n",
      "          Disable outlines grammar constrained generation. This is a feature that allows you to generate text that follows a specific grammar [env: DISABLE_GRAMMAR_SUPPORT=]\n",
      "  \u001B[1m-e\u001B[0m, \u001B[1m--env\u001B[0m\n",
      "          Display a lot of information about your runtime environment\n",
      "      \u001B[1m--max-client-batch-size\u001B[0m <MAX_CLIENT_BATCH_SIZE>\n",
      "          Control the maximum number of inputs that a client can send in a single request [env: MAX_CLIENT_BATCH_SIZE=] [default: 4]\n",
      "  \u001B[1m-h\u001B[0m, \u001B[1m--help\u001B[0m\n",
      "          Print help (see more with '--help')\n",
      "  \u001B[1m-V\u001B[0m, \u001B[1m--version\u001B[0m\n",
      "          Print version\n"
     ]
    }
   ],
   "source": [
    "!text-generation-launcher -h"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "598435df-0cdb-411b-96c2-3930fc222f8e",
   "metadata": {},
   "source": [
    "We can launch directly from the notebook since we dont need the command to be interactive.\n",
    "\n",
    "We will just be using defaults in this notebook as the intent is to understand the benchmark tool."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de3b9694-d417-4d17-a28e-e481703344ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "!RUST_BACKTRACE=1 \\\n",
    "text-generation-launcher \\\n",
    "--model-id astronomer/Llama-3-8B-Instruct-GPTQ-8-Bit \\\n",
    "--quantize gptq \\\n",
    "--hostname 0.0.0.0 \\\n",
    "--port 1337 # We need to change it from the default to play well with spaces \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9de093ba-b39a-4881-ab09-106de58dcd16",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}