Skip to content

Commit

Permalink
[ci] Try to support paddle
Browse files Browse the repository at this point in the history
  • Loading branch information
0xzhang committed Apr 29, 2022
1 parent e0b2674 commit bc60143
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 21 deletions.
30 changes: 22 additions & 8 deletions .github/workflows/scripts/unix_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ python3 -m pip install dist/*.whl
if [ -z "$GPU_TEST" ]; then
python3 -m pip install -r requirements_test.txt
python3 -m pip install "torch; python_version < '3.10'"
if [[ $PLATFORM == *"linux"* ]]; then
python3 -m pip install "paddlepaddle==0.0.0; python_version < '3.10'" -f https://www.paddlepaddle.org.cn/whl/linux/cpu-mkl/develop.html
fi
else
## Only GPU machine uses system python.
export PATH=$PATH:$HOME/.local/bin
# pip will skip packages if already installed
python3 -m pip install -r requirements_test.txt
if [[ $PLATFORM == *"linux"* ]]; then
python3 -m pip install "paddlepaddle-gpu==0.0.0.post112; python_version < '3.10'" -f https://www.paddlepaddle.org.cn/whl/linux/gpu/develop.html
fi
fi
ti diagnose
ti changelog
Expand All @@ -38,27 +44,35 @@ TI_LIB_DIR="$TI_PATH/_lib/runtime" ./build/taichi_cpp_tests
if [ -z "$GPU_TEST" ]; then
if [[ $PLATFORM == *"m1"* ]]; then
# Split per arch to avoid flaky test
python3 tests/run_tests.py -vr2 -t4 -k "not torch" -a cpu
python3 tests/run_tests.py -vr2 -t4 -k "not torch and not paddle" -a cpu
# Run metal and vulkan separately so that they don't use M1 chip simultaneously.
python3 tests/run_tests.py -vr2 -t4 -k "not torch" -a vulkan
python3 tests/run_tests.py -vr2 -t2 -k "not torch" -a metal
python3 tests/run_tests.py -vr2 -t4 -k "not torch and not paddle" -a vulkan
python3 tests/run_tests.py -vr2 -t2 -k "not torch and not paddle" -a metal
python3 tests/run_tests.py -vr2 -t1 -k "torch" -a "$TI_WANTED_ARCHS"
# Paddle's paddle.fluid.core.Tensor._ptr() is only available on develop branch
# Not support Apple M1 and no GPU version on MAC
else
python3 tests/run_tests.py -vr2 -t4 -a "$TI_WANTED_ARCHS"
python3 tests/run_tests.py -vr2 -t4 -k "not paddle" -a "$TI_WANTED_ARCHS"
if [[ $PLATFORM == *"linux"* ]]; then
python3 tests/run_tests.py -vr2 -t4 -k "paddle" -a "$TI_WANTED_ARCHS"
fi
fi
else
# Split per arch to increase parallelism for linux GPU tests
if [[ $TI_WANTED_ARCHS == *"cuda"* ]]; then
python3 tests/run_tests.py -vr2 -t4 -k "not torch" -a cuda
python3 tests/run_tests.py -vr2 -t4 -k "not torch and not paddle" -a cuda
fi
if [[ $TI_WANTED_ARCHS == *"cpu"* ]]; then
python3 tests/run_tests.py -vr2 -t8 -k "not torch" -a cpu
python3 tests/run_tests.py -vr2 -t8 -k "not torch and not paddle" -a cpu
fi
if [[ $TI_WANTED_ARCHS == *"vulkan"* ]]; then
python3 tests/run_tests.py -vr2 -t8 -k "not torch" -a vulkan
python3 tests/run_tests.py -vr2 -t8 -k "not torch and not paddle" -a vulkan
fi
if [[ $TI_WANTED_ARCHS == *"opengl"* ]]; then
python3 tests/run_tests.py -vr2 -t4 -k "not torch" -a opengl
python3 tests/run_tests.py -vr2 -t4 -k "not torch and not paddle" -a opengl
fi
python3 tests/run_tests.py -vr2 -t1 -k "torch" -a "$TI_WANTED_ARCHS"
if [[ $PLATFORM == *"linux"* ]]; then
python3 tests/run_tests.py -vr2 -t1 -k "paddle" -a "$TI_WANTED_ARCHS"
fi
fi
9 changes: 6 additions & 3 deletions .github/workflows/scripts/win_test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ pip install -r requirements_test.txt
# TODO relax this when torch supports 3.10
if ("$env:TI_WANTED_ARCHS".Contains("cuda")) {
pip install "torch==1.10.1+cu113; python_version < '3.10'" -f https://download.pytorch.org/whl/cu113/torch_stable.html
pip install paddlepaddle-gpu==0.0.0.post112 -f https://www.paddlepaddle.org.cn/whl/windows/gpu/develop.html
} else {
pip install "torch; python_version < '3.10'"
pip install paddlepaddle==0.0.0 -f https://www.paddlepaddle.org.cn/whl/windows/cpu-mkl-avx/develop.html
}
if ("$env:TI_WANTED_ARCHS".Contains("cuda")) {
python tests/run_tests.py -vr2 -t4 -k "not torch" -a cuda
python tests/run_tests.py -vr2 -t4 -k "not torch and not paddle" -a cuda
if (-not $?) { exit 1 }
}
if ("$env:TI_WANTED_ARCHS".Contains("cpu")) {
python tests/run_tests.py -vr2 -t6 -k "not torch" -a cpu
python tests/run_tests.py -vr2 -t6 -k "not torch and not paddle" -a cpu
if (-not $?) { exit 1 }
}
if ("$env:TI_WANTED_ARCHS".Contains("opengl")) {
python tests/run_tests.py -vr2 -t4 -k "not torch" -a opengl
python tests/run_tests.py -vr2 -t4 -k "not torch and not paddle" -a opengl
if (-not $?) { exit 1 }
}
python tests/run_tests.py -vr2 -t2 -k "torch" -a "$env:TI_WANTED_ARCHS"
python tests/run_tests.py -vr2 -t2 -k "paddle" -a "$env:TI_WANTED_ARCHS"
if (-not $?) { exit 1 }
6 changes: 4 additions & 2 deletions ci/scripts/ubuntu_build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ git checkout $SHA
python3 -m pip install -r requirements_dev.txt -i http://repo.taichigraphics.com/repository/pypi/simple --trusted-host repo.taichigraphics.com
# Update Torch version, otherwise cuda tests fail. See #2969.
python3 -m pip install torch==1.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html -i http://repo.taichigraphics.com/repository/pypi/simple --trusted-host repo.taichigraphics.com
# Paddle's paddle.fluid.core.Tensor._ptr() is only available on PaddlePaddle's develop branch
python3 -m pip install paddlepaddle-gpu==0.0.0.post112 -f https://www.paddlepaddle.org.cn/whl/linux/gpu/develop.html
TAICHI_CMAKE_ARGS="-DTI_WITH_VULKAN:BOOL=ON -DTI_WITH_CUDA:BOOL=ON -DTI_WITH_OPENGL:BOOL=ON" python3 setup.py install

# Add Docker specific ENV
export TI_IN_DOCKER=true

# Run tests
ti diagnose
python tests/run_tests.py -vr2 -t2 -k "not ndarray and not torch"
python tests/run_tests.py -vr2 -t1 -k "ndarray or torch"
python tests/run_tests.py -vr2 -t2 -k "not ndarray and not torch and not paddle"
python tests/run_tests.py -vr2 -t1 -k "ndarray or torch or paddle"
6 changes: 4 additions & 2 deletions ci/scripts/ubuntu_build_test_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ git clone --recursive https://github.com/taichi-dev/taichi --branch=master
cd taichi
git checkout $SHA
python3 -m pip install -r requirements_dev.txt -i http://repo.taichigraphics.com/repository/pypi/simple --trusted-host repo.taichigraphics.com
# Paddle's paddle.fluid.core.Tensor._ptr() is only available on PaddlePaddle's develop branch
python3 -m pip install paddlepaddle==0.0.0 -f https://www.paddlepaddle.org.cn/whl/linux/cpu-mkl/develop.html
TAICHI_CMAKE_ARGS="-DTI_WITH_VULKAN:BOOL=OFF -DTI_WITH_CUDA:BOOL=OFF -DTI_WITH_OPENGL:BOOL=OFF" python3 setup.py install

# Add Docker specific ENV
export TI_IN_DOCKER=true

# Run tests
ti diagnose
python tests/run_tests.py -vr2 -t2 -k "not ndarray and not torch"
python tests/run_tests.py -vr2 -t1 -k "ndarray or torch"
python tests/run_tests.py -vr2 -t2 -k "not ndarray and not torch and not paddle"
python tests/run_tests.py -vr2 -t1 -k "ndarray or torch or paddle"
2 changes: 1 addition & 1 deletion ci/windows/win_build_test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ python setup.py develop
WriteInfo("Build finished")

WriteInfo("Testing Taichi")
python tests/run_tests.py -vr2 -t2 -k "not torch" -a cpu
python tests/run_tests.py -vr2 -t2 -k "not torch and not paddle" -a cpu
WriteInfo("Test finished")
5 changes: 2 additions & 3 deletions python/taichi/lang/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,8 @@ def to_paddle(self, device=None):
import paddle # pylint: disable=C0415

# pylint: disable=E1101
arr = paddle.zeros(size=self.shape,
dtype=to_paddle_type(self.dtype),
device=device)
arr = paddle.zeros(shape=self.shape,
dtype=to_paddle_type(self.dtype))
from taichi._kernels import tensor_to_ext_arr # pylint: disable=C0415
tensor_to_ext_arr(self, arr)
taichi.lang.runtime_ops.sync()
Expand Down
2 changes: 1 addition & 1 deletion python/taichi/lang/kernel_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def func__(*args):
actual_argument_slot, int(tmp.data_ptr()),
tmp.element_size() * tmp.nelement(), v.shape)
else:
# For now, paddle.fluid.core.Tensor._ptr() is only available on PaddlePaddle's develop branch
# For now, paddle.fluid.core.Tensor._ptr() is only available on develop branch
tmp, paddle_callbacks = self.get_paddle_callbacks(
v, has_pp)
callbacks += paddle_callbacks
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_get_external_tensor_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_get_external_tensor_shape_access_paddle(size):
def func(x: ti.types.ndarray(), index: ti.template()) -> ti.i32:
return x.shape[index]

x_hat = paddle.ones(size, dtype=paddle.int32, device=paddle.CPUPlace())
x_hat = paddle.ones([size], dtype=paddle.int32)
for idx, y_ref in enumerate(size):
y_hat = func(x_hat, idx)
assert y_ref == y_hat, "Size of axis {} should equal {} and not {}.".format(
Expand Down

0 comments on commit bc60143

Please sign in to comment.