{ "cells": [ { "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 \n", " The name of the model to load. Can be a MODEL_ID as listed on 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 \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 \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 \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 \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 \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 \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 \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 \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 \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 \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 \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 \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 \n", " Legacy version of [`Args::max_input_tokens`] [env: MAX_INPUT_LENGTH=]\n", " \u001B[1m--max-total-tokens\u001B[0m \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 \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 \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 \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 \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 \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 \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 \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 \n", " The port to listen on [env: PORT=80] [default: 3000]\n", " \u001B[1m--shard-uds-path\u001B[0m \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 \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 \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 \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 \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 \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 \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 \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 \n", " [env: OTLP_ENDPOINT=]\n", " \u001B[1m--cors-allow-origin\u001B[0m \n", " [env: CORS_ALLOW_ORIGIN=]\n", " \u001B[1m--watermark-gamma\u001B[0m \n", " [env: WATERMARK_GAMMA=]\n", " \u001B[1m--watermark-delta\u001B[0m \n", " [env: WATERMARK_DELTA=]\n", " \u001B[1m--ngrok\u001B[0m\n", " Enable ngrok tunneling [env: NGROK=]\n", " \u001B[1m--ngrok-authtoken\u001B[0m \n", " ngrok authentication token [env: NGROK_AUTHTOKEN=]\n", " \u001B[1m--ngrok-edge\u001B[0m \n", " ngrok edge [env: NGROK_EDGE=]\n", " \u001B[1m--tokenizer-config-path\u001B[0m \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 \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 }