-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vLLM inference engine support (#398)
Signed-off-by: Dolpher Du <[email protected]> Co-authored-by: Gang G Li <[email protected]>
- Loading branch information
1 parent
923c1f3
commit 0094f52
Showing
10 changed files
with
454 additions
and
0 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,23 @@ | ||
# Patterns to ignore when building packages. | ||
# This supports shell glob matching, relative path matching, and | ||
# negation (prefixed with !). Only one pattern per line. | ||
.DS_Store | ||
# Common VCS dirs | ||
.git/ | ||
.gitignore | ||
.bzr/ | ||
.bzrignore | ||
.hg/ | ||
.hgignore | ||
.svn/ | ||
# Common backup files | ||
*.swp | ||
*.bak | ||
*.tmp | ||
*.orig | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj | ||
.vscode/ |
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,10 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
apiVersion: v2 | ||
name: vllm | ||
description: The Helm chart for vLLM Inference Server | ||
type: application | ||
version: 1.0.0 | ||
# The vLLM version | ||
appVersion: "0.5" |
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,53 @@ | ||
# vllm | ||
|
||
Helm chart for deploying vLLM Inference service. | ||
|
||
Refer to [Deploy with Helm Charts](../README.md) for global guides. | ||
|
||
## Installing the Chart | ||
|
||
To install the chart, run the following: | ||
|
||
Note that you cannot use vllm as the service release name due to [environment variables conflict](https://docs.vllm.ai/en/stable/serving/env_vars.html#environment-variables). | ||
|
||
```console | ||
cd GenAIInfra/helm-charts/common | ||
export MODELDIR=/mnt/opea-models | ||
export MODELNAME="Intel/neural-chat-7b-v3-3" | ||
export HFTOKEN="insert-your-huggingface-token-here" | ||
helm install myvllm vllm --set global.modelUseHostPath=${MODELDIR} --set LLM_MODEL_ID=${MODELNAME} --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} | ||
# To deploy on Gaudi enabled kubernetes cluster | ||
# helm install myvllm vllm --set global.modelUseHostPath=${MODELDIR} --set LLM_MODEL_ID=${MODELNAME} --set global.HUGGINGFACEHUB_API_TOKEN=${HFTOKEN} --values gaudi-values.yaml | ||
``` | ||
|
||
By default, the vllm service will downloading the "Intel/neural-chat-7b-v3-3". | ||
|
||
If you already cached the model locally, you can pass it to container like this example: | ||
|
||
MODELDIR=/mnt/opea-models | ||
|
||
MODELNAME="facebook/opt-125m" | ||
|
||
## Verify | ||
|
||
To verify the installation, run the command `kubectl get pod` to make sure all pods are runinng. | ||
|
||
Then run the command `kubectl port-forward svc/myvllm 2080:80` to expose the vllm service for access. | ||
|
||
Open another terminal and run the following command to verify the service if working: | ||
|
||
```console | ||
curl http://localhost:2080/v1/completions \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"model": "Intel/neural-chat-7b-v3-3", "prompt": "What is Deep Learning?", "max_tokens": 32, "temperature": 0}' | ||
``` | ||
|
||
## Values | ||
|
||
| Key | Type | Default | Description | | ||
| ------------------------------- | ------ | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| LLM_MODEL_ID | string | `"Intel/neural-chat-7b-v3-3"` | Models id from https://huggingface.co/, or predownloaded model directory | | ||
| global.HUGGINGFACEHUB_API_TOKEN | string | `insert-your-huggingface-token-here` | Hugging Face API token | | ||
| global.modelUseHostPath | string | `""` | Cached models directory, vllm will not download if the model is cached here. The host path "modelUseHostPath" will be mounted to container as /data directory. Set this to null/empty will force it to download model. | | ||
| image.repository | string | `"opea/vllm"` | | | ||
| image.tag | string | `"latest"` | | |
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,19 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Default values for vllm. | ||
# This is a YAML-formatted file. | ||
# Declare variables to be passed into your templates. | ||
|
||
image: | ||
repository: opea/llm-vllm-hpu | ||
tag: "latest" | ||
|
||
VLLM_CPU_KVCACHE_SPACE: "40" | ||
|
||
# Workaround for current HPU image with start command /bin/bash | ||
# extraCmdArgs: ["--enforce-eager","--tensor-parallel-size","1","--block-size","128","--max-num-seqs","256","--max-seq_len-to-capture","2048"] | ||
extraCmdArgs: ["/bin/bash","-c","python3 -m vllm.entrypoints.openai.api_server --enforce-eager --model Intel/neural-chat-7b-v3-3 --tensor-parallel-size 1 --host 0.0.0.0 --port 2080 --download-dir /data --block-size 128 --max-num-seqs 256 --max-seq_len-to-capture 2048"] | ||
resources: | ||
limits: | ||
habana.ai/gaudi: 1 |
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,62 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "vllm.name" -}} | ||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "vllm.fullname" -}} | ||
{{- if .Values.fullnameOverride }} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- $name := default .Chart.Name .Values.nameOverride }} | ||
{{- if contains $name .Release.Name }} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "vllm.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "vllm.labels" -}} | ||
helm.sh/chart: {{ include "vllm.chart" . }} | ||
{{ include "vllm.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "vllm.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "vllm.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name of the service account to use | ||
*/}} | ||
{{- define "vllm.serviceAccountName" -}} | ||
{{- if .Values.serviceAccount.create }} | ||
{{- default (include "vllm.fullname" .) .Values.serviceAccount.name }} | ||
{{- else }} | ||
{{- default "default" .Values.serviceAccount.name }} | ||
{{- end }} | ||
{{- end }} |
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,25 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ include "vllm.fullname" . }}-config | ||
labels: | ||
{{- include "vllm.labels" . | nindent 4 }} | ||
data: | ||
HF_TOKEN: {{ .Values.global.HUGGINGFACEHUB_API_TOKEN | quote}} | ||
{{- if .Values.global.HF_ENDPOINT }} | ||
HF_ENDPOINT: {{ .Values.global.HF_ENDPOINT | quote}} | ||
{{- end }} | ||
http_proxy: {{ .Values.global.http_proxy | quote }} | ||
https_proxy: {{ .Values.global.https_proxy | quote }} | ||
no_proxy: {{ .Values.global.no_proxy | quote }} | ||
HABANA_LOGS: "/tmp/habana_logs" | ||
NUMBA_CACHE_DIR: "/tmp" | ||
HF_HOME: "/tmp/.cache/huggingface" | ||
# https://github.com/outlines-dev/outlines/blob/main/outlines/caching.py#L14-L29 | ||
OUTLINES_CACHE_DIR: "/tmp/.cache/outlines" | ||
{{- if .Values.VLLM_CPU_KVCACHE_SPACE }} | ||
VLLM_CPU_KVCACHE_SPACE: {{ .Values.VLLM_CPU_KVCACHE_SPACE | quote}} | ||
{{- end }} |
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,116 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ include "vllm.fullname" . }} | ||
labels: | ||
{{- include "vllm.labels" . | nindent 4 }} | ||
spec: | ||
replicas: {{ .Values.replicaCount }} | ||
selector: | ||
matchLabels: | ||
{{- include "vllm.selectorLabels" . | nindent 6 }} | ||
template: | ||
metadata: | ||
{{- with .Values.podAnnotations }} | ||
annotations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
labels: | ||
{{- include "vllm.selectorLabels" . | nindent 8 }} | ||
spec: | ||
{{- with .Values.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
securityContext: | ||
{{- toYaml .Values.podSecurityContext | nindent 8 }} | ||
containers: | ||
- name: {{ .Chart.Name }} | ||
envFrom: | ||
- configMapRef: | ||
name: {{ include "vllm.fullname" . }}-config | ||
{{- if .Values.global.extraEnvConfig }} | ||
- configMapRef: | ||
name: {{ .Values.global.extraEnvConfig }} | ||
optional: true | ||
{{- end }} | ||
securityContext: | ||
{{- if .Values.global.modelUseHostPath }} | ||
{} | ||
{{- else }} | ||
{{- toYaml .Values.securityContext | nindent 12 }} | ||
{{- end }} | ||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||
imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
args: | ||
{{- if .Values.extraCmdArgs }} | ||
{{- range .Values.extraCmdArgs }} | ||
- {{ . | quote }} | ||
{{- end }} | ||
{{- end }} | ||
- "--model" | ||
- {{ .Values.LLM_MODEL_ID | quote }} | ||
- "--host" | ||
- "0.0.0.0" | ||
- "--port" | ||
- {{ .Values.port | quote }} | ||
- "--download-dir" | ||
- "/data" | ||
volumeMounts: | ||
- mountPath: /data | ||
name: model-volume | ||
- mountPath: /dev/shm | ||
name: shm | ||
- mountPath: /tmp | ||
name: tmp | ||
ports: | ||
- name: http | ||
containerPort: {{ .Values.port }} | ||
protocol: TCP | ||
{{- if .Values.livenessProbe }} | ||
livenessProbe: | ||
{{- toYaml .Values.livenessProbe | nindent 12 }} | ||
{{- end }} | ||
{{- if .Values.readinessProbe }} | ||
readinessProbe: | ||
{{- toYaml .Values.readinessProbe | nindent 12 }} | ||
{{- end }} | ||
{{- if .Values.startupProbe }} | ||
startupProbe: | ||
{{- toYaml .Values.startupProbe | nindent 12 }} | ||
{{- end }} | ||
resources: | ||
{{- toYaml .Values.resources | nindent 12 }} | ||
volumes: | ||
- name: model-volume | ||
{{- if .Values.global.modelUsePVC }} | ||
persistentVolumeClaim: | ||
claimName: {{ .Values.global.modelUsePVC }} | ||
{{- else if .Values.global.modelUseHostPath }} | ||
hostPath: | ||
path: {{ .Values.global.modelUseHostPath }} | ||
type: Directory | ||
{{- else }} | ||
emptyDir: {} | ||
{{- end }} | ||
- name: shm | ||
emptyDir: | ||
medium: Memory | ||
sizeLimit: {{ .Values.shmSize }} | ||
- name: tmp | ||
emptyDir: {} | ||
{{- with .Values.nodeSelector }} | ||
nodeSelector: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.affinity }} | ||
affinity: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.tolerations }} | ||
tolerations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} |
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,18 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ include "vllm.fullname" . }} | ||
labels: | ||
{{- include "vllm.labels" . | nindent 4 }} | ||
spec: | ||
type: {{ .Values.service.type }} | ||
ports: | ||
- port: 80 | ||
targetPort: {{ .Values.port }} | ||
protocol: TCP | ||
name: vllm | ||
selector: | ||
{{- include "vllm.selectorLabels" . | nindent 4 }} |
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,29 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: "{{ include "vllm.fullname" . }}-testpod" | ||
labels: | ||
{{- include "vllm.labels" . | nindent 4 }} | ||
annotations: | ||
"helm.sh/hook": test | ||
#"helm.sh/hook-delete-policy": "hook-succeeded, hook-failure" | ||
spec: | ||
containers: | ||
- name: curl | ||
image: python:3.10.14 | ||
command: ['bash', '-c'] | ||
args: | ||
- | | ||
max_retry=20; | ||
for ((i=1; i<=max_retry; i++)); do | ||
curl http://{{ include "vllm.fullname" . }}/v1/completions \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"model": {{ .Values.LLM_MODEL_ID | quote }},"prompt": "What is Deep Learning?","max_tokens": 32,"temperature": 0}' && break; | ||
curlcode=$? | ||
if [[ $curlcode -eq 7 ]]; then sleep 10; else echo "curl failed with code $curlcode"; exit 1; fi; | ||
done; | ||
if [ $i -gt $max_retry ]; then echo "test failed with maximum retry"; exit 1; fi | ||
restartPolicy: Never |
Oops, something went wrong.