Skip to content

Commit e80e567

Browse files
Add gpu support for ChatQnA (#308)
* add gpu support for chatqna Signed-off-by: Ding, Ke <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Ding, Ke <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4fecd6a commit e80e567

File tree

4 files changed

+470
-1
lines changed

4 files changed

+470
-1
lines changed

ChatQnA/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Refer to the [Gaudi Guide](./docker/gaudi/README.md) for instructions on deployi
2222

2323
Refer to the [Xeon Guide](./docker/xeon/README.md) for instructions on deploying ChatQnA on Xeon.
2424

25+
## Deploy ChatQnA on NVIDIA GPU
26+
27+
Refer to the [NVIDIA GPU Guide](./docker/gpu/README.md) for instructions on deploying ChatQnA on NVIDIA GPU.
28+
2529
## Deploy ChatQnA into Kubernetes on Xeon & Gaudi
2630

2731
Refer to the [Kubernetes Guide](./kubernetes/manifests/README.md) for instructions on deploying ChatQnA into Kubernetes on Xeon & Gaudi.

ChatQnA/docker/gpu/README.md

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
# Build MegaService of ChatQnA on NVIDIA GPU
2+
3+
This document outlines the deployment process for a ChatQnA application utilizing the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline on NVIDIA GPU platform. The steps include Docker image creation, container deployment via Docker Compose, and service execution to integrate microservices such as embedding, retriever, rerank, and llm. We will publish the Docker images to Docker Hub, it will simplify the deployment process for this service.
4+
5+
## 🚀 Build Docker Images
6+
7+
First of all, you need to build Docker Images locally. This step can be ignored after the Docker images published to Docker hub.
8+
9+
### 1. Source Code install GenAIComps
10+
11+
```bash
12+
git clone https://github.com/opea-project/GenAIComps.git
13+
cd GenAIComps
14+
```
15+
16+
### 2. Build Embedding Image
17+
18+
```bash
19+
docker build --no-cache -t opea/embedding-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/langchain/docker/Dockerfile .
20+
```
21+
22+
### 3. Build Retriever Image
23+
24+
```bash
25+
docker build --no-cache -t opea/retriever-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/redis/docker/Dockerfile .
26+
```
27+
28+
### 4. Build Rerank Image
29+
30+
```bash
31+
docker build --no-cache -t opea/reranking-tei:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/reranks/langchain/docker/Dockerfile .
32+
```
33+
34+
### 5. Build LLM Image
35+
36+
```bash
37+
docker build --no-cache -t opea/llm-tgi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/llms/text-generation/tgi/Dockerfile .
38+
```
39+
40+
### 6. Build Dataprep Image
41+
42+
```bash
43+
docker build --no-cache -t opea/dataprep-redis:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/redis/langchain/docker/Dockerfile .
44+
```
45+
46+
### 7. Build MegaService Docker Image
47+
48+
To construct the Mega Service, we utilize the [GenAIComps](https://github.com/opea-project/GenAIComps.git) microservice pipeline within the `chatqna.py` Python script. Build the MegaService Docker image using the command below:
49+
50+
```bash
51+
git clone https://github.com/opea-project/GenAIExamples.git
52+
cd GenAIExamples/ChatQnA/docker
53+
docker build --no-cache -t opea/chatqna:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f Dockerfile .
54+
cd ../../..
55+
```
56+
57+
### 8. Build UI Docker Image
58+
59+
Construct the frontend Docker image using the command below:
60+
61+
```bash
62+
cd GenAIExamples/ChatQnA/docker/ui/
63+
docker build --no-cache -t opea/chatqna-ui:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f ./docker/Dockerfile .
64+
cd ../../../..
65+
```
66+
67+
Then run the command `docker images`, you will have the following 7 Docker Images:
68+
69+
1. `opea/embedding-tei:latest`
70+
2. `opea/retriever-redis:latest`
71+
3. `opea/reranking-tei:latest`
72+
4. `opea/llm-tgi:latest`
73+
5. `opea/dataprep-redis:latest`
74+
6. `opea/chatqna:latest`
75+
7. `opea/chatqna-ui:latest`
76+
77+
## 🚀 Start MicroServices and MegaService
78+
79+
### Setup Environment Variables
80+
81+
Since the `docker_compose.yaml` will consume some environment variables, you need to setup them in advance as below.
82+
83+
```bash
84+
export no_proxy=${your_no_proxy}
85+
export http_proxy=${your_http_proxy}
86+
export https_proxy=${your_http_proxy}
87+
export EMBEDDING_MODEL_ID="BAAI/bge-base-en-v1.5"
88+
export RERANK_MODEL_ID="BAAI/bge-reranker-base"
89+
export LLM_MODEL_ID="Intel/neural-chat-7b-v3-3"
90+
export TEI_EMBEDDING_ENDPOINT="http://${host_ip}:8090"
91+
export TEI_RERANKING_ENDPOINT="http://${host_ip}:8808"
92+
export TGI_LLM_ENDPOINT="http://${host_ip}:8008"
93+
export REDIS_URL="redis://${host_ip}:6379"
94+
export INDEX_NAME="rag-redis"
95+
export HUGGINGFACEHUB_API_TOKEN=${your_hf_api_token}
96+
export MEGA_SERVICE_HOST_IP=${host_ip}
97+
export EMBEDDING_SERVICE_HOST_IP=${host_ip}
98+
export RETRIEVER_SERVICE_HOST_IP=${host_ip}
99+
export RERANK_SERVICE_HOST_IP=${host_ip}
100+
export LLM_SERVICE_HOST_IP=${host_ip}
101+
export BACKEND_SERVICE_ENDPOINT="http://${host_ip}:8888/v1/chatqna"
102+
export DATAPREP_SERVICE_ENDPOINT="http://${host_ip}:6007/v1/dataprep"
103+
```
104+
105+
Note: Please replace with `host_ip` with you external IP address, do **NOT** use localhost.
106+
107+
### Start all the services Docker Containers
108+
109+
```bash
110+
cd GenAIExamples/ChatQnA/docker/gpu/
111+
docker compose -f docker_compose.yaml up -d
112+
```
113+
114+
### Validate MicroServices and MegaService
115+
116+
1. TEI Embedding Service
117+
118+
```bash
119+
curl ${host_ip}:8090/embed \
120+
-X POST \
121+
-d '{"inputs":"What is Deep Learning?"}' \
122+
-H 'Content-Type: application/json'
123+
```
124+
125+
2. Embedding Microservice
126+
127+
```bash
128+
curl http://${host_ip}:6000/v1/embeddings \
129+
-X POST \
130+
-d '{"text":"hello"}' \
131+
-H 'Content-Type: application/json'
132+
```
133+
134+
3. Retriever Microservice
135+
136+
To consume the retriever microservice, you need to generate a mock embedding vector of length 768 in Python script:
137+
138+
```python
139+
import random
140+
141+
embedding = [random.uniform(-1, 1) for _ in range(768)]
142+
print(embedding)
143+
```
144+
145+
Then substitute your mock embedding vector for the `${your_embedding}` in the following `curl` command:
146+
147+
```bash
148+
curl http://${host_ip}:7000/v1/retrieval \
149+
-X POST \
150+
-d '{"text":"test", "embedding":${your_embedding}}' \
151+
-H 'Content-Type: application/json'
152+
```
153+
154+
4. TEI Reranking Service
155+
156+
```bash
157+
curl http://${host_ip}:8808/rerank \
158+
-X POST \
159+
-d '{"query":"What is Deep Learning?", "texts": ["Deep Learning is not...", "Deep learning is..."]}' \
160+
-H 'Content-Type: application/json'
161+
```
162+
163+
5. Reranking Microservice
164+
165+
```bash
166+
curl http://${host_ip}:8000/v1/reranking \
167+
-X POST \
168+
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \
169+
-H 'Content-Type: application/json'
170+
```
171+
172+
6. TGI Service
173+
174+
```bash
175+
curl http://${host_ip}:8008/generate \
176+
-X POST \
177+
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":64, "do_sample": true}}' \
178+
-H 'Content-Type: application/json'
179+
```
180+
181+
7. LLM Microservice
182+
183+
```bash
184+
curl http://${host_ip}:9000/v1/chat/completions \
185+
-X POST \
186+
-d '{"query":"What is Deep Learning?","max_new_tokens":17,"top_k":10,"top_p":0.95,"typical_p":0.95,"temperature":0.01,"repetition_penalty":1.03,"streaming":true}' \
187+
-H 'Content-Type: application/json'
188+
```
189+
190+
8. MegaService
191+
192+
```bash
193+
curl http://${host_ip}:8888/v1/chatqna -H "Content-Type: application/json" -d '{
194+
"messages": "What is the revenue of Nike in 2023?"
195+
}'
196+
```
197+
198+
9. Dataprep Microservice(Optional)
199+
200+
If you want to update the default knowledge base, you can use the following commands:
201+
202+
Update Knowledge Base via Local File Upload:
203+
204+
```bash
205+
curl -X POST "http://${host_ip}:6007/v1/dataprep" \
206+
-H "Content-Type: multipart/form-data" \
207+
-F "files=@./nke-10k-2023.pdf"
208+
```
209+
210+
This command updates a knowledge base by uploading a local file for processing. Update the file path according to your environment.
211+
212+
Add Knowledge Base via HTTP Links:
213+
214+
```bash
215+
curl -X POST "http://${host_ip}:6007/v1/dataprep" \
216+
-H "Content-Type: multipart/form-data" \
217+
-F 'link_list=["https://opea.dev"]'
218+
```
219+
220+
This command updates a knowledge base by submitting a list of HTTP links for processing.
221+
222+
## Enable LangSmith for Monotoring Application (Optional)
223+
224+
LangSmith offers tools to debug, evaluate, and monitor language models and intelligent agents. It can be used to assess benchmark data for each microservice. Before launching your services with `docker compose -f docker_compose.yaml up -d`, you need to enable LangSmith tracing by setting the `LANGCHAIN_TRACING_V2` environment variable to true and configuring your LangChain API key.
225+
226+
Here's how you can do it:
227+
228+
1. Install the latest version of LangSmith:
229+
230+
```bash
231+
pip install -U langsmith
232+
```
233+
234+
2. Set the necessary environment variables:
235+
236+
```bash
237+
export LANGCHAIN_TRACING_V2=true
238+
export LANGCHAIN_API_KEY=ls_...
239+
```
240+
241+
## 🚀 Launch the UI
242+
243+
To access the frontend, open the following URL in your browser: http://{host_ip}:5173. By default, the UI runs on port 5173 internally. If you prefer to use a different host port to access the frontend, you can modify the port mapping in the `docker_compose.yaml` file as shown below:
244+
245+
```yaml
246+
chaqna-ui-server:
247+
image: opea/chatqna-ui:latest
248+
...
249+
ports:
250+
- "80:5173"
251+
```
252+
253+
![project-screenshot](../../assets/img/chat_ui_init.png)

0 commit comments

Comments
 (0)