-
Notifications
You must be signed in to change notification settings - Fork 62
/
manifest_xeon_test.sh
executable file
·278 lines (253 loc) · 10.4 KB
/
manifest_xeon_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
set -xe
USER_ID=$(whoami)
LOG_PATH=/home/$(whoami)/logs
MOUNT_DIR=/home/$USER_ID/.cache/huggingface/hub
# IMAGE_REPO is $OPEA_IMAGE_REPO, or else ""
IMAGE_REPO=${OPEA_IMAGE_REPO:-""}
function init_docsum() {
# executed under path manifest/docsum/xeon
# replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT"
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt#path: $MOUNT_DIR#g" {} \;
# replace the repository "image: opea/*" with "image: ${IMAGE_REPO}opea/"
find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: \"${IMAGE_REPO}opea/#g" {} \;
# set huggingface token
find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
}
function init_codetrans() {
# executed under path manifest/codetrans/xeon
# replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT"
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt#path: $MOUNT_DIR#g" {} \;
# replace the repository "image: opea/*" with "image: ${IMAGE_REPO}opea/"
find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: \"${IMAGE_REPO}opea/#g" {} \;
# set huggingface token
find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
}
function init_codegen() {
# executed under path manifest/codegen/xeon
# replace the mount dir "path: /mnt/model" with "path: $CHART_MOUNT"
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt#path: $MOUNT_DIR#g" {} \;
# replace the repository "image: opea/*" with "image: ${IMAGE_REPO}opea/"
find . -name '*.yaml' -type f -exec sed -i "s#image: \"opea/*#image: \"${IMAGE_REPO}opea/#g" {} \;
# set huggingface token
find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
}
function install_docsum {
echo "namespace is $NAMESPACE"
find . -name 'qna_configmap_xeon.yaml' -type f -exec sed -i "s#default#${NAMESPACE}#g" {} \;
kubectl apply -f qna_configmap_xeon.yaml -n $NAMESPACE
kubectl apply -f docsum_llm.yaml -n $NAMESPACE
kubectl apply -f tgi_service.yaml -n $NAMESPACE
}
function install_codetrans {
echo "namespace is $NAMESPACE"
kubectl apply -f . -n $NAMESPACE
}
function install_codegen {
echo "namespace is $NAMESPACE"
kubectl apply -f . -n $NAMESPACE
}
function init_chatqna() {
# executed under path manifest/chatqna/xeon
# replace the mount dir "path: /mnt" with "path: $CHART_MOUNT"
find . -name '*.yaml' -type f -exec sed -i "s#path: /mnt/models#path: $MOUNT_DIR#g" {} \;
# replace the repository "image: opea/*" with "image: ${IMAGE_REPO}opea/"
find . -name '*.yaml' -type f -exec sed -i "s#image: opea/*#image: ${IMAGE_REPO}opea/#g" {} \;
# set huggingface token
find . -name '*.yaml' -type f -exec sed -i "s#insert-your-huggingface-token-here#$(cat /home/$USER_ID/.cache/huggingface/token)#g" {} \;
}
function install_chatqna {
# replace namespace "default" with real namespace
find . -name '*.yaml' -type f -exec sed -i "s#default.svc#$NAMESPACE.svc#g" {} \;
# for very yaml file in yaml_files, apply it to the k8s cluster
yaml_files=("qna_configmap_xeon" "redis-vector-db" "tei_embedding_service" "tei_reranking_service" "tgi_service" "retriever" "embedding" "reranking" "llm")
for yaml_file in ${yaml_files[@]}; do
kubectl apply -f $yaml_file.yaml -n $NAMESPACE
done
sleep 60
kubectl apply -f chaqna-xeon-backend-server.yaml -n $NAMESPACE
}
function validate_docsum() {
ip_address=$(kubectl get svc $SERVICE_NAME -n $NAMESPACE -o jsonpath='{.spec.clusterIP}')
port=$(kubectl get svc $SERVICE_NAME -n $NAMESPACE -o jsonpath='{.spec.ports[0].port}')
echo "try to curl http://${ip_address}:${port}/v1/chat/docsum..."
# Curl the DocSum LLM Service
curl http://${ip_address}:${port}/v1/chat/docsum \
-X POST \
-d '{"type", "text", "messages":"Text Embeddings Inference (TEI) is a toolkit for deploying and serving open source text embeddings and sequence classification models. TEI enables high-performance extraction for the most popular models, including FlagEmbedding, Ember, GTE and E5."}' \
-H 'Content-Type: application/json' > $LOG_PATH/curl_docsum.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "LLM for docsum failed, please check the logs in ${LOG_PATH}!"
exit 1
fi
echo "Checking response results, make sure the output is reasonable. "
local status=false
if [[ -f $LOG_PATH/curl_docsum.log ]] && \
[[ $(grep -c "TEI" $LOG_PATH/curl_docsum.log) != 0 ]]; then
status=true
fi
if [ $status == false ]; then
echo "Response check failed, please check the logs in artifacts!"
else
echo "Response check succeed!"
fi
}
function validate_codetrans() {
ip_address=$(kubectl get svc $SERVICE_NAME -n $NAMESPACE -o jsonpath='{.spec.clusterIP}')
port=$(kubectl get svc $SERVICE_NAME -n $NAMESPACE -o jsonpath='{.spec.ports[0].port}')
echo "try to curl http://${ip_address}:${port}/v1/chat/completions..."
# Curl the CodeTrans LLM Service
curl http://${ip_address}:${port}/v1/chat/completions \
-X POST \
-d '{"query":" ### System: Please translate the following Golang codes into Python codes. ### Original codes: '\'''\'''\''Golang \npackage main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n '\'''\'''\'' ### Translated codes:"}' \
-H 'Content-Type: application/json' > $LOG_PATH/curl_codetrans.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "LLM for codetrans failed, please check the logs in ${LOG_PATH}!"
exit 1
fi
echo "Checking response results, make sure the output is reasonable. "
local status=false
if [[ -f $LOG_PATH/curl_codetrans.log ]] && \
[[ $(grep -c "Hello" $LOG_PATH/curl_codetrans.log) != 0 ]]; then
status=true
fi
if [ $status == false ]; then
echo "Response check failed, please check the logs in artifacts!"
else
echo "Response check succeed!"
fi
}
function validate_codegen() {
ip_address=$(kubectl get svc $SERVICE_NAME -n $NAMESPACE -o jsonpath='{.spec.clusterIP}')
port=$(kubectl get svc $SERVICE_NAME -n $NAMESPACE -o jsonpath='{.spec.ports[0].port}')
echo "try to curl http://${ip_address}:${port}/v1/codegen..."
# Curl the Mega Service
curl http://${ip_address}:${port}/v1/codegen \
-H "Content-Type: application/json" \
-d '{"messages": "Implement a high-level API for a TODO list application. The API takes as input an operation request and updates the TODO list in place. If the request is invalid, raise an exception."}' > $LOG_PATH/curl_codegen.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Megaservice codegen failed, please check the logs in ${LOG_PATH}!"
exit 1
fi
echo "Checking response results, make sure the output is reasonable. "
local status=false
if [[ -f $LOG_PATH/curl_codegen.log ]] && \
[[ $(grep -c "print" $LOG_PATH/curl_codegen.log) != 0 ]]; then
status=true
fi
if [ $status == false ]; then
echo "Response check failed, please check the logs in artifacts!"
else
echo "Response check succeed!"
fi
}
function validate_chatqna() {
# make sure microservice retriever is ready
test_embedding=$(python3 -c "import random; embedding = [random.uniform(-1, 1) for _ in range(768)]; print(embedding)")
until curl http://retriever-svc.$NAMESPACE:7000/v1/retrieval -X POST \
-d '{"text":"What is the revenue of Nike in 2023?","embedding":"'"${test_embedding}"'"}' \
-H 'Content-Type: application/json'; do sleep 10; done
# make sure microservice tgi-svc is ready
until curl http://tgi-svc.$NAMESPACE:9009/generate -X POST \
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \
-H 'Content-Type: application/json'; do sleep 10; done
# Curl the Mega Service
curl http://chaqna-xeon-backend-server-svc.$NAMESPACE:8888/v1/chatqna -H "Content-Type: application/json" \
-d '{ "messages": "What is the revenue of Nike in 2023?" }' > $LOG_PATH/curl_chatqna.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Megaservice chatqna failed, please check the logs in ${LOG_PATH}!"
exit 1
fi
echo "Checking response results, make sure the output is reasonable. "
local status=false
if [[ -f $LOG_PATH/curl_chatqna.log ]] && \
[[ $(grep -c "billion" $LOG_PATH/curl_chatqna.log) != 0 ]]; then
status=true
fi
if [ $status == false ]; then
echo "Response check failed, please check the logs in artifacts!"
exit 1
else
echo "Response check succeed!"
fi
}
if [ $# -eq 0 ]; then
echo "Usage: $0 <function_name>"
exit 1
fi
case "$1" in
init_docsum)
cp manifests/ChatQnA/qna_configmap_xeon.yaml manifests/DocSum/xeon/
pushd manifests/DocSum/xeon
init_docsum
popd
;;
init_codetrans)
pushd manifests/CodeTrans/xeon
init_codetrans
popd
;;
init_codegen)
pushd manifests/CodeGen/xeon
init_codegen
popd
;;
init_chatqna)
pushd manifests/ChatQnA
init_chatqna
popd
;;
install_docsum)
pushd manifests/DocSum/xeon
NAMESPACE=$2
install_docsum
popd
;;
install_codetrans)
pushd manifests/CodeTrans/xeon
NAMESPACE=$2
install_codetrans
popd
;;
install_codegen)
pushd manifests/CodeGen/xeon
NAMESPACE=$2
install_codegen
popd
;;
install_chatqna)
pushd manifests/ChatQnA
NAMESPACE=$2
install_chatqna
popd
;;
validate_docsum)
NAMESPACE=$2
SERVICE_NAME=docsum-llm-uservice
# validate_docsum
;;
validate_codetrans)
NAMESPACE=$2
SERVICE_NAME=codetrans-llm-uservice
validate_codetrans
;;
validate_codegen)
NAMESPACE=$2
SERVICE_NAME=codegen
validate_codegen
;;
validate_chatqna)
NAMESPACE=$2
SERVICE_NAME=chaqna-xeon-backend-server-svc
validate_chatqna
;;
*)
echo "Unknown function: $1"
;;
esac