CoolFace
Apppublic

sleepdeep/llm-deploy

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
README.md428 linesDownload Raw Back to root
1---2title: llm-deploy3app_file: server.py4sdk: gradio5sdk_version: 3.50.26---7# Text generation web UI8 9A Gradio web UI for Large Language Models.10 11Its goal is to become the [AUTOMATIC1111/stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) of text generation.12 13|![Image1](https://github.com/oobabooga/screenshots/raw/main/print_instruct.png) | ![Image2](https://github.com/oobabooga/screenshots/raw/main/print_chat.png) |14|:---:|:---:|15|![Image1](https://github.com/oobabooga/screenshots/raw/main/print_default.png) | ![Image2](https://github.com/oobabooga/screenshots/raw/main/print_parameters.png) |16 17## Features18 19* 3 interface modes: default (two columns), notebook, and chat.20* Multiple model backends: [Transformers](https://github.com/huggingface/transformers), [llama.cpp](https://github.com/ggerganov/llama.cpp) (through [llama-cpp-python](https://github.com/abetlen/llama-cpp-python)), [ExLlamaV2](https://github.com/turboderp/exllamav2), [AutoGPTQ](https://github.com/PanQiWei/AutoGPTQ), [AutoAWQ](https://github.com/casper-hansen/AutoAWQ), [GPTQ-for-LLaMa](https://github.com/qwopqwop200/GPTQ-for-LLaMa), [CTransformers](https://github.com/marella/ctransformers), [QuIP#](https://github.com/Cornell-RelaxML/quip-sharp).21* Dropdown menu for quickly switching between different models.22* Large number of extensions (built-in and user-contributed), including Coqui TTS for realistic voice outputs, Whisper STT for voice inputs, translation, [multimodal pipelines](https://github.com/oobabooga/text-generation-webui/tree/main/extensions/multimodal), vector databases, Stable Diffusion integration, and a lot more. See [the wiki](https://github.com/oobabooga/text-generation-webui/wiki/07-%E2%80%90-Extensions) and [the extensions directory](https://github.com/oobabooga/text-generation-webui-extensions) for details.23* [Chat with custom characters](https://github.com/oobabooga/text-generation-webui/wiki/03-%E2%80%90-Parameters-Tab#character).24* Precise chat templates for instruction-following models, including Llama-2-chat, Alpaca, Vicuna, Mistral.25* LoRA: train new LoRAs with your own data, load/unload LoRAs on the fly for generation.26* Transformers library integration: load models in 4-bit or 8-bit precision through bitsandbytes, use llama.cpp with transformers samplers (`llamacpp_HF` loader), CPU inference in 32-bit precision using PyTorch.27* OpenAI-compatible API server with Chat and Completions endpoints -- see the [examples](https://github.com/oobabooga/text-generation-webui/wiki/12-%E2%80%90-OpenAI-API#examples).28 29## How to install30 311) Clone or [download](https://github.com/oobabooga/text-generation-webui/archive/refs/heads/main.zip) the repository.322) Run the `start_linux.sh`, `start_windows.bat`, `start_macos.sh`, or `start_wsl.bat` script depending on your OS.333) Select your GPU vendor when asked.344) Once the installation ends, browse to `http://localhost:7860/?__theme=dark`.355) Have fun!36 37To restart the web UI in the future, just run the `start_` script again. This script creates an `installer_files` folder where it sets up the project's requirements. In case you need to reinstall the requirements, you can simply delete that folder and start the web UI again.38 39The script accepts command-line flags. Alternatively, you can edit the `CMD_FLAGS.txt` file with a text editor and add your flags there.40 41To get updates in the future, run `update_linux.sh`, `update_windows.bat`, `update_macos.sh`, or `update_wsl.bat`.42 43<details>44<summary>45Setup details and information about installing manually46</summary>47 48### One-click-installer49 50The script uses Miniconda to set up a Conda environment in the `installer_files` folder.51 52If you ever need to install something manually in the `installer_files` environment, you can launch an interactive shell using the cmd script: `cmd_linux.sh`, `cmd_windows.bat`, `cmd_macos.sh`, or `cmd_wsl.bat`.53 54* There is no need to run any of those scripts (`start_`, `update_`, or `cmd_`) as admin/root.55* For additional instructions about AMD and WSL setup, consult [the documentation](https://github.com/oobabooga/text-generation-webui/wiki).56* For automated installation, you can use the `GPU_CHOICE`, `USE_CUDA118`, `LAUNCH_AFTER_INSTALL`, and `INSTALL_EXTENSIONS` environment variables. For instance: `GPU_CHOICE=A USE_CUDA118=FALSE LAUNCH_AFTER_INSTALL=FALSE INSTALL_EXTENSIONS=FALSE ./start_linux.sh`.57 58### Manual installation using Conda59 60Recommended if you have some experience with the command-line.61 62#### 0. Install Conda63 64https://docs.conda.io/en/latest/miniconda.html65 66On Linux or WSL, it can be automatically installed with these two commands ([source](https://educe-ubc.github.io/conda.html)):67 68```69curl -sL "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" > "Miniconda3.sh"70bash Miniconda3.sh71```72 73#### 1. Create a new conda environment74 75```76conda create -n textgen python=3.1177conda activate textgen78```79 80#### 2. Install Pytorch81 82| System | GPU | Command |83|--------|---------|---------|84| Linux/WSL | NVIDIA | `pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121` |85| Linux/WSL | CPU only | `pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu` |86| Linux | AMD | `pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.6` |87| MacOS + MPS | Any | `pip3 install torch torchvision torchaudio` |88| Windows | NVIDIA | `pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121` |89| Windows | CPU only | `pip3 install torch torchvision torchaudio` |90 91The up-to-date commands can be found here: https://pytorch.org/get-started/locally/.92 93For NVIDIA, you also need to install the CUDA runtime libraries:94 95```96conda install -y -c "nvidia/label/cuda-12.1.1" cuda-runtime97```98 99If you need `nvcc` to compile some library manually, replace the command above with100 101```102conda install -y -c "nvidia/label/cuda-12.1.1" cuda103```104 105#### 3. Install the web UI106 107```108git clone https://github.com/oobabooga/text-generation-webui109cd text-generation-webui110pip install -r <requirements file according to table below>111```112 113Requirements file to use:114 115| GPU | CPU | requirements file to use |116|--------|---------|---------|117| NVIDIA | has AVX2 | `requirements.txt` |118| NVIDIA | no AVX2 | `requirements_noavx2.txt` |119| AMD | has AVX2 | `requirements_amd.txt` |120| AMD | no AVX2 | `requirements_amd_noavx2.txt` |121| CPU only | has AVX2 | `requirements_cpu_only.txt` |122| CPU only | no AVX2 | `requirements_cpu_only_noavx2.txt` |123| Apple | Intel | `requirements_apple_intel.txt` |124| Apple | Apple Silicon | `requirements_apple_silicon.txt` |125 126### Start the web UI127 128```129conda activate textgen130cd text-generation-webui131python server.py132```133 134Then browse to135 136`http://localhost:7860/?__theme=dark`137 138##### AMD GPU on Windows139 1401) Use `requirements_cpu_only.txt` or `requirements_cpu_only_noavx2.txt` in the command above.141 1422) Manually install llama-cpp-python using the appropriate command for your hardware: [Installation from PyPI](https://github.com/abetlen/llama-cpp-python#installation-with-hardware-acceleration).143    * Use the `LLAMA_HIPBLAS=on` toggle.144    * Note the [Windows remarks](https://github.com/abetlen/llama-cpp-python#windows-remarks).145 1463) Manually install AutoGPTQ: [Installation](https://github.com/PanQiWei/AutoGPTQ#install-from-source).147    * Perform the from-source installation - there are no prebuilt ROCm packages for Windows.148 149##### Older NVIDIA GPUs150 1511) For Kepler GPUs and older, you will need to install CUDA 11.8 instead of 12:152 153```154pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118155conda install -y -c "nvidia/label/cuda-11.8.0" cuda-runtime156```157 1582) bitsandbytes >= 0.39 may not work. In that case, to use `--load-in-8bit`, you may have to downgrade like this:159    * Linux: `pip install bitsandbytes==0.38.1`160    * Windows: `pip install https://github.com/jllllll/bitsandbytes-windows-webui/raw/main/bitsandbytes-0.38.1-py3-none-any.whl`161 162##### Manual install163 164The `requirements*.txt` above contain various wheels precompiled through GitHub Actions. If you wish to compile things manually, or if you need to because no suitable wheels are available for your hardware, you can use `requirements_nowheels.txt` and then install your desired loaders manually.165 166### Alternative: Docker167 168```169ln -s docker/{nvidia/Dockerfile,docker-compose.yml,.dockerignore} .170cp docker/.env.example .env171# Edit .env and set: 172#   TORCH_CUDA_ARCH_LIST based on your GPU model173#   APP_RUNTIME_GID      your host user's group id (run `id -g` in a terminal)174#   BUILD_EXTENIONS      optionally add comma separated list of extensions to build175docker compose up --build176```177 178* You need to have Docker Compose v2.17 or higher installed. See [this guide](https://github.com/oobabooga/text-generation-webui/wiki/09-%E2%80%90-Docker) for instructions.179* For additional docker files, check out [this repository](https://github.com/Atinoda/text-generation-webui-docker).180 181### Updating the requirements182 183From time to time, the `requirements*.txt` change. To update, use these commands:184 185```186conda activate textgen187cd text-generation-webui188pip install -r <requirements file that you have used> --upgrade189```190</details>191 192<details>193<summary>194List of command-line flags195</summary>196 197#### Basic settings198 199| Flag                                       | Description |200|--------------------------------------------|-------------|201| `-h`, `--help`                             | show this help message and exit |202| `--multi-user`                             | Multi-user mode. Chat histories are not saved or automatically loaded. WARNING: this is likely not safe for sharing publicly. |203| `--character CHARACTER`                    | The name of the character to load in chat mode by default. |204| `--model MODEL`                            | Name of the model to load by default. |205| `--lora LORA [LORA ...]`                   | The list of LoRAs to load. If you want to load more than one LoRA, write the names separated by spaces. |206| `--model-dir MODEL_DIR`                    | Path to directory with all the models. |207| `--lora-dir LORA_DIR`                      | Path to directory with all the loras. |208| `--model-menu`                             | Show a model menu in the terminal when the web UI is first launched. |209| `--settings SETTINGS_FILE`                 | Load the default interface settings from this yaml file. See `settings-template.yaml` for an example. If you create a file called `settings.yaml`, this file will be loaded by default without the need to use the `--settings` flag. |210| `--extensions EXTENSIONS [EXTENSIONS ...]` | The list of extensions to load. If you want to load more than one extension, write the names separated by spaces. |211| `--verbose`                                | Print the prompts to the terminal. |212| `--chat-buttons`                           | Show buttons on the chat tab instead of a hover menu. |213 214#### Model loader215 216| Flag                                       | Description |217|--------------------------------------------|-------------|218| `--loader LOADER`                          | Choose the model loader manually, otherwise, it will get autodetected. Valid options: Transformers, llama.cpp, llamacpp_HF, ExLlamav2_HF, ExLlamav2, AutoGPTQ, AutoAWQ, GPTQ-for-LLaMa, ctransformers, QuIP#. |219 220#### Accelerate/transformers221 222| Flag                                        | Description |223|---------------------------------------------|-------------|224| `--cpu`                                     | Use the CPU to generate text. Warning: Training on CPU is extremely slow. |225| `--auto-devices`                            | Automatically split the model across the available GPU(s) and CPU. |226|  `--gpu-memory GPU_MEMORY [GPU_MEMORY ...]` | Maximum GPU memory in GiB to be allocated per GPU. Example: --gpu-memory 10 for a single GPU, --gpu-memory 10 5 for two GPUs. You can also set values in MiB like --gpu-memory 3500MiB. |227| `--cpu-memory CPU_MEMORY`                   | Maximum CPU memory in GiB to allocate for offloaded weights. Same as above. |228| `--disk`                                    | If the model is too large for your GPU(s) and CPU combined, send the remaining layers to the disk. |229| `--disk-cache-dir DISK_CACHE_DIR`           | Directory to save the disk cache to. Defaults to "cache". |230| `--load-in-8bit`                            | Load the model with 8-bit precision (using bitsandbytes). |231| `--bf16`                                    | Load the model with bfloat16 precision. Requires NVIDIA Ampere GPU. |232| `--no-cache`                                | Set `use_cache` to `False` while generating text. This reduces VRAM usage slightly, but it comes at a performance cost. |233| `--trust-remote-code`                       | Set `trust_remote_code=True` while loading the model. Necessary for some models. |234| `--no_use_fast`                             | Set use_fast=False while loading the tokenizer (it's True by default). Use this if you have any problems related to use_fast. |235| `--use_flash_attention_2`                   | Set use_flash_attention_2=True while loading the model. |236 237#### bitsandbytes 4-bit238 239⚠️  Requires minimum compute of 7.0 on Windows at the moment.240 241| Flag                                        | Description |242|---------------------------------------------|-------------|243| `--load-in-4bit`                            | Load the model with 4-bit precision (using bitsandbytes). |244| `--use_double_quant`                        | use_double_quant for 4-bit. |245| `--compute_dtype COMPUTE_DTYPE`             | compute dtype for 4-bit. Valid options: bfloat16, float16, float32. |246| `--quant_type QUANT_TYPE`                   | quant_type for 4-bit. Valid options: nf4, fp4. |247 248#### llama.cpp249 250| Flag        | Description |251|-------------|-------------|252| `--tensorcores`  | Use llama-cpp-python compiled with tensor cores support. This increases performance on RTX cards. NVIDIA only. |253| `--n_ctx N_CTX` | Size of the prompt context. |254| `--threads` | Number of threads to use. |255| `--threads-batch THREADS_BATCH` | Number of threads to use for batches/prompt processing. |256| `--no_mul_mat_q` | Disable the mulmat kernels. |257| `--n_batch` | Maximum number of prompt tokens to batch together when calling llama_eval. |258| `--no-mmap`   | Prevent mmap from being used. |259| `--mlock`     | Force the system to keep the model in RAM. |260| `--n-gpu-layers N_GPU_LAYERS` | Number of layers to offload to the GPU. |261| `--tensor_split TENSOR_SPLIT`       | Split the model across multiple GPUs. Comma-separated list of proportions. Example: 18,17. |262| `--numa`      | Activate NUMA task allocation for llama.cpp. |263| `--logits_all`| Needs to be set for perplexity evaluation to work. Otherwise, ignore it, as it makes prompt processing slower. |264| `--no_offload_kqv` | Do not offload the K, Q, V to the GPU. This saves VRAM but reduces the performance. |265| `--cache-capacity CACHE_CAPACITY`   | Maximum cache capacity (llama-cpp-python). Examples: 2000MiB, 2GiB. When provided without units, bytes will be assumed. |266 267#### ExLlamav2268 269| Flag             | Description |270|------------------|-------------|271|`--gpu-split`     | Comma-separated list of VRAM (in GB) to use per GPU device for model layers. Example: 20,7,7. |272|`--max_seq_len MAX_SEQ_LEN`           | Maximum sequence length. |273|`--cfg-cache`                         | ExLlamav2_HF: Create an additional cache for CFG negative prompts. Necessary to use CFG with that loader. |274|`--no_flash_attn`                     | Force flash-attention to not be used. |275|`--cache_8bit`                        | Use 8-bit cache to save VRAM. |276|`--num_experts_per_token NUM_EXPERTS_PER_TOKEN` |  Number of experts to use for generation. Applies to MoE models like Mixtral. |277 278#### AutoGPTQ279 280| Flag             | Description |281|------------------|-------------|282| `--triton`                     | Use triton. |283| `--no_inject_fused_attention`  | Disable the use of fused attention, which will use less VRAM at the cost of slower inference. |284| `--no_inject_fused_mlp`        | Triton mode only: disable the use of fused MLP, which will use less VRAM at the cost of slower inference. |285| `--no_use_cuda_fp16`           | This can make models faster on some systems. |286| `--desc_act`                   | For models that don't have a quantize_config.json, this parameter is used to define whether to set desc_act or not in BaseQuantizeConfig. |287| `--disable_exllama`            | Disable ExLlama kernel, which can improve inference speed on some systems. |288| `--disable_exllamav2`          | Disable ExLlamav2 kernel. |289 290#### GPTQ-for-LLaMa291 292| Flag                      | Description |293|---------------------------|-------------|294| `--wbits WBITS`           | Load a pre-quantized model with specified precision in bits. 2, 3, 4 and 8 are supported. |295| `--model_type MODEL_TYPE` | Model type of pre-quantized model. Currently LLaMA, OPT, and GPT-J are supported. |296| `--groupsize GROUPSIZE`   | Group size. |297| `--pre_layer PRE_LAYER [PRE_LAYER ...]`  | The number of layers to allocate to the GPU. Setting this parameter enables CPU offloading for 4-bit models. For multi-gpu, write the numbers separated by spaces, eg `--pre_layer 30 60`. |298| `--checkpoint CHECKPOINT` | The path to the quantized checkpoint file. If not specified, it will be automatically detected. |299| `--monkey-patch`          | Apply the monkey patch for using LoRAs with quantized models. |300 301#### ctransformers302 303| Flag        | Description |304|-------------|-------------|305| `--model_type MODEL_TYPE` | Model type of pre-quantized model. Currently gpt2, gptj, gptneox, falcon, llama, mpt, starcoder (gptbigcode), dollyv2, and replit are supported. |306 307#### HQQ308 309| Flag        | Description |310|-------------|-------------|311| `--hqq-backend` | Backend for the HQQ loader. Valid options: PYTORCH, PYTORCH_COMPILE, ATEN. |312 313#### DeepSpeed314 315| Flag                                  | Description |316|---------------------------------------|-------------|317| `--deepspeed`                         | Enable the use of DeepSpeed ZeRO-3 for inference via the Transformers integration. |318| `--nvme-offload-dir NVME_OFFLOAD_DIR` | DeepSpeed: Directory to use for ZeRO-3 NVME offloading. |319| `--local_rank LOCAL_RANK`             | DeepSpeed: Optional argument for distributed setups. |320 321#### RoPE (for llama.cpp, ExLlamaV2, and transformers)322 323| Flag             | Description |324|------------------|-------------|325| `--alpha_value ALPHA_VALUE`           | Positional embeddings alpha factor for NTK RoPE scaling. Use either this or `compress_pos_emb`, not both. |326| `--rope_freq_base ROPE_FREQ_BASE`     | If greater than 0, will be used instead of alpha_value. Those two are related by `rope_freq_base = 10000 * alpha_value ^ (64 / 63)`. |327| `--compress_pos_emb COMPRESS_POS_EMB` | Positional embeddings compression factor. Should be set to `(context length) / (model's original context length)`. Equal to `1/rope_freq_scale`. |328 329#### Gradio330 331| Flag                                  | Description |332|---------------------------------------|-------------|333| `--listen`                            | Make the web UI reachable from your local network. |334| `--listen-port LISTEN_PORT`           | The listening port that the server will use. |335| `--listen-host LISTEN_HOST`           | The hostname that the server will use. |336| `--share`                             | Create a public URL. This is useful for running the web UI on Google Colab or similar. |337| `--auto-launch`                       | Open the web UI in the default browser upon launch. |338| `--gradio-auth USER:PWD`              | Set Gradio authentication password in the format "username:password". Multiple credentials can also be supplied with "u1:p1,u2:p2,u3:p3". |339| `--gradio-auth-path GRADIO_AUTH_PATH` | Set the Gradio authentication file path. The file should contain one or more user:password pairs in the same format as above. |340| `--ssl-keyfile SSL_KEYFILE`           | The path to the SSL certificate key file. |341| `--ssl-certfile SSL_CERTFILE`         | The path to the SSL certificate cert file. |342 343#### API344 345| Flag                                  | Description |346|---------------------------------------|-------------|347| `--api`                               | Enable the API extension. |348| `--public-api`                        | Create a public URL for the API using Cloudfare. |349| `--public-api-id PUBLIC_API_ID`       | Tunnel ID for named Cloudflare Tunnel. Use together with public-api option. |350| `--api-port API_PORT`                 | The listening port for the API. |351| `--api-key API_KEY`                   | API authentication key. |352| `--admin-key ADMIN_KEY`               | API authentication key for admin tasks like loading and unloading models. If not set, will be the same as --api-key. |353| `--nowebui`                           | Do not launch the Gradio UI. Useful for launching the API in standalone mode. |354 355#### Multimodal356 357| Flag                                  | Description |358|---------------------------------------|-------------|359| `--multimodal-pipeline PIPELINE`      | The multimodal pipeline to use. Examples: `llava-7b`, `llava-13b`. |360 361</details>362 363## Documentation364 365https://github.com/oobabooga/text-generation-webui/wiki366 367## Downloading models368 369Models should be placed in the folder `text-generation-webui/models`. They are usually downloaded from [Hugging Face](https://huggingface.co/models?pipeline_tag=text-generation&sort=downloads).370 371* GGUF models are a single file and should be placed directly into `models`. Example:372 373```374text-generation-webui375└── models376    └── llama-2-13b-chat.Q4_K_M.gguf377```378 379* The remaining model types (like 16-bit transformers models and GPTQ models) are made of several files and must be placed in a subfolder. Example:380 381```382text-generation-webui383├── models384│   ├── lmsys_vicuna-33b-v1.3385│   │   ├── config.json386│   │   ├── generation_config.json387│   │   ├── pytorch_model-00001-of-00007.bin388│   │   ├── pytorch_model-00002-of-00007.bin389│   │   ├── pytorch_model-00003-of-00007.bin390│   │   ├── pytorch_model-00004-of-00007.bin391│   │   ├── pytorch_model-00005-of-00007.bin392│   │   ├── pytorch_model-00006-of-00007.bin393│   │   ├── pytorch_model-00007-of-00007.bin394│   │   ├── pytorch_model.bin.index.json395│   │   ├── special_tokens_map.json396│   │   ├── tokenizer_config.json397│   │   └── tokenizer.model398```399 400In both cases, you can use the "Model" tab of the UI to download the model from Hugging Face automatically. It is also possible to download it via the command-line with 401 402```403python download-model.py organization/model404```405 406Run `python download-model.py --help` to see all the options.407 408## Google Colab notebook409 410https://colab.research.google.com/github/oobabooga/text-generation-webui/blob/main/Colab-TextGen-GPU.ipynb411 412## Contributing413 414If you would like to contribute to the project, check out the [Contributing guidelines](https://github.com/oobabooga/text-generation-webui/wiki/Contributing-guidelines).415 416## Community417 418* Subreddit: https://www.reddit.com/r/oobabooga/419* Discord: https://discord.gg/jwZCF2dPQN420 421## Acknowledgment422 423In August 2023, [Andreessen Horowitz](https://a16z.com/) (a16z) provided a generous grant to encourage and support my independent work on this project. I am **extremely** grateful for their trust and recognition.424 425## Support426 427[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/B0B5JFPBO)428