Skip to content

OneFlow Serving

OneFlow Serving #483

Workflow file for this run

name: OneFlow Serving
on:
pull_request:
types: [review_requested]
branches:
- "*"
release:
types:
- published
schedule:
- cron: "0 18 * * *"
workflow_dispatch:
inputs:
tag:
description: "Docker image tag"
required: true
type: string
env:
TRITON_VERSION: "21.10"
SERVING_IMAGE: "oneflow-serving"
MANYLINUX_CACHE_DIR: ~/manylinux-cache-dir/triton-cu114
REGION_ID: cn-beijing
REGISTRY: registry.cn-beijing.aliyuncs.com
NAMESPACE: oneflow
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
cancel_previous:
name: Cancel previous runs
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event.pull_request.draft == false && github.base_ref == 'main' && contains(github.event.pull_request.requested_reviewers.*.login, 'oneflow-ci-bot'))
steps:
- name: Cancel previous runs of outdated commit
if: github.ref != 'refs/heads/main'
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
build_test:
name: Build oneflow and backend
runs-on: [self-hosted, linux, provision]
needs: [cancel_previous]
if: github.event_name == 'release' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event.pull_request.draft == false && github.base_ref == 'main' && contains(github.event.pull_request.requested_reviewers.*.login, 'oneflow-ci-bot'))
outputs:
image_tag: ${{ steps.output-step.outputs.image_tag }}
acr_image_tag: ${{ steps.output-step.outputs.acr_image_tag }}
steps:
- name: Fix permissions
run: |
docker run --rm -v $PWD:/p -w /p busybox chmod -R o+w .
- uses: actions/checkout@v2
- name: Clone oneflow
run: |
git clone https://github.com/Oneflow-Inc/oneflow --depth=1
- name: Set environment variables
run: |
set -x
extra_docker_args=""
manylinux_cache_dir=${{ env.MANYLINUX_CACHE_DIR }}
container_name=serving-build-run-id-${{ github.run_id }}-${{ github.run_number }}-test
extra_docker_args+=" --runtime=nvidia"
extra_docker_args+=" --detach"
extra_docker_args+=" --name ${container_name}"
extra_docker_args+=" --shm-size=8g --rm -w $PWD -v $PWD:$PWD"
extra_docker_args+=" -v $manylinux_cache_dir:$manylinux_cache_dir"
extra_docker_args+=" --network=host"
extra_docker_args+=" -e HTTPS_PROXY -e HTTP_PROXY"
extra_docker_args+=" --env TRITON_VERSION=${{ env.TRITON_VERSION }}"
extra_docker_args+=" --env ONEFLOW_CI_SRC_DIR=$PWD/oneflow"
extra_docker_args+=" --env ONEFLOW_CI_BUILD_DIR=$manylinux_cache_dir/build"
extra_docker_args+=" --env ONEFLOW_CI_BUILD_SCRIPT=$PWD/ci/build/build-gcc7.sh"
extra_docker_args+=" --env WHEELHOUSE_DIR=$manylinux_cache_dir/wheelhouse"
extra_docker_args+=" --env ONEFLOW_CI_CMAKE_INIT_CACHE=$PWD/cmake/ci/oneflow-cuda.cmake"
extra_docker_args+=" --env ONEFLOW_CI_PYTHON_EXE=python3"
echo "extra_docker_args=${extra_docker_args}" >> $GITHUB_ENV
echo "container_name=${container_name}" >> $GITHUB_ENV
echo "image_tag=registry.cn-beijing.aliyuncs.com/oneflow/triton-devel:latest" >> $GITHUB_ENV
- name: Build oneflow and oneflow backend for triton
run: |
docker run --rm -v $PWD:/p -w /p busybox chmod -R o+w .
docker run --rm -v ${{ env.MANYLINUX_CACHE_DIR }}:/p -w /p busybox chmod -R o+w .
docker pull ${{ env.image_tag }}
docker container rm -f ${{ env.container_name }} || true
docker run $extra_docker_args ${{ env.image_tag }} sleep 3600
docker exec ${{ env.container_name }} python3 -m pip install -r ci/build/requirement.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
docker exec -w $PWD ${{ env.container_name }} /bin/bash ci/build/oneflow.sh
docker exec -w $PWD ${{ env.container_name }} /bin/bash ci/build/backend.sh
- name: Prepare for test
run: |
set -x
manylinux_cache_dir=${{ env.MANYLINUX_CACHE_DIR }}
docker exec -w $PWD/test/common ${{ env.container_name }} bash -c "source $manylinux_cache_dir/build/ci_source.sh && python3 export_model.py"
- name: Remove container
run: |
docker container rm -f ${{ env.container_name }}
- name: Set environment variables
run: |
set -x
extra_docker_args=""
container_name=user-image-run-id-${{ github.run_id }}-${{ github.run_number }}-test
extra_docker_args+=" --runtime=nvidia"
extra_docker_args+=" --detach"
extra_docker_args+=" --name ${container_name}"
extra_docker_args+=" --shm-size=8g --rm -w $PWD -v $PWD:$PWD"
echo "extra_docker_args=${extra_docker_args}" >> $GITHUB_ENV
echo "container_name=${container_name}" >> $GITHUB_ENV
echo "image_tag=${{ env.SERVING_IMAGE }}" >> $GITHUB_ENV
echo "triton_version=${{ env.TRITON_VERSION }}" >> $GITHUB_ENV
- name: Export docker image name
run: |
set -x
if [[ "${{ github.event_name }}" == "release" ]]
then
echo "image_tag=${{ env.SERVING_IMAGE }}:${{ github.ref_name }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]
then
echo "image_tag=${{ env.SERVING_IMAGE }}:${{ github.event.inputs.tag }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "schedule" ]]
then
echo "image_tag=${{ env.SERVING_IMAGE }}:nightly" >> $GITHUB_ENV
else
echo "image_tag=${{ env.SERVING_IMAGE }}:run-id-${{ github.run_id }}" >> $GITHUB_ENV
fi
- name: Export ACR docker image name
run: |
echo "acr_image_tag=${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.image_tag }}" >> $GITHUB_ENV
- name: Make user docker image
run: |
echo ${{ env.image_tag }}
mkdir -p context
cp ci/build/oneflow_serving_triton_entrypoint.sh context/
cp ci/build/oneflow-serving.py context/oneflow-serving
cp -r ${{ env.MANYLINUX_CACHE_DIR }}/build/liboneflow_cpp/ context/
cp build/libtriton_oneflow.so context/
docker build -f docker/Dockerfile context/ --build-arg TRITON_CONTAINER_VERSION=${{ env.triton_version }} -t ${{ env.image_tag }}
- name: Test
run: |
docker container rm -f ${{ env.container_name }} || true
docker run $extra_docker_args ${{ env.image_tag }} sleep 3600
docker exec -w $(pwd) ${{ env.container_name }} pip3 install -r ./ci/test/requirement.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
docker exec -w $(pwd) ${{ env.container_name }} bash ./ci/test/run_tests.sh
- name: Login to ACR with the AccessKey pair
uses: aliyun/acr-login@v1
with:
login-server: https://registry.${{ env.REGION_ID }}.aliyuncs.com
username: "${{ secrets.ACR_USERNAME }}"
password: "${{ secrets.ACR_PASSWORD }}"
- name: Docker push to ACR
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
run: |
docker tag ${{ env.image_tag }} ${{ env.acr_image_tag }}
docker push ${{ env.acr_image_tag }}
- name: Remove container
run: docker container rm -f ${{ env.container_name }}
- name: Remove image
run: |
set -x
[ -z "${{ env.image_tag }}" ] && exit 0
if [[ "$(docker images -q ${{ env.image_tag }} 2> /dev/null)" != "" ]]; then
docker rmi ${{ env.image_tag }}
fi
[ -z "${{ env.acr_image_tag }}" ] && exit 0
if [[ "$(docker images -q ${{ env.acr_image_tag }} 2> /dev/null)" != "" ]]; then
docker rmi ${{ env.acr_image_tag }}
fi
- name: Output environment variables
id: output-step
run: |
echo "::set-output name=image_tag::${{ env.image_tag }}"
echo "::set-output name=acr_image_tag::${{ env.acr_image_tag }}"
docker_push:
name: Push to docker hub
runs-on: ubuntu-latest
needs: [build_test]
if: github.event_name == 'release'|| github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
steps:
- name: Set environment variables
run: |
echo "image_tag=oneflowinc/${{ needs.build_test.outputs.image_tag }}" >> $GITHUB_ENV
echo "acr_image_tag=${{ needs.build_test.outputs.acr_image_tag }}" >> $GITHUB_ENV
- name: Output environment variables
run: |
echo ${{ env.acr_image_tag }}
echo ${{ env.image_tag }}
- name: Login to ACR with the AccessKey pair
uses: aliyun/acr-login@v1
with:
login-server: https://registry.${{ env.REGION_ID }}.aliyuncs.com
username: "${{ secrets.ACR_USERNAME }}"
password: "${{ secrets.ACR_PASSWORD }}"
- name: Login to docker hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Pull, tag and push
run: |
docker pull ${{ env.acr_image_tag }}
docker tag ${{ env.acr_image_tag }} ${{ env.image_tag }}
docker push ${{ env.image_tag }}
- name: Pull, tag and push
run: |
docker pull ${{ env.acr_image_tag }}
docker tag ${{ env.acr_image_tag }} ${{ env.image_tag }}
docker push ${{ env.image_tag }}
- name: Push latest
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
run: |
docker tag ${{ env.acr_image_tag }} oneflowinc/${{ env.SERVING_IMAGE }}:latest
docker push oneflowinc/${{ env.SERVING_IMAGE }}:latest