Deploying and servicing VLLM models on AMD Rocm based on VLLM project
6.9K
vLLM is a fast and easy-to-use library for LLM inference and serving, it delivers state-of-the-art serving throughput with a set of advanced features such as PagedAttention, Continuous batching and etc.. Besides GPUs, vLLM already supported Intel CPUs and Gaudi accelerators. This guide provides an example on how to launch vLLM serving endpoint on CPU and Gaudi accelerators.
export LLM_ENDPOINT_PORT=8008
export host_ip=${host_ip}
export HF_TOKEN=${HF_TOKEN}
export LLM_ENDPOINT="http://${host_ip}:${LLM_ENDPOINT_PORT}"
export LLM_MODEL_ID="Intel/neural-chat-7b-v3-3"
For gated models such as LLAMA-2, you will have to pass the environment HF_TOKEN. Please follow this link huggingface token to get the access token and export HF_TOKEN environment with the token.
First let's enable VLLM on CPU.
bash ./build_docker_vllm.sh
The build_docker_vllm accepts one parameter hw_mode to specify the hardware mode of the service, with the default being cpu, and the optional selection can be hpu.
bash ./launch_vllm_service.sh
If you want to customize the port or model_name, can run:
bash ./launch_vllm_service.sh ${port_number} ${model_name}
cd deployment/docker_compose
docker compose -f compose.yaml up vllm-server -d
Then we show how to enable VLLM on Gaudi.
bash ./build_docker_vllm.sh hpu
Set hw_mode to hpu.
cd deployment/docker_compose
docker compose -f compose.yaml up vllm-gaudi-server -d
For small model, we can just use single node.
bash ./launch_vllm_service.sh ${port_number} ${model_name} hpu 1
Set hw_mode to hpu and parallel_number to 1.
The launch_vllm_service.sh script accepts 7 parameters:
If you want to get more performance tuning tips, can refer to Performance tuning.
For large model such as meta-llama/Meta-Llama-3-70b, we need to launch on multiple nodes.
bash ./launch_vllm_service.sh ${port_number} ${model_name} hpu ${parallel_number}
For example, if we run meta-llama/Meta-Llama-3-70b with 8 cards, we can use following command.
bash ./launch_vllm_service.sh 8008 meta-llama/Meta-Llama-3-70b hpu 8
vLLM powered by OpenVINO supports all LLM models from vLLM supported models list and can perform optimal model serving on Intel GPU and all x86-64 CPUs with, at least, AVX2 support, as well as on both integrated and discrete Intel® GPUs (starting from Intel® UHD Graphics generation). OpenVINO vLLM backend supports the following advanced vLLM features:
--enable-prefix-caching)--enable-chunked-prefill)To build the docker image for Intel CPU, run the command
bash ./build_docker_vllm_openvino.sh
Once it successfully builds, you will have the vllm-openvino image. It can be used to spawn a serving container with OpenAI API endpoint or you can work with it interactively via bash shell.
For gated models, such as LLAMA-2, you will have to pass -e HUGGING_FACE_HUB_TOKEN=<token> to the docker run command above with a valid Hugging Face Hub read token.
Please follow this link huggingface token to get an access token and export HF_TOKEN environment with the token.
export HF_TOKEN=<token>
To start the model server for Intel CPU:
bash launch_vllm_service_openvino.sh
vLLM OpenVINO backend environment variables
VLLM_OPENVINO_DEVICE to specify which device utilize for the inference. If there are multiple GPUs in the system, additional indexes can be used to choose the proper one (e.g, VLLM_OPENVINO_DEVICE=GPU.1). If the value is not specified, CPU device is used by default.
VLLM_OPENVINO_ENABLE_QUANTIZED_WEIGHTS=ON enables U8 weights compression during model loading stage. By default, compression is turned off. You can also export model with different compression techniques using optimum-cli and pass exported folder as <model_id>
vLLM OpenVINO backend uses the following environment variables to control behavior:
VLLM_OPENVINO_KVCACHE_SPACE to specify the KV Cache size (e.g, VLLM_OPENVINO_KVCACHE_SPACE=40 means 40 GB space for KV cache), larger setting will allow vLLM running more requests in parallel. This parameter should be set based on the hardware configuration and memory management pattern of users.
VLLM_OPENVINO_CPU_KV_CACHE_PRECISION=u8 to control KV cache precision. By default, FP16 / BF16 is used depending on platform.
VLLM_OPENVINO_ENABLE_QUANTIZED_WEIGHTS=ON to enable U8 weights compression during model loading stage. By default, compression is turned off.
To enable better TPOT / TTFT latency, you can use vLLM's chunked prefill feature (--enable-chunked-prefill). Based on the experiments, the recommended batch size is 256 (--max-num-batched-tokens)
OpenVINO best known configuration is:
$ VLLM_OPENVINO_KVCACHE_SPACE=100 VLLM_OPENVINO_CPU_KV_CACHE_PRECISION=u8 VLLM_OPENVINO_ENABLE_QUANTIZED_WEIGHTS=ON \
python3 vllm/benchmarks/benchmark_throughput.py --model meta-llama/Llama-2-7b-chat-hf --dataset vllm/benchmarks/ShareGPT_V3_unfiltered_cleaned_split.json --enable-chunked-prefill --max-num-batched-tokens 256
cd GenAIComps/comps/third_parties/vllm/src
docker build -f Dockerfile.amd_gpu -t opea/vllm-rocm:latest . --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy
cd GenAIComps/comps/third_parties/vllm/deployment/docker_compose
# IP port for vLLM service
export VLLM_SERVICE_PORT=8011
# HF token
export HF_TOKEN="your_hf_token"
# Cache dir
export HF_CACHE_DIR="./data"
# Model
export VLLM_LLM_MODEL_ID="Intel/neural-chat-7b-v3-3"
# Specify the number of GPUs used
export TENSOR_PARALLEL_SIZE=1
# Run deploy
docker compose -f compose.yaml up vllm-rocm-server -d
curl http://${host_ip}:${VLLM_SERVICE_PORT}/v1/chat/completions \
-X POST \
-H "Content-Type: application/json" \
-d '{"model": "Intel/neural-chat-7b-v3-3", "messages": [{"role": "user", "content": "What is Deep Learning?"}]}'
And then you can make requests like below to check the service status:
curl http://${host_ip}:9009/v1/chat/completions \
-X POST \
-H "Content-Type: application/json" \
-d '{"model": "meta-llama/Meta-Llama-3-8B-Instruct", "messages": [{"role": "user", "content": "What is Deep Learning?"}]}'
Then we warp the VLLM service into LLM microservice.
bash build_docker_microservice.sh
bash launch_microservice.sh
curl http://${your_ip}:9000/v1/health_check\
-X GET \
-H 'Content-Type: application/json'
# Output
# {"Service Title":"opea_service@llm_vllm/MicroService","Service Description":"OPEA Microservice Infrastructure"}
User can set the following model parameters according to needs:
# stream mode
curl http://${your_ip}:9000/v1/chat/completions \
-X POST \
-d '{"model": "${model_name}", "messages": "What is Deep Learning?", "max_tokens":17}' \
-H 'Content-Type: application/json'
curl http://${your_ip}:9000/v1/chat/completions \
-X POST \
-d '{"model": "${model_name}", "messages": [{"role": "user", "content": "What is Deep Learning?"}], "max_tokens":17}' \
-H 'Content-Type: application/json'
#Non-stream mode
curl http://${your_ip}:9000/v1/chat/completions \
-X POST \
-d '{"model": "${model_name}", "messages": "What is Deep Learning?", "max_tokens":17, "stream":false}' \
-H 'Content-Type: application/json'
Content type
Image
Digest
sha256:441a1dc60…
Size
8.8 GB
Last updated
6 months ago
docker pull opea/vllm-rocm