|
1 | 1 | # Fast Inference Solutions for BLOOM
|
2 | 2 |
|
3 |
| -This repo provides demos and packages to perform fast inference solutions for BLOOM. Some of the solutions have their own repos in which case a link to the corresponding repos is provided instead. |
| 3 | +This repo provides demos and packages to perform fast inference solutions for BLOOM. Some of the solutions have their own repos in which case a link to the [corresponding repos](#Other-inference-solutions) is provided instead. |
4 | 4 |
|
5 |
| -Some of the solutions provide both half-precision and int8-quantized solution. |
6 | 5 |
|
7 |
| -## Client-side solutions |
| 6 | +# Inference solutions for BLOOM 176B |
8 | 7 |
|
9 |
| -Solutions developed to perform large batch inference locally: |
| 8 | +We support HuggingFace accelerate and DeepSpeed Inference for generation. |
10 | 9 |
|
11 |
| -Pytorch: |
| 10 | +Install required packages: |
12 | 11 |
|
13 |
| -* [Accelerate, DeepSpeed-Inference and DeepSpeed-ZeRO](./bloom-inference-scripts) |
| 12 | +```shell |
| 13 | +pip install flask flask_api gunicorn pydantic accelerate huggingface_hub>=0.9.0 deepspeed>=0.7.3 deepspeed-mii==0.0.2 |
| 14 | +``` |
14 | 15 |
|
15 |
| -* [Custom HF Code](https://github.com/huggingface/transformers_bloom_parallel/). |
| 16 | +alternatively you can also install deepspeed from source: |
| 17 | +```shell |
| 18 | +git clone https://github.com/microsoft/DeepSpeed |
| 19 | +cd DeepSpeed |
| 20 | +CFLAGS="-I$CONDA_PREFIX/include/" LDFLAGS="-L$CONDA_PREFIX/lib/" TORCH_CUDA_ARCH_LIST="7.0" DS_BUILD_CPU_ADAM=1 DS_BUILD_AIO=1 DS_BUILD_UTILS=1 pip install -e . --global-option="build_ext" --global-option="-j8" --no-cache -v --disable-pip-version-check |
| 21 | +``` |
16 | 22 |
|
17 |
| -JAX: |
| 23 | +All the provided scripts are tested on 8 A100 80GB GPUs for BLOOM 176B (fp16/bf16) and 4 A100 80GB GPUs for BLOOM 176B (int8). These scripts might not work for other models or a different number of GPUs. |
18 | 24 |
|
19 |
| -* [BLOOM Inference in JAX](https://github.com/huggingface/bloom-jax-inference) |
| 25 | +DS inference is deployed using logic borrowed from DeepSpeed MII library. |
20 | 26 |
|
| 27 | +Note: Sometimes GPU memory is not freed when DS inference deployment crashes. You can free this memory by running `killall python` in terminal. |
21 | 28 |
|
| 29 | +For using BLOOM quantized, use dtype = int8. Also, change the model_name to microsoft/bloom-deepspeed-inference-int8 for DeepSpeed-Inference. For HF accelerate, no change is needed for model_name. |
22 | 30 |
|
23 |
| -## Server solutions |
| 31 | +HF accelerate uses [LLM.int8()](https://arxiv.org/abs/2208.07339) and DS-inference uses [ZeroQuant](https://arxiv.org/abs/2206.01861) for post-training quantization. |
| 32 | + |
| 33 | +## BLOOM inference via command-line |
| 34 | + |
| 35 | +This asks for generate_kwargs everytime. |
| 36 | +Example: generate_kwargs = |
| 37 | +```json |
| 38 | +{"min_length": 100, "max_new_tokens": 100, "do_sample": false} |
| 39 | +``` |
| 40 | + |
| 41 | +1. using HF accelerate |
| 42 | +```shell |
| 43 | +python -m inference_server.cli --model_name bigscience/bloom --model_class AutoModelForCausalLM --dtype bf16 --deployment_framework hf_accelerate --generate_kwargs '{"min_length": 100, "max_new_tokens": 100, "do_sample": false}' |
| 44 | +``` |
| 45 | + |
| 46 | +2. using DS inference |
| 47 | +```shell |
| 48 | +python -m inference_server.cli --model_name microsoft/bloom-deepspeed-inference-fp16 --model_class AutoModelForCausalLM --dtype fp16 --deployment_framework ds_inference --generate_kwargs '{"min_length": 100, "max_new_tokens": 100, "do_sample": false}' |
| 49 | +``` |
| 50 | + |
| 51 | +## BLOOM server deployment |
| 52 | + |
| 53 | +[make <model_name>](../Makefile) can be used to launch a generation server. Please note that the serving method is synchronous and users have to wait in queue until the preceding requests have been processed. An example to fire server requests is given [here](../server_request.py). Alternativey, a [Dockerfile](./Dockerfile) is also provided which launches a generation server on port 5000. |
| 54 | + |
| 55 | +An interactive UI can be launched via the following command to connect to the generation server. The default URL of the UI is `http://127.0.0.1:5001/`. |
| 56 | +```shell |
| 57 | +python -m ui |
| 58 | +``` |
| 59 | +This command launches the following UI to play with generation. Sorry for the crappy design. Unfotunately, my UI skills only go so far. 😅😅😅 |
| 60 | + |
| 61 | + |
| 62 | +## Benchmark system for BLOOM inference |
| 63 | + |
| 64 | +1. using HF accelerate |
| 65 | +```shell |
| 66 | +python -m inference_server.benchmark --model_name bigscience/bloom --model_class AutoModelForCausalLM --dtype bf16 --deployment_framework hf_accelerate --benchmark_cycles 5 |
| 67 | +``` |
| 68 | + |
| 69 | +2. using DS inference |
| 70 | +```shell |
| 71 | +deepspeed --num_gpus 8 --module inference_server.benchmark --model_name bigscience/bloom --model_class AutoModelForCausalLM --dtype fp16 --deployment_framework ds_inference --benchmark_cycles 5 |
| 72 | +``` |
| 73 | +alternatively, to load model faster: |
| 74 | +```shell |
| 75 | +deepspeed --num_gpus 8 --module inference_server.benchmark --model_name microsoft/bloom-deepspeed-inference-fp16 --model_class AutoModelForCausalLM --dtype fp16 --deployment_framework ds_inference --benchmark_cycles 5 |
| 76 | +``` |
24 | 77 |
|
25 |
| -Solutions developed to be used in a server mode (i.e. varied batch size, varied request rate): |
| 78 | +3. using DS ZeRO |
| 79 | +```shell |
| 80 | +deepspeed --num_gpus 8 --module inference_server.benchmark --model_name bigscience/bloom --model_class AutoModelForCausalLM --dtype bf16 --deployment_framework ds_zero --benchmark_cycles 5 |
| 81 | +``` |
26 | 82 |
|
27 |
| -Pytorch: |
| 83 | +# Support |
28 | 84 |
|
29 |
| -* [Accelerate and DeepSpeed-Inference based solutions](./bloom-inference-server) |
30 | 85 |
|
31 |
| -Rust: |
| 86 | +If you run into things not working or have other questions please open an Issue in the corresponding backend: |
| 87 | + |
| 88 | +- [Accelerate](https://github.com/huggingface/accelerate/issues) |
| 89 | +- [Deepspeed-Inference](https://github.com/microsoft/DeepSpeed/issues) |
| 90 | +- [Deepspeed-ZeRO](https://github.com/microsoft/DeepSpeed/issues) |
| 91 | + |
| 92 | +If there a specific issue with one of the scripts and not the backend only then please open an Issue here and tag [@mayank31398](https://github.com/mayank31398). |
| 93 | + |
| 94 | + |
| 95 | +# Other inference solutions |
| 96 | +## Client-side solutions |
| 97 | + |
| 98 | +Solutions developed to perform large batch inference locally: |
| 99 | + |
| 100 | +* [Custom HF Code](https://github.com/huggingface/transformers_bloom_parallel/). |
| 101 | + |
| 102 | +JAX: |
| 103 | + |
| 104 | +* [BLOOM Inference in JAX](https://github.com/huggingface/bloom-jax-inference) |
| 105 | + |
| 106 | + |
| 107 | +## Server solutions |
32 | 108 |
|
33 |
| -* [Bloom-server](https://github.com/Narsil/bloomserver) |
| 109 | +A solution developed to be used in a server mode (i.e. varied batch size, varied request rate) can be found [here](https://github.com/Narsil/bloomserver). This is implemented in Rust. |
0 commit comments