hf_text-generation-inference/README.md

156 lines
4.6 KiB
Markdown
Raw Normal View History

<div align="center">
# Text Generation Inference
2022-10-08 04:30:12 -06:00
<a href="https://github.com/huggingface/text-generation-inference">
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/huggingface/text-generation-inference?style=social">
</a>
<a href="https://github.com/huggingface/text-generation-inference/blob/main/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/huggingface/text-generation-inference">
</a>
<a href="https://huggingface.github.io/text-generation-inference">
<img alt="Swagger API documentation" src="https://img.shields.io/badge/API-Swagger-informational">
</a>
2022-10-18 07:19:03 -06:00
![architecture](assets/architecture.jpg)
</div>
A Rust, Python and gRPC server for text generation inference. Used in production at [HuggingFace](https://huggingface.co)
to power LLMs api-inference widgets.
## Table of contents
- [Features](#features)
- [Officially Supported Models](#officially-supported-models)
- [Get Started](#get-started)
- [Docker](#docker)
- [Local Install](#local-install)
- [OpenAPI](#api-documentation)
- [CUDA Kernels](#cuda-kernels)
- [Run BLOOM](#run-bloom)
- [Download](#download)
- [Run](#run)
- [Quantization](#quantization)
- [Develop](#develop)
- [Testing](#testing)
2022-10-27 06:25:29 -06:00
## Features
- Token streaming using Server Side Events (SSE)
2022-11-14 08:22:10 -07:00
- [Dynamic batching of incoming requests](https://github.com/huggingface/text-generation-inference/blob/main/router/src/batcher.rs#L88) for increased total throughput
- Quantization with [bitsandbytes](https://github.com/TimDettmers/bitsandbytes)
2022-10-27 06:25:29 -06:00
- [Safetensors](https://github.com/huggingface/safetensors) weight loading
- 45ms per token generation for BLOOM with 8xA100 80GB
- Logits warpers (temperature scaling, topk, repetition penalty ...)
2022-12-12 10:25:22 -07:00
- Stop sequences
2022-12-15 09:03:56 -07:00
- Log probabilities
2022-10-27 06:25:29 -06:00
2022-11-07 04:53:56 -07:00
## Officially supported models
2022-11-07 04:53:56 -07:00
- [BLOOM](https://huggingface.co/bigscience/bloom)
- [BLOOMZ](https://huggingface.co/bigscience/bloomz)
- [MT0-XXL](https://huggingface.co/bigscience/mt0-xxl)
2022-12-01 11:31:54 -07:00
- ~~[Galactica](https://huggingface.co/facebook/galactica-120b)~~ (deactivated)
2023-01-20 04:24:39 -07:00
- [SantaCoder](https://huggingface.co/bigcode/santacoder)
- [GPT-Neox 20B](https://huggingface.co/EleutherAI/gpt-neox-20b): use `--revision pr/13`
2022-10-27 06:25:29 -06:00
Other models are supported on a best effort basis using:
`AutoModelForCausalLM.from_pretrained(<model>, device_map="auto")`
or
`AutoModelForSeq2SeqLM.from_pretrained(<model>, device_map="auto")`
## Get started
### Docker
The easiest way of getting started is using the official Docker container:
```shell
model=bigscience/bloom-560m
num_shard=2
volume=$PWD/data # share a volume with the Docker container to avoid downloading weights every run
docker run --gpus all -p 8080:80 -v $volume:/data ghcr.io/huggingface/text-generation-inference:latest --model-id $model --num-shard $num_shard
```
You can then query the model using either the `/generate` or `/generate_stream` routes:
2022-10-08 04:30:12 -06:00
```shell
curl 127.0.0.1:8080/generate \
-X POST \
-d '{"inputs":"Testing API","parameters":{"max_new_tokens":9}}' \
-H 'Content-Type: application/json'
```
2022-10-08 04:30:12 -06:00
```shell
curl 127.0.0.1:8080/generate_stream \
-X POST \
-d '{"inputs":"Testing API","parameters":{"max_new_tokens":9}}' \
-H 'Content-Type: application/json'
2022-10-08 04:30:12 -06:00
```
To use GPUs, you will need to install the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html).
### API documentation
2022-10-08 04:30:12 -06:00
You can consult the OpenAPI documentation of the `text-generation-inference` REST API using the `/docs` route.
The Swagger UI is also available at: [https://huggingface.github.io/text-generation-inference](https://huggingface.github.io/text-generation-inference).
### Local install
You can also opt to install `text-generation-inference` locally. You will need to have cargo and Python installed on your
machine
2022-10-27 06:25:29 -06:00
2022-10-08 04:30:12 -06:00
```shell
BUILD_EXTENSIONS=True make install # Install repository and HF/transformer fork with CUDA kernels
2022-10-18 07:19:03 -06:00
make run-bloom-560m
2022-10-08 04:30:12 -06:00
```
### CUDA Kernels
The custom CUDA kernels are only tested on NVIDIA A100s. If you have any installation or runtime issues, you can remove
the kernels by using the `BUILD_EXTENSIONS=False` environment variable.
Be aware that the official Docker image has them enabled by default.
## Run BLOOM
### Download
2022-10-27 06:25:29 -06:00
First you need to download the weights:
```shell
make download-bloom
```
### Run
2022-10-27 06:25:29 -06:00
```shell
make run-bloom # Requires 8xA100 80GB
```
### Quantization
2022-10-27 06:25:29 -06:00
You can also quantize the weights with bitsandbytes to reduce the VRAM requirement:
```shell
make run-bloom-quantize # Requires 8xA100 40GB
```
## Develop
2022-10-18 07:19:03 -06:00
2022-10-08 04:30:12 -06:00
```shell
make server-dev
make router-dev
2022-10-08 04:30:12 -06:00
```
## Testing
```shell
make python-tests
make integration-tests
2022-12-08 10:49:33 -07:00
```