Skip to content

Commit

Permalink
Support iree ci (#8419)
Browse files Browse the repository at this point in the history
* create mlir cpu and modify build gcc 7 shell script

* fix the bug of test_iree_resnet.py cuda test in cpu version error

* fix constant folding tests

* suport oneflow_test_cpu_only

* pub

* build script add flag

* modify test yml

* add python3 into \PATH

* don't use pretrain model

* install flowvision

Co-authored-by: mosout <mosout@qq.com>
Co-authored-by: jackalcooper <jackalcooper@gmail.com>
  • Loading branch information
3 people authored Jun 16, 2022
1 parent 357ef40 commit f6c3cb6
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,14 @@ jobs:
run: |
echo "::error file=test.yml,line=204,col=10::steps.save-cache.outputs.cache-hit != matrix.cache-hit"
exit 1
- uses: Oneflow-Inc/get-oneflow@support-cuda-1106
- uses: Oneflow-Inc/get-oneflow@support-iree-ci
name: Build manylinux ${{ matrix.entry }}
id: build-cpu
if: ${{ matrix.entry =='cpu' && !matrix.cache-hit }}
with:
cmake-init-cache: ${{ env.ONEFLOW_SRC }}/cmake/caches/ci/cpu.cmake
build-script: ${{ env.ONEFLOW_SRC }}/ci/manylinux/build.sh
run-lit: true
oneflow-src: ${{ env.ONEFLOW_SRC }}
oneflow-build-env: manylinux
wheelhouse-dir: ${{ env.WHEELHOUSE_DIR }}
Expand Down
5 changes: 5 additions & 0 deletions ci/manylinux/build-gcc7.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ cmake -S ${ONEFLOW_CI_SRC_DIR} -C ${ONEFLOW_CI_CMAKE_INIT_CACHE} -DPython3_EXECU
# cmake build
cd ${ONEFLOW_CI_BUILD_DIR}
cmake --build . --parallel ${ONEFLOW_CI_BUILD_PARALLEL}
if [ ! -z "$ONEFLOW_CI_BUILD_RUN_LIT" ]; then
${ONEFLOW_CI_PYTHON_EXE} -m pip install -i https://mirrors.aliyun.com/pypi/simple --user flowvision==0.1.0
export PATH=$PATH:$(dirname $ONEFLOW_CI_PYTHON_EXE)
cmake --build . -t c1
fi

# build pip
cd ${ONEFLOW_CI_SRC_DIR}
Expand Down
5 changes: 5 additions & 0 deletions ci/manylinux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ cmake -S ${ONEFLOW_CI_SRC_DIR} -C ${ONEFLOW_CI_CMAKE_INIT_CACHE} -DPython3_EXECU
# cmake build
cd ${ONEFLOW_CI_BUILD_DIR}
cmake --build . --parallel ${ONEFLOW_CI_BUILD_PARALLEL}
if [ ! -z "$ONEFLOW_CI_BUILD_RUN_LIT" ]; then
${ONEFLOW_CI_PYTHON_EXE} -m pip install -i https://mirrors.aliyun.com/pypi/simple --user flowvision==0.1.0
export PATH=$PATH:$(dirname $ONEFLOW_CI_PYTHON_EXE)
cmake --build . -t c1
fi

# build pip
cd ${ONEFLOW_CI_SRC_DIR}
Expand Down
24 changes: 24 additions & 0 deletions cmake/caches/cn/fast/mlir-cpu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set(BUILD_SHARED_LIBS YES CACHE BOOL "")
# uncomment only if you know what you are doing
# set(CMAKE_LINK_DEPENDS_NO_SHARED YES CACHE BOOL "")
set(BUILD_CUDA NO CACHE BOOL "")
set(BUILD_GIT_VERSION NO CACHE BOOL "")
set(TREAT_WARNINGS_AS_ERRORS YES CACHE BOOL "")
set(BUILD_HWLOC NO CACHE BOOL "")
set(BUILD_TESTING OFF CACHE BOOL "")
set(WITH_MLIR YES CACHE BOOL "")
set(WITH_MLIR_CUDA_CODEGEN NO CACHE BOOL "")
set(THIRD_PARTY_MIRROR aliyun CACHE STRING "")
set(PIP_INDEX_MIRROR "https://pypi.tuna.tsinghua.edu.cn/simple" CACHE STRING "")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
set(CMAKE_GENERATOR Ninja CACHE STRING "")
set(CMAKE_C_COMPILER_LAUNCHER ccache CACHE STRING "")
set(CMAKE_CXX_COMPILER_LAUNCHER ccache CACHE STRING "")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF CACHE BOOL "")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld" CACHE STRING "")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=lld" CACHE STRING "")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld" CACHE STRING "")
set(CPU_THREADING_RUNTIME SEQ CACHE STRING
"when using lld with TBB enabled, there will be linkage error")
set(BUILD_HWLOC OFF CACHE BOOL "")
set(WITH_ONEDNN OFF CACHE BOOL "")
1 change: 1 addition & 0 deletions oneflow/ir/test/Frontend/test_iree_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class TestIreeResnet(oneflow.unittest.TestCase):
def test_iree_resnet_cpu(test_case):
_test_iree_resnet_cpu(test_case)

