Skip to content

Commit bba84db

Browse files
huydhnfacebook-github-bot
authored andcommitted
Fix flaky issues on MacOS CI (buck2, libzstd) (#200)
Summary: Here are some flaky issue on MacOS CI that I have seen: * https://github.com/pytorch/executorch/actions/runs/6053110980/job/16428034274 with `dyld[68891]: Library not loaded: rpath/libzstd.1.dylib` error. This is the same issue happening on PyTorch, so I copy the fix there in the `print_cmake_info` function * Buck build fails on MacOS. I'm not sure the reason here but retry probably works: * https://github.com/pytorch/executorch/actions/runs/6029912472/job/16360557094 with `Failed to connect to buck daemon` * https://github.com/pytorch/executorch/actions/runs/6052938317/job/16427461951 with some internal errors with `write_file` Pull Request resolved: #200 Reviewed By: guangy10, dbort Differential Revision: D48926042 Pulled By: huydhn fbshipit-source-id: 6e48e670a2989c658f204c76f096cca2c9fe19e6
1 parent 770e4cc commit bba84db

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

.ci/scripts/setup-macos.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,28 @@ install_buck() {
5757
fi
5858
}
5959

60+
# This is the same rpath fix copied from PyTorch macos setup script
61+
# https://github.com/pytorch/pytorch/blob/main/.ci/pytorch/macos-common.sh
62+
print_cmake_info() {
63+
CMAKE_EXEC=$(which cmake)
64+
echo "$CMAKE_EXEC"
65+
66+
export CMAKE_EXEC
67+
# Explicitly add conda env lib folder to cmake rpath to address the flaky issue
68+
# where cmake dependencies couldn't be found. This seems to point to how conda
69+
# links $CMAKE_EXEC to its package cache when cloning a new environment
70+
install_name_tool -add_rpath @executable_path/../lib "${CMAKE_EXEC}" || true
71+
# Adding the rpath will invalidate cmake signature, so signing it again here
72+
# to trust the executable. EXC_BAD_ACCESS (SIGKILL (Code Signature Invalid))
73+
# with an exit code 137 otherwise
74+
codesign -f -s - "${CMAKE_EXEC}" || true
75+
}
76+
6077
# NB: we need buck2 in all cases because cmake build also depends on calling
6178
# buck2 atm
6279
install_buck
6380
install_conda
6481
install_pip_dependencies
82+
print_cmake_info
6583
install_executorch
6684
build_executorch_runner "${BUILD_TOOL}"

.ci/scripts/utils.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8+
reset_buck() {
9+
# On MacOS, buck2 daemon can get into a weird non-responsive state
10+
buck2 kill && buck2 clean
11+
rm -rf ~/.buck/buckd
12+
}
13+
14+
retry () {
15+
"$@" || (sleep 30 && reset_buck && "$@") || (sleep 60 && reset_buck && "$@")
16+
}
17+
818
install_executorch() {
919
which pip
1020
# Install executorch, this assumes that Executorch is checked out in the
@@ -40,8 +50,8 @@ install_pip_dependencies() {
4050
}
4151

4252
build_executorch_runner_buck2() {
43-
# Build executorch runtime
44-
buck2 build //examples/executor_runner:executor_runner
53+
# Build executorch runtime with retry as this step is flaky on macos CI
54+
retry buck2 build //examples/executor_runner:executor_runner
4555
}
4656

4757
build_executorch_runner_cmake() {
@@ -50,7 +60,9 @@ build_executorch_runner_cmake() {
5060
rm -rf "${CMAKE_OUTPUT_DIR}" && mkdir "${CMAKE_OUTPUT_DIR}"
5161

5262
pushd "${CMAKE_OUTPUT_DIR}" || return
53-
cmake -DBUCK2=buck2 -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" ..
63+
# This command uses buck2 to gather source files and buck2 could crash flakily
64+
# on MacOS
65+
retry cmake -DBUCK2=buck2 -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" ..
5466
popd || return
5567

5668
if [ "$(uname)" == "Darwin" ]; then

examples/custom_ops/test_custom_ops.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
set -e
1313

14+
# shellcheck source=/dev/null
15+
source "$(dirname "${BASH_SOURCE[0]}")/../../.ci/scripts/utils.sh"
16+
1417
test_buck2_custom_op_1() {
1518
local model_name='custom_ops_1'
1619
echo "Exporting ${model_name}.pte"
@@ -34,7 +37,7 @@ test_cmake_custom_op_1() {
3437
(rm -rf cmake-out \
3538
&& mkdir cmake-out \
3639
&& cd cmake-out \
37-
&& cmake -DBUCK2=buck2 \
40+
&& retry cmake -DBUCK2=buck2 \
3841
-DREGISTER_EXAMPLE_CUSTOM_OP=1 \
3942
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
4043

@@ -85,7 +88,7 @@ test_cmake_custom_op_2() {
8588
(rm -rf cmake-out \
8689
&& mkdir cmake-out \
8790
&& cd cmake-out \
88-
&& cmake -DBUCK2=buck2 \
91+
&& retry cmake -DBUCK2=buck2 \
8992
-DREGISTER_EXAMPLE_CUSTOM_OP=2 \
9093
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
9194
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)

examples/quantization/test_quantize.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
set -e
1111

12+
# shellcheck source=/dev/null
13+
source "$(dirname "${BASH_SOURCE[0]}")/../../.ci/scripts/utils.sh"
14+
1215
get_shared_lib_ext() {
1316
UNAME=$(uname)
1417
if [[ $UNAME == "Darwin" ]];
@@ -47,7 +50,7 @@ test_cmake_quantization() {
4750
(rm -rf cmake-out \
4851
&& mkdir cmake-out \
4952
&& cd cmake-out \
50-
&& cmake -DBUCK2=buck2 \
53+
&& retry cmake -DBUCK2=buck2 \
5154
-DREGISTER_QUANTIZED_OPS=ON \
5255
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
5356
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)

examples/selective_build/test_selective_build.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# 4. (TODO) Select from a serialized model (.pte)
1313
set -e
1414

15+
# shellcheck source=/dev/null
16+
source "$(dirname "${BASH_SOURCE[0]}")/../../.ci/scripts/utils.sh"
17+
1518
test_buck2_select_all_ops() {
1619
echo "Exporting MobilenetV3"
1720
${PYTHON_EXECUTABLE} -m examples.export.export_example --model_name="mv3"
@@ -57,7 +60,7 @@ test_cmake_select_all_ops() {
5760
(rm -rf cmake-out \
5861
&& mkdir cmake-out \
5962
&& cd cmake-out \
60-
&& cmake -DBUCK2="$BUCK" \
63+
&& retry cmake -DBUCK2="$BUCK" \
6164
-DBUILD_SELECTIVE_BUILD_TEST=ON \
6265
-DCMAKE_BUILD_TYPE=Release \
6366
-DSELECT_ALL_OPS=ON \
@@ -81,7 +84,7 @@ test_cmake_select_ops_in_list() {
8184
(rm -rf cmake-out \
8285
&& mkdir cmake-out \
8386
&& cd cmake-out \
84-
&& cmake -DBUCK2="$BUCK" \
87+
&& retry cmake -DBUCK2="$BUCK" \
8588
-DMAX_KERNEL_NUM=16 \
8689
-DBUILD_SELECTIVE_BUILD_TEST=ON \
8790
-DCMAKE_BUILD_TYPE=Release \
@@ -108,7 +111,7 @@ test_cmake_select_ops_in_yaml() {
108111
(rm -rf cmake-out \
109112
&& mkdir cmake-out \
110113
&& cd cmake-out \
111-
&& cmake -DBUCK2="$BUCK" \
114+
&& retry cmake -DBUCK2="$BUCK" \
112115
-DBUILD_SELECTIVE_BUILD_TEST=ON \
113116
-DCMAKE_BUILD_TYPE=Release \
114117
-DSELECT_OPS_YAML=ON \

0 commit comments

Comments
 (0)