Skip to content

Commit

Permalink
Add codegen and docsum CI (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Sun, Xuehao <[email protected]>
Co-authored-by: chensuyue <[email protected]>
  • Loading branch information
XuehaoSun and chensuyue authored Apr 8, 2024
1 parent ef1ef8c commit a96b4f2
Show file tree
Hide file tree
Showing 8 changed files with 327 additions and 7 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/CodeGen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CodeGen-test

on:
pull_request:
branches: [main]
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- CodeGen/**
- .github/workflows/CodeGen.yml
workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
CodeGen:
runs-on: gaudi2
strategy:
matrix:
job_name: ["codegen"]
fail-fast: false
steps:
- name: Clean Up Working Directory
run: sudo rm -rf ${{github.workspace}}/*

- name: Checkout out Repo
uses: actions/checkout@v4

- name: Run Test
env:
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
run: |
cd ${{ github.workspace }}/CodeGen/tests
bash test_${{ matrix.job_name }}_inference.sh
- name: Publish pipeline artifact
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.job_name }}
path: ${{ github.workspace }}/CodeGen/tests/*.log
43 changes: 43 additions & 0 deletions .github/workflows/DocSum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: DocSum-test

on:
pull_request:
branches: [main]
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- DocSum/**
- .github/workflows/DocSum.yml
workflow_dispatch:

# If there is a new commit, the previous jobs will be canceled
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
DocSum:
runs-on: gaudi2
strategy:
matrix:
job_name: ["langchain"]
fail-fast: false
steps:
- name: Clean Up Working Directory
run: sudo rm -rf ${{github.workspace}}/*

- name: Checkout out Repo
uses: actions/checkout@v4

- name: Run Test
env:
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
run: |
cd ${{ github.workspace }}/DocSum/tests
bash test_${{ matrix.job_name }}_inference.sh
- name: Publish pipeline artifact
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.job_name }}
path: ${{ github.workspace }}/DocSum/tests/*.log
4 changes: 2 additions & 2 deletions ChatQnA/tests/test_langchain_inference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ function docker_stop() {
function main() {
test_env_setup
rename
docker_stop $CHATQNA_CONTAINER_NAME && docker_stop $LANGCHAIN_CONTAINER_NAME && docker_stop $REDIS_CONTAINER_NAME
docker_stop $CHATQNA_CONTAINER_NAME && docker_stop $LANGCHAIN_CONTAINER_NAME && docker_stop $REDIS_CONTAINER_NAME && sleep 5s

launch_tgi_gaudi_service
launch_redis_and_langchain_service
start_backend_service

run_tests

docker_stop $CHATQNA_CONTAINER_NAME && docker_stop $LANGCHAIN_CONTAINER_NAME && docker_stop $REDIS_CONTAINER_NAME
docker_stop $CHATQNA_CONTAINER_NAME && docker_stop $LANGCHAIN_CONTAINER_NAME && docker_stop $REDIS_CONTAINER_NAME && sleep 5s
echo y | docker system prune

check_response
Expand Down
4 changes: 2 additions & 2 deletions CodeGen/serving/tgi_gaudi/launch_tgi_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ volume=$PWD/data

# Build the Docker run command based on the number of cards
if [ "$num_cards" -eq 1 ]; then
docker_cmd="docker run -p $port_number:80 -v $volume:/data --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:1.2.1 --model-id $model_name"
docker_cmd="docker run -d --name="CodeGen_server" -p $port_number:80 -v $volume:/data --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:1.2.1 --model-id $model_name"
else
docker_cmd="docker run -p $port_number:80 -v $volume:/data --runtime=habana -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:1.2.1 --model-id $model_name --sharded true --num-shard $num_cards"
docker_cmd="docker run -d --name="CodeGen_server" -p $port_number:80 -v $volume:/data --runtime=habana -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:1.2.1 --model-id $model_name --sharded true --num-shard $num_cards"
fi

# Execute the Docker run command
Expand Down
113 changes: 113 additions & 0 deletions CodeGen/tests/test_codegen_inference.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -xe

function test_env_setup() {
WORKPATH=$(dirname "$PWD")
LOG_PATH="$WORKPATH/tests/codegen.log"

COPILOT_CONTAINER_NAME="test-copilot"
CODEGEN_CONTAINER_NAME="test-CodeGen_server"
cd $WORKPATH # go to CodeGen
}

function rename() {
# Rename the container names
cd ${WORKPATH}
sed -i "s/CodeGen_server/${CODEGEN_CONTAINER_NAME}/g" serving/tgi_gaudi/launch_tgi_service.sh
}

function docker_setup() {
local card_num=1
local port=8902
local model_name="m-a-p/OpenCodeInterpreter-DS-6.7B"

cd ${WORKPATH}

# Reset the tgi port
sed -i "s/8080/$port/g" codegen/codegen-app/server.py

docker pull ghcr.io/huggingface/tgi-gaudi:1.2.1
bash serving/tgi_gaudi/launch_tgi_service.sh $card_num $port $model_name
sleep 3m # Waits 3 minutes
}

function launch_copilot_docker() {
local port=8903
sed -i "s/port=8000/port=$port/g" codegen/codegen-app/server.py

cd $WORKPATH/codegen
bash ./build_docker.sh

cd $WORKPATH
docker run -dit --name=$COPILOT_CONTAINER_NAME \
--net=host --ipc=host \
-v /var/run/docker.sock:/var/run/docker.sock intel/gen-ai-examples:copilot /bin/bash
}

function launch_server() {
cd $WORKPATH

# Start the Backend Service
docker exec $COPILOT_CONTAINER_NAME \
bash -c "export HUGGINGFACEHUB_API_TOKEN=$HUGGINGFACEHUB_API_TOKEN;nohup python server.py &"
sleep 1m
}

function run_tests() {
cd $WORKPATH
local port=8903
}

function check_response() {
cd $WORKPATH
echo "Checking response"
local status=false
if [[ $(grep -c "\$51.2 billion" $LOG_PATH) != 0 ]]; then
status=true
fi

if [ $status == false ]; then
echo "Response check failed"
exit 1
else
echo "Response check succeed"
fi
}

function docker_stop() {
local container_name=$1
cid=$(docker ps -aq --filter "name=$container_name")
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
}

function main() {
test_env_setup
rename
docker_stop $CODEGEN_CONTAINER_NAME && docker_stop $COPILOT_CONTAINER_NAME && sleep 5s

docker_setup
launch_copilot_docker
launch_server

run_tests

docker_stop $CODEGEN_CONTAINER_NAME && docker_stop $COPILOT_CONTAINER_NAME && sleep 5s
echo y | docker system prune

check_response
}

main
2 changes: 1 addition & 1 deletion DocSum/langchain/docker/build_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# limitations under the License.


docker build . -t document-summarize:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy
docker build . -t intel/gen-ai-examples:document-summarize --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy
4 changes: 2 additions & 2 deletions DocSum/serving/tgi_gaudi/launch_tgi_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ volume=$PWD/data

# Build the Docker run command based on the number of cards
if [ "$num_cards" -eq 1 ]; then
docker_cmd="docker run -p $port_number:80 -v $volume:/data --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:1.2.1 --model-id $model_name"
docker_cmd="docker run -d --name="DocSum_server" -p $port_number:80 -v $volume:/data --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:1.2.1 --model-id $model_name"
else
docker_cmd="docker run -p $port_number:80 -v $volume:/data --runtime=habana -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:1.2.1 --model-id $model_name --sharded true --num-shard $num_cards"
docker_cmd="docker run -d --name="DocSum_server" -p $port_number:80 -v $volume:/data --runtime=habana -e PT_HPU_ENABLE_LAZY_COLLECTIVES=true -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e HTTPS_PROXY=$https_proxy -e HTTP_PROXY=$https_proxy ghcr.io/huggingface/tgi-gaudi:1.2.1 --model-id $model_name --sharded true --num-shard $num_cards"
fi

# Execute the Docker run command
Expand Down
121 changes: 121 additions & 0 deletions DocSum/tests/test_langchain_inference.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/bin/bash
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -xe

function test_env_setup() {
WORKPATH=$(dirname "$PWD")
LOG_PATH="$WORKPATH/tests/langchain.log"

DOCUMENT_SUMMARY_CONTAINER_NAME="test-document-summary"
DOCSUM_CONTAINER_NAME="test-DocSum_server"
cd $WORKPATH # go to DocSum
}

function rename() {
# Rename the container names
cd ${WORKPATH}
sed -i "s/DocSum_server/${DOCSUM_CONTAINER_NAME}/g" serving/tgi_gaudi/launch_tgi_service.sh
}

function docker_setup() {
local card_num=1
local port=8900
local model_name="Intel/neural-chat-7b-v3-3"

cd ${WORKPATH}

# Reset the tgi port
sed -i "s/8080/$port/g" langchain/docker/summarize-app/app/server.py
sed -i "s/8080/$port/g" langchain/docker/summarize-app/Dockerfile

docker pull ghcr.io/huggingface/tgi-gaudi:1.2.1
bash serving/tgi_gaudi/launch_tgi_service.sh $card_num $port $model_name
sleep 3m # Waits 3 minutes
}

function launch_document_summary_docker() {
local port=8901
sed -i "s/port=8000/port=$port/g" langchain/docker/summarize-app/app/server.py

cd $WORKPATH/langchain/docker/
bash ./build_docker.sh

cd $WORKPATH
docker run -dit --net=host --ipc=host \
--name=$DOCUMENT_SUMMARY_CONTAINER_NAME \
-v /var/run/docker.sock:/var/run/docker.sock intel/gen-ai-examples:document-summarize /bin/bash
}

function launch_server() {
cd $WORKPATH

# Start the Backend Service
docker exec $DOCUMENT_SUMMARY_CONTAINER_NAME \
bash -c "export HUGGINGFACEHUB_API_TOKEN=$HUGGINGFACEHUB_API_TOKEN;nohup python app/server.py &"
sleep 1m
}

function run_tests() {
cd $WORKPATH
local port=8901

status_code=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:$port/v1/text_summarize \
-X POST \
-H 'Content-Type: application/json' \
-d '{"text":"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."}') || true

sleep 5s
}

function check_response() {
cd $WORKPATH
echo "Checking response"
local status=false
if [ "$status_code" -eq 200 ]; then
status=true
fi

if [ $status == false ]; then
echo "Response check failed"
exit 1
else
echo "Response check succeed"
fi
}

function docker_stop() {
local container_name=$1
cid=$(docker ps -aq --filter "name=$container_name")
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid; fi
}

function main() {
test_env_setup
rename
docker_stop $DOCSUM_CONTAINER_NAME && docker_stop $DOCUMENT_SUMMARY_CONTAINER_NAME && sleep 5s

docker_setup
launch_document_summary_docker
launch_server

run_tests

docker_stop $DOCSUM_CONTAINER_NAME && docker_stop $DOCUMENT_SUMMARY_CONTAINER_NAME && sleep 5s
echo y | docker system prune

check_response
}

main

0 comments on commit a96b4f2

Please sign in to comment.