Repository: alibaba/BladeDISC (language: python)

Issue:
Add Tensorflow-Blade
In the past weeks, we have open-source some of the cpp and python code for tensorflow-blade, which optimize the tensorflow model for inference. The first stage of tensorflow blade open source is done when the following actions are complete:

- [x] cpp code and related tests merged: [pr](https://github.com/alibaba/BladeDISC/pull/171)
- [x] python code and related tests merged: [pr](https://github.com/alibaba/BladeDISC/pull/189)
- [x] complete ci pipeline with develop docker: [pr](https://github.com/alibaba/BladeDISC/pull/191)
- [x] tutorial for users to use tensorflow-blade
- [ ] docs for design of tensorflow-blade
- [x] docs for make contribution to tensorflow-blade


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/cpu_reusable.yml b/.github/workflows/cpu_reusable.yml
index 7a2b8d77435..70aa8b6244c 100644
--- a/.github/workflows/cpu_reusable.yml
+++ b/.github/workflows/cpu_reusable.yml
@@ -48,7 +48,7 @@ jobs:
           --build-arg DISC_HOST_TF_VERSION="tensorflow==1.15.5" \
           --build-arg DEVICE=cpu \
           -f docker/dev/Dockerfile .
-    - name: Build And Test DISC
+    - name: Build And Test
       run: |
         set -e
         docker run --rm -t --user $(id -u):$(id -g) \
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 5fed1135ebd..06545a9894c 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -106,7 +106,7 @@ jobs:
           -v $PWD:/disc \
           -e GITHUB_WORKFLOW=$GITHUB_WORKFLOW \
           -w /disc \
-          disc-dev-cuda11.0 bash ./scripts/ci/test_tensorflow_blade.sh
+          disc-dev-cuda11.0 bash ./scripts/ci/test_tensorflow_blade.sh cu110 2.4
     - name: Deploy Docker
       if: github.event.ref == 'refs/heads/main'
       env:
@@ -219,8 +219,9 @@ jobs:
     with:
       remote_runtime_docker: bladedisc:latest-runtime-tensorflow1.15-cpu
       runtime_base_image: tensorflow/tensorflow:1.15.5
-      exec_command: bash ./scripts/ci/build_and_test.sh --cpu-only
-      deploy_command: bash ./scripts/ci/deploy_tf_wrapper.sh
+      exec_command: bash -c \
+          "bash ./scripts/ci/build_and_test.sh --cpu-only && bash ./scripts/ci/test_tensorflow_blade.sh cpu 1.15"
+      deploy_command: bash ./scripts/ci/deploy_tensorflow_blade.sh
     secrets:
       ALIYUN_DOCKER_USERNAME: ${{ secrets.ALIYUN_DOCKER_USERNAME }}
       ALIYUN_DOCKER_PASSWORD: ${{ secrets.ALIYUN_DOCKER_PASSWORD }}
diff --git a/tensorflow_blade/requirement-tf1.15-cpu.txt b/tensorflow_blade/requirement-tf1.15-cpu.txt
new file mode 100644
index 00000000000..d58cf6ca705
--- /dev/null
+++ b/tensorflow_blade/requirement-tf1.15-cpu.txt
@@ -0,0 +1,9 @@
+tensorflow==1.15.0
+black==19.10b0
+flake8==3.9.2
+flake8-isort==4.0.0
+isort==5.8.0
+mypy==0.782
+py-cpuinfo==8.0.0
+six~=1.15.0
+tf2onnx==1.9.1
diff --git a/third_party/bazel/cuda_supplement/cuda_supplement_configure.bzl b/third_party/bazel/cuda_supplement/cuda_supplement_configure.bzl
index 63d1e703893..bc5d202156c 100644
--- a/third_party/bazel/cuda_supplement/cuda_supplement_configure.bzl
+++ b/third_party/bazel/cuda_supplement/cuda_supplement_configure.bzl
@@ -6,6 +6,7 @@ def _create_dummy_repository(repo_ctx):
     repo_ctx.symlink(Label("//bazel/cuda_supplement:dummy.BUILD.tpl"), "BUILD")
     repo_ctx.template("build_defs.bzl", Label("//bazel/cuda_supplement:build_defs.bzl.tpl"), {
         "%{IF_HAS_CUBLASLT}": "False",
+        "%{IF_HAS_CUDNN_STATIC}": "False",
     })
 
 


Test patch:
diff --git a/scripts/ci/test_tensorflow_blade.sh b/scripts/ci/test_tensorflow_blade.sh
index 3caa7b95060..c51e6c48810 100644
--- a/scripts/ci/test_tensorflow_blade.sh
+++ b/scripts/ci/test_tensorflow_blade.sh
@@ -14,6 +14,14 @@
 set -ex
 SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
 
+if [[ $# -ne 2 ]]; then
+    echo "Usage: $0 <device> <tf_version>"
+    exit -1
+fi
+
+device=$1
+tf_ver=$2
+
 # RuntimeError: Click will abort further execution because Python was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/unicode-support/ for mitigation steps.
 # This system supports the C.UTF-8 locale which is recommended. You might be able to resolve your issue by exporting the following environment variables:
 export LC_ALL=C.UTF-8
@@ -23,13 +31,21 @@ VENV_PATH=venv
 # note(yancey.yx): using virtualenv to avoid permission issue on workflow actions CI,
 python -m virtualenv ${VENV_PATH} && source ${VENV_PATH}/bin/activate
 
-(cd tensorflow_blade \
-  && python -m pip install -q -r requirement-tf2.4-cu110.txt \
-  && ./build.py -s configure \
-  && ./build.py -s check \
-  && ./build.py -s build \
-  && ./build.py -s test \
-  && ./build.py -s package)
+pushd tensorflow_blade
+
+require_txt="requirement-tf${tf_ver}-${device}.txt"
+[[ ! -f ${require_txt} ]] && echo "requirement-tf${tf_ver}-${device}.txt not found" && exit -1
+python -m pip install -q -r ${require_txt}
+
+device_type="gpu"
+[[ ${device} == "cpu" ]] && device_type="cpu"
+
+./build.py -s configure --device ${device_type}
+./build.py -s check
+./build.py -s build
+./build.py -s test
+./build.py -s package
+popd
 
 mkdir -p build && \
 mv tensorflow_blade/dist/tensorflow_blade*.whl ./build