Refine CodeTrans Test Scripts (#239)

Signed-off-by: letonghan <letong.han@intel.com>
This commit is contained in:
Letong Han
2024-05-31 18:09:23 +08:00
committed by GitHub
parent b012161eb3
commit 6ebfea1f10
3 changed files with 96 additions and 70 deletions

View File

@@ -7,7 +7,7 @@ version: "3.8"
services:
tgi_service:
image: ghcr.io/huggingface/text-generation-inference:1.4
container_name: tgi-service
container_name: codetrans-tgi-service
ports:
- "8008:80"
volumes:

View File

@@ -45,55 +45,60 @@ function start_services() {
sleep 2m # Waits 2 minutes
}
function validate_microservices() {
# Check if the microservices are running correctly.
# TODO: Any results check required??
curl http://${ip_address}:8008/generate \
-X POST \
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \
-H 'Content-Type: application/json' > ${LOG_PATH}/generate.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Microservice failed, please check the logs in artifacts!"
docker logs tgi-gaudi-server >> ${LOG_PATH}/generate.log
exit 1
fi
sleep 5s
function validate_services() {
local URL="$1"
local EXPECTED_RESULT="$2"
local SERVICE_NAME="$3"
local DOCKER_NAME="$4"
local INPUT_DATA="$5"
curl http://${ip_address}:9000/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}/completions.log
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Microservice failed, please check the logs in artifacts!"
docker logs llm-tgi-gaudi-server >> ${LOG_PATH}/completions.log
local HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL")
if [ "$HTTP_STATUS" -eq 200 ]; then
echo "[ $SERVICE_NAME ] HTTP status is 200. Checking content..."
local CONTENT=$(curl -s -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL" | tee ${LOG_PATH}/${SERVICE_NAME}.log)
if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then
echo "[ $SERVICE_NAME ] Content is as expected."
else
echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT"
docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log
exit 1
fi
else
echo "[ $SERVICE_NAME ] HTTP status is not 200. Received status was $HTTP_STATUS"
docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log
exit 1
fi
sleep 5s
}
function validate_microservices() {
# tgi for embedding service
validate_services \
"${ip_address}:8008/generate" \
"generated_text" \
"tgi" \
"codetrans-tgi-service" \
'{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}'
# llm microservice
validate_services \
"${ip_address}:9000/v1/chat/completions" \
"data: " \
"llm" \
"llm-tgi-gaudi-server" \
'{"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:"}'
}
function validate_megaservice() {
# Curl the Mega Service
curl http://${ip_address}:7777/v1/codetrans -H "Content-Type: application/json" -d '{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}' > ${LOG_PATH}/curl_megaservice.log
echo "Checking response results, make sure the output is reasonable. "
local status=false
if [[ -f $LOG_PATH/curl_megaservice.log ]] && \
[[ $(grep -c "@#\$print" $LOG_PATH/curl_megaservice.log) != 0 ]]; then
status=true
fi
if [ $status == false ]; then
echo "Response check failed, please check the logs in artifacts!"
docker logs codetrans-gaudi-backend-server >> ${LOG_PATH}/curl_megaservice.log
exit 1
else
echo "Response check succeed!"
fi
echo "Checking response format, make sure the output format is acceptable for UI."
# TODO
validate_services \
"${ip_address}:7777/v1/codetrans" \
"print" \
"mega-codetrans" \
"codetrans-gaudi-backend-server" \
'{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}'
}
function stop_docker() {

View File

@@ -42,40 +42,61 @@ function start_services() {
sleep 2m
}
function validate_microservices() {
curl http://${ip_address}:8008/generate \
-X POST \
-d '{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}' \
-H 'Content-Type: application/json' > ${LOG_PATH}/generate.log
sleep 5s
function validate_services() {
local URL="$1"
local EXPECTED_RESULT="$2"
local SERVICE_NAME="$3"
local DOCKER_NAME="$4"
local INPUT_DATA="$5"
curl http://${ip_address}:9000/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}/completions.log
local HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL")
if [ "$HTTP_STATUS" -eq 200 ]; then
echo "[ $SERVICE_NAME ] HTTP status is 200. Checking content..."
local CONTENT=$(curl -s -X POST -d "$INPUT_DATA" -H 'Content-Type: application/json' "$URL" | tee ${LOG_PATH}/${SERVICE_NAME}.log)
if echo "$CONTENT" | grep -q "$EXPECTED_RESULT"; then
echo "[ $SERVICE_NAME ] Content is as expected."
else
echo "[ $SERVICE_NAME ] Content does not match the expected result: $CONTENT"
docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log
exit 1
fi
else
echo "[ $SERVICE_NAME ] HTTP status is not 200. Received status was $HTTP_STATUS"
docker logs ${DOCKER_NAME} >> ${LOG_PATH}/${SERVICE_NAME}.log
exit 1
fi
sleep 5s
}
function validate_microservices() {
# tgi for embedding service
validate_services \
"${ip_address}:8008/generate" \
"generated_text" \
"tgi" \
"codetrans-tgi-service" \
'{"inputs":"What is Deep Learning?","parameters":{"max_new_tokens":17, "do_sample": true}}'
# llm microservice
validate_services \
"${ip_address}:9000/v1/chat/completions" \
"data: " \
"llm" \
"llm-tgi-server" \
'{"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:"}'
}
function validate_megaservice() {
# Curl the Mega Service
curl http://${ip_address}:7777/v1/codetrans -H "Content-Type: application/json" -d '{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}' > ${LOG_PATH}/curl_megaservice.log
echo "Checking response results, make sure the output is reasonable. "
local status=false
if [[ -f $LOG_PATH/curl_megaservice.log ]] && \
[[ $(grep -c "@#$print" $LOG_PATH/curl_megaservice.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
echo "Checking response format, make sure the output format is acceptable for UI."
# TODO
validate_services \
"${ip_address}:7777/v1/codetrans" \
"print" \
"mega-codetrans" \
"codetrans-xeon-backend-server" \
'{"language_from": "Golang","language_to": "Python","source_code": "package main\n\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello, World!\");\n}"}'
}