ColossalAI/colossalai/inference
Jianghai cf579ff46d
[Inference] Dynamic Batching Inference, online and offline (#4953)
* [inference] Dynamic Batching for Single and Multiple GPUs (#4831)

* finish batch manager

* 1

* first

* fix

* fix dynamic batching

* llama infer

* finish test

* support different lengths generating

* del prints

* del prints

* fix

* fix bug

---------

Co-authored-by: CjhHa1 <cjh18671720497outlook.com>

* [inference] Async dynamic batching  (#4894)

* finish input and output logic

* add generate

* test forward

* 1

* [inference]Re push async dynamic batching (#4901)

* adapt to ray server

* finish async

* finish test

* del test

---------

Co-authored-by: yuehuayingxueluo <867460659@qq.com>

* Revert "[inference]Re push async dynamic batching (#4901)" (#4905)

This reverts commit fbf3c09e67.

* Revert "[inference] Async dynamic batching  (#4894)"

This reverts commit fced140250.

* Revert "[inference] Async dynamic batching  (#4894)" (#4909)

This reverts commit fced140250.

* Add Ray Distributed Environment Init Scripts

* support DynamicBatchManager base function

* revert _set_tokenizer version

* add driver async generate

* add async test

* fix bugs in test_ray_dist.py

* add get_tokenizer.py

* fix code style

* fix bugs about No module named 'pydantic' in ci test

* fix bugs in ci test

* fix bugs in ci test

* fix bugs in ci test

* [infer]Add Ray Distributed Environment Init Scripts (#4911)

* Revert "[inference] Async dynamic batching  (#4894)"

This reverts commit fced140250.

* Add Ray Distributed Environment Init Scripts

* support DynamicBatchManager base function

* revert _set_tokenizer version

* add driver async generate

* add async test

* fix bugs in test_ray_dist.py

* add get_tokenizer.py

* fix code style

* fix bugs about No module named 'pydantic' in ci test

* fix bugs in ci test

* fix bugs in ci test

* fix bugs in ci test

* support dynamic batch for bloom model and is_running function

* [Inference]Test for new Async engine (#4935)

* infer engine

* infer engine

* test engine

* test engine

* new manager

* change step

* add

* test

* fix

* fix

* finish test

* finish test

* finish test

* finish test

* add license

---------

Co-authored-by: yuehuayingxueluo <867460659@qq.com>

* add assertion for config (#4947)

* [Inference] Finish dynamic batching offline test (#4948)

* test

* fix test

* fix quant

* add default

* fix

* fix some bugs

* fix some bugs

* fix

* fix bug

* fix bugs

* reset param

---------

Co-authored-by: yuehuayingxueluo <867460659@qq.com>
Co-authored-by: Cuiqing Li <lixx3527@gmail.com>
Co-authored-by: CjhHa1 <cjh18671720497outlook.com>
2023-10-30 10:52:19 +08:00
..
dynamic_batching [Inference] Dynamic Batching Inference, online and offline (#4953) 2023-10-30 10:52:19 +08:00
pipeline [Pipeline inference] Combine kvcache with pipeline inference (#4938) 2023-10-27 16:19:54 +08:00
quant [Inference] Dynamic Batching Inference, online and offline (#4953) 2023-10-30 10:52:19 +08:00
tensor_parallel [Inference] Dynamic Batching Inference, online and offline (#4953) 2023-10-30 10:52:19 +08:00
README.md [Refactor] Integrated some lightllm kernels into token-attention (#4946) 2023-10-19 22:22:47 +08:00
__init__.py [Pipeline inference] Combine kvcache with pipeline inference (#4938) 2023-10-27 16:19:54 +08:00
async_engine.py [Inference] Dynamic Batching Inference, online and offline (#4953) 2023-10-30 10:52:19 +08:00
async_manager.py [Inference] Dynamic Batching Inference, online and offline (#4953) 2023-10-30 10:52:19 +08:00
manager.py [Inference] Dynamic Batching Inference, online and offline (#4953) 2023-10-30 10:52:19 +08:00

README.md

🚀 Colossal-Inference

Table of contents

Introduction

Colossal Inference is a module that contains colossal-ai designed inference framework, featuring high performance, steady and easy usability. Colossal Inference incorporated the advantages of the latest open-source inference systems, including LightLLM, TGI, vLLM, FasterTransformer and flash attention. while combining the design of Colossal AI, especially Shardformer, to reduce the learning curve for users.

Design

Colossal Inference is composed of two main components:

  1. High performance kernels and ops: which are inspired from existing libraries and modified correspondingly.
  2. Efficient memory management mechanismwhich includes the key-value cache manager, allowing for zero memory waste during inference.
    1. cache manager: serves as a memory manager to help manage the key-value cache, it integrates functions such as memory allocation, indexing and release.
    2. batch_infer_info: holds all essential elements of a batch inference, which is updated every batch.
  3. High-level inference engine combined with Shardformer: it allows our inference framework to easily invoke and utilize various parallel methods.
    1. engine.TPInferEngine: it is a high level interface that integrates with shardformer, especially for multi-card (tensor parallel) inference:
    2. modeling.llama.LlamaInferenceForwards: contains the forward methods for llama inference. (in this case : llama)
    3. policies.llama.LlamaModelInferPolicy : contains the policies for llama models, which is used to call shardformer and segmentate the model forward in tensor parallelism way.

Pipeline of inference:

In this section we discuss how the colossal inference works and integrates with the Shardformer . The details can be found in our codes.

Colossal-Inference

Roadmap of our implementation

  • Design cache manager and batch infer state
  • Design TpInference engine to integrates with Shardformer
  • Register corresponding high-performance kernel and ops
  • Design policies and forwards (e.g. Llama and Bloom)
    • policy
    • context forward
    • token forward
  • Replace the kernels with faster-transformer in token-forward stage
  • Support all models
    • Llama
    • Bloom
    • Chatglm2
  • Benchmarking for all models

Get started

Installation

pip install -e .

Requirements

dependencies

pytorch= 1.13.1 (gpu)
cuda>= 11.6
transformers= 4.30.2
triton==2.0.0.dev20221202
# for install vllm, please use this branch to install https://github.com/tiandiao123/vllm/tree/setup_branch
vllm
# for install flash-attention, please use commit hash: 67ae6fd74b4bc99c36b2ce524cf139c35663793c
flash-attention

# install lightllm since we depend on lightllm triton kernels
git clone https://github.com/ModelTC/lightllm 
git checkout 28c1267cfca536b7b4f28e921e03de735b003039
cd lightllm
pip3 install -e .

Docker

You can use docker run to use docker container to set-up environment

# env: python==3.8, cuda 11.6, pytorch == 1.13.1 triton==2.0.0.dev20221202, vllm kernels support, flash-attention-2 kernels support
docker pull hpcaitech/colossalai-inference:v2
docker run -it --gpus all --name ANY_NAME -v $PWD:/workspace -w /workspace hpcaitech/colossalai-inference:v2 /bin/bash

# enter into docker container
cd /path/to/CollossalAI
pip install -e .

# install lightllm
git clone https://github.com/ModelTC/lightllm 
git checkout 28c1267cfca536b7b4f28e921e03de735b003039
cd lightllm
pip3 install -e .


Dive into fast-inference!

example files are in

cd colossalai.examples
python xx

Performance

environment:

We conducted multiple benchmark tests to evaluate the performance. We compared the inference latency and throughputs between colossal-inference and original hugging-face torch fp16.

For various models, experiments were conducted using multiple batch sizes under the consistent model configuration of 7 billion(7b) parameters, 1024 input length, and 128 output length. The obtained results are as follows (due to time constraints, the evaluation has currently been performed solely on the A100 single GPU performance; multi-GPU performance will be addressed in the future):

Single GPU Performance:

Currently the stats below are calculated based on A100 (single GPU), and we calculate token latency based on average values of context-forward and decoding forward process, which means we combine both of processes to calculate token generation times. We are actively developing new features and methods to further optimize the performance of LLM models. Please stay tuned.

Llama

batch_size 8 16 32
hugging-face torch fp16 199.12 246.56 278.4
colossal-inference 326.4 582.72 816.64

llama

Bloom

batch_size 8 16 32
hugging-face torch fp16 189.68 226.66 249.61
colossal-inference 323.28 538.52 611.64

bloom

The results of more models are coming soon!