Skip to content

Commit 5f4b182

Browse files
Added UT for rerank finetuning on Gaudi (#1472)
Signed-off-by: Ye, Xinyu <xinyu.ye@intel.com>
1 parent 39abef8 commit 5f4b182

File tree

3 files changed

+154
-2
lines changed

3 files changed

+154
-2
lines changed

RerankFinetuning/docker_image_build/build.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ services:
1111
context: GenAIComps
1212
dockerfile: comps/finetuning/src/Dockerfile
1313
image: ${REGISTRY:-opea}/finetuning:${TAG:-latest}
14+
finetuning-gaudi:
15+
build:
16+
args:
17+
http_proxy: ${http_proxy}
18+
https_proxy: ${https_proxy}
19+
no_proxy: ${no_proxy}
20+
context: GenAIComps
21+
dockerfile: comps/finetuning/src/Dockerfile.intel_hpu
22+
image: ${REGISTRY:-opea}/finetuning-gaudi:${TAG:-latest}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
set -x
5+
IMAGE_REPO=${IMAGE_REPO:-"opea"}
6+
IMAGE_TAG=${IMAGE_TAG:-"latest"}
7+
echo "REGISTRY=IMAGE_REPO=${IMAGE_REPO}"
8+
echo "TAG=IMAGE_TAG=${IMAGE_TAG}"
9+
export REGISTRY=${IMAGE_REPO}
10+
export TAG=${IMAGE_TAG}
11+
12+
WORKPATH=$(dirname "$PWD")
13+
LOG_PATH="$WORKPATH/tests"
14+
ip_address=$(hostname -I | awk '{print $1}')
15+
finetuning_service_port=8015
16+
ray_port=8265
17+
service_name=finetuning-gaudi
18+
19+
function build_docker_images() {
20+
cd $WORKPATH/docker_image_build
21+
if [ ! -d "GenAIComps" ] ; then
22+
git clone --depth 1 --branch ${opea_branch:-"main"} https://github.com/opea-project/GenAIComps.git
23+
fi
24+
docker compose -f build.yaml build ${service_name} --no-cache > ${LOG_PATH}/docker_image_build.log
25+
}
26+
27+
function start_service() {
28+
export no_proxy="localhost,127.0.0.1,"${ip_address}
29+
docker run -d --name="finetuning-server" -p $finetuning_service_port:$finetuning_service_port -p $ray_port:$ray_port --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy ${IMAGE_REPO}/finetuning-gaudi:${IMAGE_TAG}
30+
sleep 1m
31+
}
32+
33+
function validate_microservice() {
34+
cd $LOG_PATH
35+
export no_proxy="localhost,127.0.0.1,"${ip_address}
36+
37+
# test /v1/dataprep upload file
38+
URL="http://${ip_address}:$finetuning_service_port/v1/files"
39+
cat <<EOF > test_data.json
40+
{"query": "Five women walk along a beach wearing flip-flops.", "pos": ["Some women with flip-flops on, are walking along the beach"], "neg": ["The 4 women are sitting on the beach.", "There was a reform in 1996.", "She's not going to court to clear her record.", "The man is talking about hawaii.", "A woman is standing outside.", "The battle was over. ", "A group of people plays volleyball."]}
41+
{"query": "A woman standing on a high cliff on one leg looking over a river.", "pos": ["A woman is standing on a cliff."], "neg": ["A woman sits on a chair.", "George Bush told the Republicans there was no way he would let them even consider this foolish idea, against his top advisors advice.", "The family was falling apart.", "no one showed up to the meeting", "A boy is sitting outside playing in the sand.", "Ended as soon as I received the wire.", "A child is reading in her bedroom."]}
42+
{"query": "Two woman are playing instruments; one a clarinet, the other a violin.", "pos": ["Some people are playing a tune."], "neg": ["Two women are playing a guitar and drums.", "A man is skiing down a mountain.", "The fatal dose was not taken when the murderer thought it would be.", "Person on bike", "The girl is standing, leaning against the archway.", "A group of women watch soap operas.", "No matter how old people get they never forget. "]}
43+
{"query": "A girl with a blue tank top sitting watching three dogs.", "pos": ["A girl is wearing blue."], "neg": ["A girl is with three cats.", "The people are watching a funeral procession.", "The child is wearing black.", "Financing is an issue for us in public schools.", "Kids at a pool.", "It is calming to be assaulted.", "I face a serious problem at eighteen years old. "]}
44+
{"query": "A yellow dog running along a forest path.", "pos": ["a dog is running"], "neg": ["a cat is running", "Steele did not keep her original story.", "The rule discourages people to pay their child support.", "A man in a vest sits in a car.", "Person in black clothing, with white bandanna and sunglasses waits at a bus stop.", "Neither the Globe or Mail had comments on the current state of Canada's road system. ", "The Spring Creek facility is old and outdated."]}
45+
{"query": "It sets out essential activities in each phase along with critical factors related to those activities.", "pos": ["Critical factors for essential activities are set out."], "neg": ["It lays out critical activities but makes no provision for critical factors related to those activities.", "People are assembled in protest.", "The state would prefer for you to do that.", "A girl sits beside a boy.", "Two males are performing.", "Nobody is jumping", "Conrad was being plotted against, to be hit on the head."]}
46+
EOF
47+
HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X POST -F 'file=@./test_data.json' -F purpose="fine-tune" -H 'Content-Type: multipart/form-data' "$URL")
48+
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
49+
RESPONSE_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
50+
SERVICE_NAME="finetuning-server - upload - file"
51+
52+
# Parse the JSON response
53+
purpose=$(echo "$RESPONSE_BODY" | jq -r '.purpose')
54+
filename=$(echo "$RESPONSE_BODY" | jq -r '.filename')
55+
56+
# Define expected values
57+
expected_purpose="fine-tune"
58+
expected_filename="test_data.json"
59+
60+
if [ "$HTTP_STATUS" -ne "200" ]; then
61+
echo "[ $SERVICE_NAME ] HTTP status is not 200. Received status was $HTTP_STATUS"
62+
docker logs finetuning-server >> ${LOG_PATH}/finetuning-server_upload_file.log
63+
exit 1
64+
else
65+
echo "[ $SERVICE_NAME ] HTTP status is 200. Checking content..."
66+
fi
67+
# Check if the parsed values match the expected values
68+
if [[ "$purpose" != "$expected_purpose" || "$filename" != "$expected_filename" ]]; then
69+
echo "[ $SERVICE_NAME ] Content does not match the expected result: $RESPONSE_BODY"
70+
docker logs finetuning-server >> ${LOG_PATH}/finetuning-server_upload_file.log
71+
exit 1
72+
else
73+
echo "[ $SERVICE_NAME ] Content is as expected."
74+
fi
75+
76+
# test /v1/fine_tuning/jobs
77+
URL="http://${ip_address}:$finetuning_service_port/v1/fine_tuning/jobs"
78+
HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X POST -H 'Content-Type: application/json' -d '{"training_file": "test_data.json","model": "BAAI/bge-reranker-base","General":{"task":"rerank","lora_config":null}}' "$URL")
79+
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
80+
RESPONSE_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
81+
SERVICE_NAME="finetuning-server - create finetuning job"
82+
83+
if [ "$HTTP_STATUS" -ne "200" ]; then
84+
echo "[ $SERVICE_NAME ] HTTP status is not 200. Received status was $HTTP_STATUS"
85+
docker logs finetuning-server >> ${LOG_PATH}/finetuning-server_create.log
86+
exit 1
87+
else
88+
echo "[ $SERVICE_NAME ] HTTP status is 200. Checking content..."
89+
fi
90+
if [[ "$RESPONSE_BODY" != *'{"id":"ft-job'* ]]; then
91+
echo "[ $SERVICE_NAME ] Content does not match the expected result: $RESPONSE_BODY"
92+
docker logs finetuning-server >> ${LOG_PATH}/finetuning-server_create.log
93+
exit 1
94+
else
95+
echo "[ $SERVICE_NAME ] Content is as expected."
96+
fi
97+
98+
sleep 3m
99+
100+
docker logs finetuning-server 2>&1 | tee ${LOG_PATH}/finetuning-server_create.log
101+
FINETUNING_LOG=$(grep "succeeded" ${LOG_PATH}/finetuning-server_create.log)
102+
if [[ "$FINETUNING_LOG" != *'succeeded'* ]]; then
103+
echo "Finetuning failed."
104+
RAY_JOBID=$(grep "Submitted Ray job" ${LOG_PATH}/finetuning-server_create.log | sed 's/.*raysubmit/raysubmit/' | cut -d' ' -f 1)
105+
docker exec finetuning-server python -c "import os;os.environ['RAY_ADDRESS']='http://localhost:8265';from ray.job_submission import JobSubmissionClient;client = JobSubmissionClient();print(client.get_job_logs('${RAY_JOBID}'))" 2>&1 | tee ${LOG_PATH}/finetuning.log
106+
exit 1
107+
else
108+
echo "Finetuning succeeded."
109+
fi
110+
}
111+
112+
function stop_docker() {
113+
cid=$(docker ps -aq --filter "name=finetuning-server*")
114+
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi
115+
}
116+
117+
function main() {
118+
119+
stop_docker
120+
121+
build_docker_images
122+
start_service
123+
124+
validate_microservice
125+
126+
stop_docker
127+
echo y | docker system prune
128+
129+
}
130+
131+
main

