This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vLLM] Support vLLM CPU backend and provide QBits acceleration (#1551)
Co-authored-by: VincyZhang <[email protected]> Co-authored-by: Wang, Chang <[email protected]>
- Loading branch information
1 parent
93b12e9
commit 0e13607
Showing
6 changed files
with
292 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# vLLM Acceleration with ITREX | ||
|
||
Intel extension for transformers(ITREX) integrates the vLLM CPU backend and offers optional [QBits Module](../../docs/qbits.md) to accelerate the vLLM inference on CPUs. | ||
|
||
## Installation Methods | ||
|
||
1. vLLM Installation with CPU: Install vLLM from source code following the instructions provided [here](https://docs.vllm.ai/en/latest/getting_started/cpu-installation.html). | ||
|
||
2. ITREX Installation: Install the ITREX following the [link](../../docs/get_started.md) | ||
|
||
3. Dependencies: Install some additional dependencies that may be used. The dependencies are listed in the current directory. | ||
|
||
Note: torch==2.3.0+cpu is required and vllm==0.4.2+cpu is validated. | ||
|
||
## Usage Example | ||
|
||
ITREX provides a script that demonstrates the vLLM inference acceleration. Run it with the following command: | ||
```bash | ||
numactl -m 0 -C 0-55 python vllm_acceleration_example.py --model_path=/home/model/chatglm2-6b --prompt=你好 | ||
``` | ||
|
||
## Supported and Validated Models | ||
All models listed in the [vLLM Supported Models](https://docs.vllm.ai/en/latest/models/supported_models.html) can be accelerated theoretically. | ||
|
||
We have validated the majority of existing models using vLLM==0.4.2+cpu: | ||
* [THUDM/chatglm2-6b](https://hf-mirror.com/THUDM/chatglm2-6b) | ||
* [meta-llama/Llama-2-7b-chat-hf](https://hf-mirror.com/meta-llama/Llama-2-7b-chat-hf) | ||
* [baichuan-inc/Baichuan2-7B-Chat](https://hf-mirror.com/baichuan-inc/Baichuan2-7B-Chat) | ||
* [tiiuae/falcon-7b](https://huggingface.co/tiiuae/falcon-7b) | ||
* [meta-llama/Meta-Llama-3-8B](https://huggingface.co/meta-llama/Meta-Llama-3-8B) | ||
* [mistralai/Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1) | ||
* [microsoft/phi-2](https://huggingface.co/microsoft/phi-2) | ||
* [Qwen/CodeQwen1.5-7B-Chat](https://huggingface.co/Qwen/CodeQwen1.5-7B-Chat) | ||
|
||
If you encounter any problems, please let us know. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accelerate | ||
datasets | ||
peft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright (c) 2024 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import argparse | ||
import time | ||
import os | ||
from vllm import LLM, SamplingParams | ||
from typing import List, Optional | ||
from intel_extension_for_transformers.transformers import AutoModelForCausalLM, RtnConfig | ||
from transformers import AutoTokenizer | ||
|
||
|
||
def main(args_in: Optional[List[str]] = None) -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--model_path", type=str, help="Model name: String", required=True) | ||
parser.add_argument( | ||
"-p", | ||
"--prompt", | ||
type=str, | ||
help="Prompt to start generation with: String (default: empty)", | ||
default="Once upon a time", | ||
) | ||
parser.add_argument("--benchmark", action="store_true") | ||
parser.add_argument("--use_neural_speed", action="store_true") | ||
args = parser.parse_args(args_in) | ||
print(args) | ||
|
||
if args.benchmark: | ||
if args.use_neural_speed: | ||
os.environ["NEURAL_SPEED_VERBOSE"] = "1" | ||
woq_config = RtnConfig(bits=4, weight_dtype="int4", compute_dtype="int8", scale_dtype="bf16") | ||
model_with_ns = AutoModelForCausalLM.from_pretrained(args.model_path, quantization_config=woq_config) | ||
|
||
tokenizer = AutoTokenizer.from_pretrained(args.model_path, trust_remote_code=True) | ||
inputs = tokenizer(args.prompt, return_tensors="pt").input_ids | ||
|
||
T5 = time.time() | ||
output = model_with_ns.generate(inputs, max_new_tokens=32) | ||
T6 = time.time() | ||
print("neural speed output = ", output) | ||
|
||
llm = LLM(model=args.model_path, trust_remote_code=True) | ||
sampling_params = SamplingParams(max_tokens=32) | ||
T1 = time.time() | ||
original_outputs = llm.generate(args.prompt, sampling_params) # Generate texts from the prompts. | ||
T2 = time.time() | ||
vllm_latency = (T2 - T1) * 1000 | ||
|
||
model = AutoModelForCausalLM.from_pretrained(args.model_path, use_vllm=True) | ||
T3 = time.time() | ||
optimized_output = model.generate(args.prompt, sampling_params) | ||
T4 = time.time() | ||
qbits_latency = (T4 - T3) * 1000 | ||
|
||
print("original outputs = ", original_outputs) | ||
print("input_tokens_length = ", len(original_outputs[0].prompt_token_ids)) | ||
print("output_tokens_length = ", len(original_outputs[0].outputs[0].token_ids)) | ||
|
||
print("optimized outputs = ", optimized_output) | ||
print("input_tokens_length = ", len(optimized_output[0].prompt_token_ids)) | ||
print("output_tokens_length = ", len(optimized_output[0].outputs[0].token_ids)) | ||
|
||
print('The qbits optimized generate:%.2f ms' % qbits_latency) | ||
print('The original vLLM generate:%.2f ms' % vllm_latency) | ||
|
||
return | ||
|
||
model = AutoModelForCausalLM.from_pretrained(args.model_path, use_vllm=True) | ||
output = model.generate(args.prompt) | ||
print(output) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.