@unittest.skipUnless(oneflow.sysconfig.with_cuda(), "only test cpu cases")
def test_iree_resnet_cuda(test_case):
_test_iree_resnet_cuda(test_case)

Expand Down
4 changes: 2 additions & 2 deletions oneflow/ir/test/OneFlow/folding/test_conv_bn.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
def _test_fuse_conv_bn(test_case):
data = flow.randn(1, 3, 224, 224)

model = resnet50(pretrained=True, progress=True)
model = resnet50(pretrained=False, progress=True)
model.eval()
eager_res = model(data)

Expand All @@ -47,7 +47,7 @@ def build(self, *input):
lazy_res = graph(data)

test_case.assertTrue(
np.allclose(eager_res.numpy(), lazy_res.numpy(), rtol=1e-5, atol=1e-5)
np.allclose(eager_res.numpy(), lazy_res.numpy(), rtol=1e-4, atol=1e-4)
)


Expand Down
12 changes: 10 additions & 2 deletions oneflow/ir/test/OneFlow/folding/test_simple_multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,27 @@ def build(self, *args):
class TestFoldMultiply(oneflow.unittest.TestCase):
def test_fold_multiply(test_case):
_test_fold_multiply(test_case, MultiplyModel, with_cuda=False)

@unittest.skipUnless(oneflow.sysconfig.with_cuda(), "only test cpu cases")
def test_fold_multiply_cuda(test_case):
_test_fold_multiply(test_case, MultiplyModel, with_cuda=True)

def test_fold_multiply_complex(test_case):
_test_fold_multiply(test_case, MultiplyModelComplex, with_cuda=False)

@unittest.skipUnless(oneflow.sysconfig.with_cuda(), "only test cpu cases")
def test_fold_multiply_complex_cuda(test_case):
_test_fold_multiply(test_case, MultiplyModelComplex, with_cuda=True)

def test_fold_multiply_with_input(test_case):
a = flow.tensor([3, 7], dtype=flow.float32)
b = flow.tensor([9, -1], dtype=flow.float32)
_test_fold_multiply(test_case, MultiplyModelWithInput, False, a, b)

a = a.to("cuda")
b = b.to("cuda")
@unittest.skipUnless(oneflow.sysconfig.with_cuda(), "only test cpu cases")
def test_fold_multiply_with_input_cuda(test_case):
a = flow.tensor([3, 7], dtype=flow.float32, device="cuda")
b = flow.tensor([9, -1], dtype=flow.float32, device="cuda")
_test_fold_multiply(test_case, MultiplyModelWithInput, True, a, b)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
os.environ["ONEFLOW_MLIR_ENABLE_INFERENCE_OPTIMIZATION"] = "1"


def _test_fuse_conv_bn(test_case):
data = flow.randn(1, 3, 224, 224).to("cuda")

model = resnet50(pretrained=True, progress=True)
model.to("cuda")
def _test_fuse_conv_bn(test_case, with_cuda):
data = flow.randn(1, 3, 224, 224)
if with_cuda:
data = data.to("cuda")

model = resnet50(pretrained=False, progress=True)
if with_cuda:
model.to("cuda")
model.eval()
eager_res = model(data)

Expand All @@ -49,14 +52,15 @@ def build(self, *input):
lazy_res = graph(data)

test_case.assertTrue(
np.allclose(eager_res.numpy(), lazy_res.numpy(), rtol=1e-5, atol=1e-5)
np.allclose(eager_res.numpy(), lazy_res.numpy(), rtol=1e-4, atol=1e-4)
)


@flow.unittest.skip_unless_1n1d()
class TestFuseConvBn(oneflow.unittest.TestCase):
def test_fuse_conv_bn(test_case):
_test_fuse_conv_bn(test_case)
@unittest.skipUnless(oneflow.sysconfig.with_cuda(), "only test cpu cases")
def test_fuse_conv_bn_cuda(test_case):
_test_fuse_conv_bn(test_case, True)


if __name__ == "__main__":
Expand Down

0 comments on commit f6c3cb6

Please sign in to comment.