RerankFinetuning/tests/test_compose_on_xeon.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ LOG_PATH="$WORKPATH/tests"
1414
ip_address=$(hostname -I | awk '{print $1}')
1515
finetuning_service_port=8015
1616
ray_port=8265
17+
service_name=finetuning
1718

1819
function build_docker_images() {
1920
cd $WORKPATH/docker_image_build
2021
if [ ! -d "GenAIComps" ] ; then
2122
git clone --depth 1 --branch ${opea_branch:-"main"} https://github.com/opea-project/GenAIComps.git
2223
fi
23-
docker compose -f build.yaml build --no-cache > ${LOG_PATH}/docker_image_build.log
24+
docker compose -f build.yaml build ${service_name} --no-cache > ${LOG_PATH}/docker_image_build.log
2425
}
2526

2627
function start_service() {
@@ -94,7 +95,18 @@ EOF
9495
echo "[ $SERVICE_NAME ] Content is as expected."
9596
fi
9697

97-
sleep 1s
98+
sleep 3m
99+
100+
docker logs finetuning-server 2>&1 | tee ${LOG_PATH}/finetuning-server_create.log
101+
FINETUNING_LOG=$(grep "succeeded" ${LOG_PATH}/finetuning-server_create.log)
102+
if [[ "$FINETUNING_LOG" != *'succeeded'* ]]; then
103+
echo "Finetuning failed."
104+
RAY_JOBID=$(grep "Submitted Ray job" ${LOG_PATH}/finetuning-server_create.log | sed 's/.*raysubmit/raysubmit/' | cut -d' ' -f 1)
105+
docker exec finetuning-server python -c "import os;os.environ['RAY_ADDRESS']='http://localhost:8265';from ray.job_submission import JobSubmissionClient;client = JobSubmissionClient();print(client.get_job_logs('${RAY_JOBID}'))" 2>&1 | tee ${LOG_PATH}/finetuning.log
106+
exit 1
107+
else
108+
echo "Finetuning succeeded."
109+
fi
98110
}
99111

100112
function stop_docker() {

0 commit comments

Comments
 (0)