derek-thomas HF staff commited on
Commit
dfa19c2
1 Parent(s): 5a151e8

Removing old notebooks

Browse files
Files changed (2) hide show
  1. TGI-benchmark.ipynb +0 -135
  2. TGI-launcher.ipynb +0 -285
TGI-benchmark.ipynb DELETED
@@ -1,135 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "id": "28e3460d-59b1-4d4c-b62e-510987fb2f28",
6
- "metadata": {},
7
- "source": [
8
- "# Introduction\n",
9
- "This notebook is to show how to launch the TGI Benchmark tool. \n",
10
- "\n",
11
- "## Warning\n",
12
- "Please note that the TGI Benchmark tool is designed to work in a terminal, not a jupyter notebook. This means you will need to copy/paste the command in a jupyter terminal tab. I am putting them here for convenience."
13
- ]
14
- },
15
- {
16
- "cell_type": "markdown",
17
- "id": "c0de3cc9-c6cd-45b3-9dd0-84b3cb2fc8b2",
18
- "metadata": {},
19
- "source": [
20
- "Here we can see the different settings for TGI Benchmark. \n",
21
- "\n",
22
- "Here are some of the most important ones:\n",
23
- "\n",
24
- "- `--tokenizer-name` This is required so the tool knows what tokenizer to use\n",
25
- "- `--batch-size` This is important for load testing. We should use more and more values to see what happens to throughput and latency\n",
26
- "- `--sequence-length` AKA input tokens, it is important to match your use-case needs\n",
27
- "- `--decode-length` AKA output tokens, it is important to match your use-case needs\n",
28
- "- `--runs` Use fewer when you are exploring, but the default 10 is good for your final estimate"
29
- ]
30
- },
31
- {
32
- "cell_type": "code",
33
- "execution_count": 1,
34
- "id": "694df6d6-a521-4dab-977b-2828d4250781",
35
- "metadata": {
36
- "tags": []
37
- },
38
- "outputs": [
39
- {
40
- "name": "stdout",
41
- "output_type": "stream",
42
- "text": [
43
- "Text Generation Benchmarking tool\n",
44
- "\n",
45
- "\u001b[1m\u001b[4mUsage:\u001b[0m \u001b[1mtext-generation-benchmark\u001b[0m [OPTIONS] \u001b[1m--tokenizer-name\u001b[0m <TOKENIZER_NAME>\n",
46
- "\n",
47
- "\u001b[1m\u001b[4mOptions:\u001b[0m\n",
48
- " \u001b[1m-t\u001b[0m, \u001b[1m--tokenizer-name\u001b[0m <TOKENIZER_NAME>\n",
49
- " The name of the tokenizer (as in model_id on the huggingface hub, or local path) [env: TOKENIZER_NAME=]\n",
50
- " \u001b[1m--revision\u001b[0m <REVISION>\n",
51
- " The revision to use for the tokenizer if on the hub [env: REVISION=] [default: main]\n",
52
- " \u001b[1m-b\u001b[0m, \u001b[1m--batch-size\u001b[0m <BATCH_SIZE>\n",
53
- " The various batch sizes to benchmark for, the idea is to get enough batching to start seeing increased latency, this usually means you're moving from memory bound (usual as BS=1) to compute bound, and this is a sweet spot for the maximum batch size for the model under test\n",
54
- " \u001b[1m-s\u001b[0m, \u001b[1m--sequence-length\u001b[0m <SEQUENCE_LENGTH>\n",
55
- " This is the initial prompt sent to the text-generation-server length in token. Longer prompt will slow down the benchmark. Usually the latency grows somewhat linearly with this for the prefill step [env: SEQUENCE_LENGTH=] [default: 10]\n",
56
- " \u001b[1m-d\u001b[0m, \u001b[1m--decode-length\u001b[0m <DECODE_LENGTH>\n",
57
- " This is how many tokens will be generated by the server and averaged out to give the `decode` latency. This is the *critical* number you want to optimize for LLM spend most of their time doing decoding [env: DECODE_LENGTH=] [default: 8]\n",
58
- " \u001b[1m-r\u001b[0m, \u001b[1m--runs\u001b[0m <RUNS>\n",
59
- " How many runs should we average from [env: RUNS=] [default: 10]\n",
60
- " \u001b[1m-w\u001b[0m, \u001b[1m--warmups\u001b[0m <WARMUPS>\n",
61
- " Number of warmup cycles [env: WARMUPS=] [default: 1]\n",
62
- " \u001b[1m-m\u001b[0m, \u001b[1m--master-shard-uds-path\u001b[0m <MASTER_SHARD_UDS_PATH>\n",
63
- " The location of the grpc socket. This benchmark tool bypasses the router completely and directly talks to the gRPC processes [env: MASTER_SHARD_UDS_PATH=] [default: /tmp/text-generation-server-0]\n",
64
- " \u001b[1m--temperature\u001b[0m <TEMPERATURE>\n",
65
- " Generation parameter in case you want to specifically test/debug particular decoding strategies, for full doc refer to the `text-generation-server` [env: TEMPERATURE=]\n",
66
- " \u001b[1m--top-k\u001b[0m <TOP_K>\n",
67
- " Generation parameter in case you want to specifically test/debug particular decoding strategies, for full doc refer to the `text-generation-server` [env: TOP_K=]\n",
68
- " \u001b[1m--top-p\u001b[0m <TOP_P>\n",
69
- " Generation parameter in case you want to specifically test/debug particular decoding strategies, for full doc refer to the `text-generation-server` [env: TOP_P=]\n",
70
- " \u001b[1m--typical-p\u001b[0m <TYPICAL_P>\n",
71
- " Generation parameter in case you want to specifically test/debug particular decoding strategies, for full doc refer to the `text-generation-server` [env: TYPICAL_P=]\n",
72
- " \u001b[1m--repetition-penalty\u001b[0m <REPETITION_PENALTY>\n",
73
- " Generation parameter in case you want to specifically test/debug particular decoding strategies, for full doc refer to the `text-generation-server` [env: REPETITION_PENALTY=]\n",
74
- " \u001b[1m--frequency-penalty\u001b[0m <FREQUENCY_PENALTY>\n",
75
- " Generation parameter in case you want to specifically test/debug particular decoding strategies, for full doc refer to the `text-generation-server` [env: FREQUENCY_PENALTY=]\n",
76
- " \u001b[1m--watermark\u001b[0m\n",
77
- " Generation parameter in case you want to specifically test/debug particular decoding strategies, for full doc refer to the `text-generation-server` [env: WATERMARK=]\n",
78
- " \u001b[1m--do-sample\u001b[0m\n",
79
- " Generation parameter in case you want to specifically test/debug particular decoding strategies, for full doc refer to the `text-generation-server` [env: DO_SAMPLE=]\n",
80
- " \u001b[1m--top-n-tokens\u001b[0m <TOP_N_TOKENS>\n",
81
- " Generation parameter in case you want to specifically test/debug particular decoding strategies, for full doc refer to the `text-generation-server` [env: TOP_N_TOKENS=]\n",
82
- " \u001b[1m-h\u001b[0m, \u001b[1m--help\u001b[0m\n",
83
- " Print help (see more with '--help')\n",
84
- " \u001b[1m-V\u001b[0m, \u001b[1m--version\u001b[0m\n",
85
- " Print version\n"
86
- ]
87
- }
88
- ],
89
- "source": [
90
- "!text-generation-benchmark -h"
91
- ]
92
- },
93
- {
94
- "cell_type": "markdown",
95
- "id": "42d9561b-1aea-4c8c-9fe8-e36af43482fe",
96
- "metadata": {},
97
- "source": [
98
- "Here is an example command. Notice that I add the batch sizes of interest repeatedly to make sure all of them are used by the benchmark tool.\n",
99
- "```bash\n",
100
- "\n",
101
- "text-generation-benchmark \\\n",
102
- "--tokenizer-name astronomer/Llama-3-8B-Instruct-GPTQ-8-Bit \\\n",
103
- "--sequence-length 3000 \\\n",
104
- "--decode-length 300 \\\n",
105
- "--batch-size 1 \\\n",
106
- "--batch-size 2 \\\n",
107
- "--batch-size 3 \\\n",
108
- "--batch-size 4 \\\n",
109
- "--batch-size 5\n",
110
- "```"
111
- ]
112
- }
113
- ],
114
- "metadata": {
115
- "kernelspec": {
116
- "display_name": "Python 3 (ipykernel)",
117
- "language": "python",
118
- "name": "python3"
119
- },
120
- "language_info": {
121
- "codemirror_mode": {
122
- "name": "ipython",
123
- "version": 3
124
- },
125
- "file_extension": ".py",
126
- "mimetype": "text/x-python",
127
- "name": "python",
128
- "nbconvert_exporter": "python",
129
- "pygments_lexer": "ipython3",
130
- "version": "3.10.8"
131
- }
132
- },
133
- "nbformat": 4,
134
- "nbformat_minor": 5
135
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
TGI-launcher.ipynb DELETED
@@ -1,285 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "id": "fe3c1d07-73d2-4906-97c4-2877f42a5fd7",
6
- "metadata": {},
7
- "source": [
8
- "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",
9
- "\n",
10
- "Here are some of the most important ones for our purposes:\n",
11
- "- `--model-id`\n",
12
- "- `--quantize` Most of the time you want to quantize to save memory\n",
13
- "- `--max-input-tokens` We will use a high number for RAG and a low number for Chat\n",
14
- "- `--max-total-tokens` \n",
15
- "- `--max-batch-size` \n",
16
- "- `--max-batch-total-tokens`\n",
17
- "\n",
18
- "These are just used because we are on spaces, and dont want to conflict with the spaces server:\n",
19
- "- `--hostname`\n",
20
- "- `--port`"
21
- ]
22
- },
23
- {
24
- "cell_type": "code",
25
- "execution_count": 2,
26
- "id": "8be5895f-a548-488e-8e5c-dc9ba429a960",
27
- "metadata": {
28
- "tags": []
29
- },
30
- "outputs": [
31
- {
32
- "name": "stdout",
33
- "output_type": "stream",
34
- "text": [
35
- "Text Generation Launcher\n",
36
- "\n",
37
- "\u001b[1m\u001b[4mUsage:\u001b[0m \u001b[1mtext-generation-launcher\u001b[0m [OPTIONS]\n",
38
- "\n",
39
- "\u001b[1m\u001b[4mOptions:\u001b[0m\n",
40
- " \u001b[1m--model-id\u001b[0m <MODEL_ID>\n",
41
- " 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",
42
- " \u001b[1m--revision\u001b[0m <REVISION>\n",
43
- " 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",
44
- " \u001b[1m--validation-workers\u001b[0m <VALIDATION_WORKERS>\n",
45
- " The number of tokenizer workers used for payload validation and truncation inside the router [env: VALIDATION_WORKERS=] [default: 2]\n",
46
- " \u001b[1m--sharded\u001b[0m <SHARDED>\n",
47
- " 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",
48
- " \u001b[1m--num-shard\u001b[0m <NUM_SHARD>\n",
49
- " 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",
50
- " \u001b[1m--quantize\u001b[0m <QUANTIZE>\n",
51
- " Whether you want the model to be quantized [env: QUANTIZE=] [possible values: awq, eetq, gptq, bitsandbytes, bitsandbytes-nf4, bitsandbytes-fp4, fp8]\n",
52
- " \u001b[1m--speculate\u001b[0m <SPECULATE>\n",
53
- " 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",
54
- " \u001b[1m--dtype\u001b[0m <DTYPE>\n",
55
- " The dtype to be forced upon the model. This option cannot be used with `--quantize` [env: DTYPE=] [possible values: float16, bfloat16]\n",
56
- " \u001b[1m--trust-remote-code\u001b[0m\n",
57
- " 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",
58
- " \u001b[1m--max-concurrent-requests\u001b[0m <MAX_CONCURRENT_REQUESTS>\n",
59
- " 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",
60
- " \u001b[1m--max-best-of\u001b[0m <MAX_BEST_OF>\n",
61
- " 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",
62
- " \u001b[1m--max-stop-sequences\u001b[0m <MAX_STOP_SEQUENCES>\n",
63
- " 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",
64
- " \u001b[1m--max-top-n-tokens\u001b[0m <MAX_TOP_N_TOKENS>\n",
65
- " 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",
66
- " \u001b[1m--max-input-tokens\u001b[0m <MAX_INPUT_TOKENS>\n",
67
- " 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",
68
- " \u001b[1m--max-input-length\u001b[0m <MAX_INPUT_LENGTH>\n",
69
- " Legacy version of [`Args::max_input_tokens`] [env: MAX_INPUT_LENGTH=]\n",
70
- " \u001b[1m--max-total-tokens\u001b[0m <MAX_TOTAL_TOKENS>\n",
71
- " 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",
72
- " \u001b[1m--waiting-served-ratio\u001b[0m <WAITING_SERVED_RATIO>\n",
73
- " 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",
74
- " \u001b[1m--max-batch-prefill-tokens\u001b[0m <MAX_BATCH_PREFILL_TOKENS>\n",
75
- " 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",
76
- " \u001b[1m--max-batch-total-tokens\u001b[0m <MAX_BATCH_TOTAL_TOKENS>\n",
77
- " **IMPORTANT** This is one critical control to allow maximum usage of the available hardware [env: MAX_BATCH_TOTAL_TOKENS=]\n",
78
- " \u001b[1m--max-waiting-tokens\u001b[0m <MAX_WAITING_TOKENS>\n",
79
- " 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",
80
- " \u001b[1m--max-batch-size\u001b[0m <MAX_BATCH_SIZE>\n",
81
- " Enforce a maximum number of requests per batch Specific flag for hardware targets that do not support unpadded inference [env: MAX_BATCH_SIZE=]\n",
82
- " \u001b[1m--cuda-graphs\u001b[0m <CUDA_GRAPHS>\n",
83
- " Specify the batch sizes to compute cuda graphs for. Use \"0\" to disable. Default = \"1,2,4,8,16,32\" [env: CUDA_GRAPHS=]\n",
84
- " \u001b[1m--hostname\u001b[0m <HOSTNAME>\n",
85
- " The IP address to listen on [env: HOSTNAME=r-derek-thomas-tgi-benchmark-space-kiwh48a6-ee7f8-q0926] [default: 0.0.0.0]\n",
86
- " \u001b[1m-p\u001b[0m, \u001b[1m--port\u001b[0m <PORT>\n",
87
- " The port to listen on [env: PORT=80] [default: 3000]\n",
88
- " \u001b[1m--shard-uds-path\u001b[0m <SHARD_UDS_PATH>\n",
89
- " The name of the socket for gRPC communication between the webserver and the shards [env: SHARD_UDS_PATH=] [default: /tmp/text-generation-server]\n",
90
- " \u001b[1m--master-addr\u001b[0m <MASTER_ADDR>\n",
91
- " The address the master shard will listen on. (setting used by torch distributed) [env: MASTER_ADDR=] [default: localhost]\n",
92
- " \u001b[1m--master-port\u001b[0m <MASTER_PORT>\n",
93
- " The address the master port will listen on. (setting used by torch distributed) [env: MASTER_PORT=] [default: 29500]\n",
94
- " \u001b[1m--huggingface-hub-cache\u001b[0m <HUGGINGFACE_HUB_CACHE>\n",
95
- " 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",
96
- " \u001b[1m--weights-cache-override\u001b[0m <WEIGHTS_CACHE_OVERRIDE>\n",
97
- " 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",
98
- " \u001b[1m--disable-custom-kernels\u001b[0m\n",
99
- " 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",
100
- " \u001b[1m--cuda-memory-fraction\u001b[0m <CUDA_MEMORY_FRACTION>\n",
101
- " 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",
102
- " \u001b[1m--rope-scaling\u001b[0m <ROPE_SCALING>\n",
103
- " 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",
104
- " \u001b[1m--rope-factor\u001b[0m <ROPE_FACTOR>\n",
105
- " Rope scaling will only be used for RoPE models See `rope_scaling` [env: ROPE_FACTOR=]\n",
106
- " \u001b[1m--json-output\u001b[0m\n",
107
- " Outputs the logs in JSON format (useful for telemetry) [env: JSON_OUTPUT=]\n",
108
- " \u001b[1m--otlp-endpoint\u001b[0m <OTLP_ENDPOINT>\n",
109
- " [env: OTLP_ENDPOINT=]\n",
110
- " \u001b[1m--cors-allow-origin\u001b[0m <CORS_ALLOW_ORIGIN>\n",
111
- " [env: CORS_ALLOW_ORIGIN=]\n",
112
- " \u001b[1m--watermark-gamma\u001b[0m <WATERMARK_GAMMA>\n",
113
- " [env: WATERMARK_GAMMA=]\n",
114
- " \u001b[1m--watermark-delta\u001b[0m <WATERMARK_DELTA>\n",
115
- " [env: WATERMARK_DELTA=]\n",
116
- " \u001b[1m--ngrok\u001b[0m\n",
117
- " Enable ngrok tunneling [env: NGROK=]\n",
118
- " \u001b[1m--ngrok-authtoken\u001b[0m <NGROK_AUTHTOKEN>\n",
119
- " ngrok authentication token [env: NGROK_AUTHTOKEN=]\n",
120
- " \u001b[1m--ngrok-edge\u001b[0m <NGROK_EDGE>\n",
121
- " ngrok edge [env: NGROK_EDGE=]\n",
122
- " \u001b[1m--tokenizer-config-path\u001b[0m <TOKENIZER_CONFIG_PATH>\n",
123
- " 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",
124
- " \u001b[1m--disable-grammar-support\u001b[0m\n",
125
- " 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",
126
- " \u001b[1m-e\u001b[0m, \u001b[1m--env\u001b[0m\n",
127
- " Display a lot of information about your runtime environment\n",
128
- " \u001b[1m--max-client-batch-size\u001b[0m <MAX_CLIENT_BATCH_SIZE>\n",
129
- " Control the maximum number of inputs that a client can send in a single request [env: MAX_CLIENT_BATCH_SIZE=] [default: 4]\n",
130
- " \u001b[1m-h\u001b[0m, \u001b[1m--help\u001b[0m\n",
131
- " Print help (see more with '--help')\n",
132
- " \u001b[1m-V\u001b[0m, \u001b[1m--version\u001b[0m\n",
133
- " Print version\n"
134
- ]
135
- }
136
- ],
137
- "source": [
138
- "!text-generation-launcher -h"
139
- ]
140
- },
141
- {
142
- "cell_type": "markdown",
143
- "id": "598435df-0cdb-411b-96c2-3930fc222f8e",
144
- "metadata": {},
145
- "source": [
146
- "We can launch directly from the notebook since we dont need the command to be interactive."
147
- ]
148
- },
149
- {
150
- "cell_type": "code",
151
- "execution_count": 2,
152
- "id": "f8856772-5173-4549-aebd-0f4564cce143",
153
- "metadata": {
154
- "tags": []
155
- },
156
- "outputs": [
157
- {
158
- "name": "stdout",
159
- "output_type": "stream",
160
- "text": [
161
- "zsh:1: command not found: text-generation-launcher\n"
162
- ]
163
- }
164
- ],
165
- "source": [
166
- "!RUST_BACKTRACE=1 \\\n",
167
- "text-generation-launcher \\\n",
168
- "--model-id astronomer/Llama-3-8B-Instruct-GPTQ-8-Bit \\\n",
169
- "--quantize gptq \\\n",
170
- "--max-input-tokens 3000 \\\n",
171
- "--max-total-tokens 3300 \\\n",
172
- "--max-batch-size 5 \\\n",
173
- "--max-total-tokens 100000 \\\n",
174
- "--hostname 0.0.0.0 \\\n",
175
- "--port 1337 # We need to change it from the default to play well with spaces \n",
176
- "\n"
177
- ]
178
- },
179
- {
180
- "cell_type": "code",
181
- "execution_count": null,
182
- "id": "de3b9694-d417-4d17-a28e-e481703344ec",
183
- "metadata": {},
184
- "outputs": [],
185
- "source": [
186
- "import subprocess\n",
187
- "import time\n",
188
- "\n",
189
- "def launch_server(tokens):\n",
190
- " try:\n",
191
- " command = [\n",
192
- " 'text-generation-launcher',\n",
193
- " '--model-id', 'astronomer/Llama-3-8B-Instruct-GPTQ-8-Bit',\n",
194
- " '--quantize', 'gptq',\n",
195
- " '--max-input-tokens', '3000',\n",
196
- " '--max-batch-size', '5',\n",
197
- " '--max-batch-total-tokens', f'{tokens}',\n",
198
- " '--hostname', '0.0.0.0',\n",
199
- " '--port', '1337',\n",
200
- " ]\n",
201
- " \n",
202
- " # Launch the subprocess with a text command (without shell=True for safety)\n",
203
- " process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)\n",
204
- " \n",
205
- " # Set a time limit to wait for the process to stabilize\n",
206
- " time_limit = 120\n",
207
- " start_time = time.time()\n",
208
- " \n",
209
- " while time.time() - start_time < time_limit:\n",
210
- " output = process.stdout.readline()\n",
211
- " if \"Connected\" in output:\n",
212
- " print(f\"Success message found for {tokens} tokens.\")\n",
213
- " process.terminate() # Gracefully terminate if successful\n",
214
- " return True\n",
215
- " if \"RuntimeError\" in output or \"OutOfMemory\" in output:\n",
216
- " print(f\"Failure message found for {tokens} tokens.\")\n",
217
- " process.terminate()\n",
218
- " return False\n",
219
- " \n",
220
- " # If no specific message was found but the process is still running\n",
221
- " if process.poll() is None:\n",
222
- " print(f\"No specific message but process is still running for {tokens} tokens.\")\n",
223
- " process.terminate()\n",
224
- " return True\n",
225
- " else:\n",
226
- " return False\n",
227
- " except Exception as e:\n",
228
- " print(f\"Error launching server with {tokens} tokens: {e}\")\n",
229
- " return False"
230
- ]
231
- },
232
- {
233
- "cell_type": "code",
234
- "execution_count": null,
235
- "id": "db472c64-2b9f-43fb-aebb-7f853778a1ae",
236
- "metadata": {},
237
- "outputs": [],
238
- "source": [
239
- "%%time\n",
240
- "def find_max_prefill_tokens():\n",
241
- " low, high = 0, 1_000_000 # Adjust the upper bound as needed\n",
242
- " best_valid = 0\n",
243
- " \n",
244
- " while low <= high:\n",
245
- " mid = (low + high) // 2\n",
246
- " print(f\"Testing with {mid} max-total-tokens...\")\n",
247
- " \n",
248
- " if launch_server(mid):\n",
249
- " print(f\"Success with {mid} max-total-tokens.\")\n",
250
- " best_valid = mid # Update best known valid count\n",
251
- " low = mid + 1\n",
252
- " else:\n",
253
- " print(f\"Failed with {mid} max-total-tokens.\")\n",
254
- " high = mid - 1\n",
255
- " \n",
256
- " print(f\"Maximum manageable prefill tokens: {best_valid}\")\n",
257
- " return best_valid\n",
258
- "\n",
259
- "# Call the function\n",
260
- "max_tokens = find_max_prefill_tokens()"
261
- ]
262
- }
263
- ],
264
- "metadata": {
265
- "kernelspec": {
266
- "display_name": "Python 3 (ipykernel)",
267
- "language": "python",
268
- "name": "python3"
269
- },
270
- "language_info": {
271
- "codemirror_mode": {
272
- "name": "ipython",
273
- "version": 3
274
- },
275
- "file_extension": ".py",
276
- "mimetype": "text/x-python",
277
- "name": "python",
278
- "nbconvert_exporter": "python",
279
- "pygments_lexer": "ipython3",
280
- "version": "3.10.8"
281
- }
282
- },
283
- "nbformat": 4,
284
- "nbformat_minor": 5
285
- }