diff --git a/.github/workflows/CodeGen.yml b/.github/workflows/CodeGen.yml new file mode 100644 index 000000000..11df5376a --- /dev/null +++ b/.github/workflows/CodeGen.yml @@ -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 diff --git a/.github/workflows/DocSum.yml b/.github/workflows/DocSum.yml new file mode 100644 index 000000000..e4b2e0bcc --- /dev/null +++ b/.github/workflows/DocSum.yml @@ -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 diff --git a/ChatQnA/tests/test_langchain_inference.sh b/ChatQnA/tests/test_langchain_inference.sh index 4e05e90fe..515a680d0 100644 --- a/ChatQnA/tests/test_langchain_inference.sh +++ b/ChatQnA/tests/test_langchain_inference.sh @@ -103,7 +103,7 @@ 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 @@ -111,7 +111,7 @@ function main() { 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 diff --git a/CodeGen/serving/tgi_gaudi/launch_tgi_service.sh b/CodeGen/serving/tgi_gaudi/launch_tgi_service.sh index 12dfa59e4..5836c31a1 100644 --- a/CodeGen/serving/tgi_gaudi/launch_tgi_service.sh +++ b/CodeGen/serving/tgi_gaudi/launch_tgi_service.sh @@ -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 diff --git a/CodeGen/tests/test_codegen_inference.sh b/CodeGen/tests/test_codegen_inference.sh new file mode 100644 index 000000000..af52db38c --- /dev/null +++ b/CodeGen/tests/test_codegen_inference.sh @@ -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 diff --git a/DocSum/langchain/docker/build_docker.sh b/DocSum/langchain/docker/build_docker.sh index 57363b2ff..8af836674 100755 --- a/DocSum/langchain/docker/build_docker.sh +++ b/DocSum/langchain/docker/build_docker.sh @@ -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 diff --git a/DocSum/serving/tgi_gaudi/launch_tgi_service.sh b/DocSum/serving/tgi_gaudi/launch_tgi_service.sh index 7bab7a6e8..25c785c4d 100644 --- a/DocSum/serving/tgi_gaudi/launch_tgi_service.sh +++ b/DocSum/serving/tgi_gaudi/launch_tgi_service.sh @@ -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 diff --git a/DocSum/tests/test_langchain_inference.sh b/DocSum/tests/test_langchain_inference.sh new file mode 100644 index 000000000..905d90b93 --- /dev/null +++ b/DocSum/tests/test_langchain_inference.sh @@ -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