Skip to content

Commit e6fb290

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Add custom ops test to CI job (#72)
Summary: Pull Request resolved: #72 Add it to pull.yml for both linux and macos Reviewed By: huydhn, JacobSzwejbka Differential Revision: D48408763 fbshipit-source-id: 14721c6e1a8b88a532eb062b54132397236857a4
1 parent d85b2ad commit e6fb290

File tree

3 files changed

+77
-18
lines changed

3 files changed

+77
-18
lines changed

.github/workflows/pull.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
bash .ci/scripts/test.sh
3232
3333
# Test custom ops
34-
bash examples/custom_ops/test_custom_ops.sh
34+
bash examples/custom_ops/test_custom_ops.sh buck2
3535
3636
buck-build-test-macos:
3737
name: buck-build-test-macos
@@ -49,6 +49,9 @@ jobs:
4949
5050
# Build and test Executorch
5151
bash .ci/scripts/test.sh
52+
53+
# Test custom ops
54+
bash examples/custom_ops/test_custom_ops.sh buck2
5255
popd
5356
5457
cmake-build-test-linux:
@@ -68,3 +71,24 @@ jobs:
6871
6972
# Build and test Executorch
7073
bash .ci/scripts/test-cmake.sh
74+
75+
# Build and test custom ops
76+
bash examples/custom_ops/test_custom_ops.sh cmake
77+
78+
cmake-build-test-macos:
79+
name: cmake-build-test-macos
80+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
81+
with:
82+
runner: macos-m1-12
83+
submodules: 'true'
84+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
85+
script: |
86+
WORKSPACE=$(pwd)
87+
88+
pushd "${WORKSPACE}/pytorch/executorch"
89+
# Setup MacOS dependencies as there is no Docker support on MacOS atm
90+
bash .ci/scripts/setup-macos.sh
91+
92+
# Build and test custom ops
93+
bash examples/custom_ops/test_custom_ops.sh cmake
94+
popd

examples/custom_ops/test_custom_ops.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set -e
1414
test_buck2_custom_op_1() {
1515
local model_name='custom_ops_1'
1616
echo "Exporting ${model_name}.pte"
17-
python3 -m "examples.custom_ops.${model_name}"
17+
python -m "examples.custom_ops.${model_name}"
1818
# should save file custom_ops_1.pte
1919

2020
echo 'Running executor_runner'
@@ -29,7 +29,7 @@ test_buck2_custom_op_1() {
2929
test_cmake_custom_op_1() {
3030
local model_name='custom_ops_1'
3131
echo "Exporting ${model_name}.pte"
32-
python3 -m "examples.custom_ops.${model_name}"
32+
python -m "examples.custom_ops.${model_name}"
3333
# should save file custom_ops_1.pte
3434
(rm -rf cmake-out \
3535
&& mkdir cmake-out \
@@ -50,7 +50,7 @@ test_buck2_custom_op_2() {
5050
SO_LIB=$(buck2 build //examples/custom_ops:custom_ops_aot_lib_2 --show-output | grep "buck-out" | cut -d" " -f2)
5151

5252
echo "Exporting ${model_name}.pte"
53-
python3 -m "examples.custom_ops.${model_name}" --so_library="$SO_LIB"
53+
python -m "examples.custom_ops.${model_name}" --so_library="$SO_LIB"
5454
# should save file custom_ops_2.pte
5555

5656
buck2 run //examples/executor_runner:executor_runner \
@@ -92,14 +92,24 @@ test_cmake_custom_op_2() {
9292

9393
EXT=$(get_shared_lib_ext)
9494
echo "Exporting ${model_name}.pte"
95-
python3 -m "examples.custom_ops.${model_name}" --so_library="cmake-out/examples/custom_ops/libcustom_ops_aot_lib$EXT"
95+
python -m "examples.custom_ops.${model_name}" --so_library="cmake-out/examples/custom_ops/libcustom_ops_aot_lib$EXT"
9696
# should save file custom_ops_2.pte
9797

9898
echo 'Running executor_runner'
9999
cmake-out/executor_runner "--model_path=./${model_name}.pte"
100100
}
101101

102-
test_buck2_custom_op_1
103-
test_cmake_custom_op_1
104-
test_buck2_custom_op_2
105-
test_cmake_custom_op_2
102+
if [[ $1 == "cmake" ]];
103+
then
104+
test_cmake_custom_op_1
105+
test_cmake_custom_op_2
106+
elif [[ $1 == "buck2" ]];
107+
then
108+
test_buck2_custom_op_1
109+
test_buck2_custom_op_2
110+
else
111+
test_cmake_custom_op_1
112+
test_cmake_custom_op_2
113+
test_buck2_custom_op_1
114+
test_buck2_custom_op_2
115+
fi

third-party/link_torch.sh

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,39 @@
1111

1212
set -e
1313

14-
LIB=$(python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')
14+
# Named argument:
15+
# -o: output directory/file
16+
# -f: a list of files/directories that we want to link to the output directory, separated by comma ",".
17+
# These paths need to be in relative path format to the python library path.
18+
while getopts ":o:f:" opt; do
19+
case $opt in
20+
o) OUT="$OPTARG"
21+
;;
22+
f) FILES="$OPTARG"
23+
;;
24+
\?) echo "Invalid option -$OPTARG" >&2
25+
exit 1
26+
;;
27+
esac
1528

16-
SUBPATH=$1
17-
OUT=$2
18-
if [[ -f "$LIB/$SUBPATH" ]] || [[ -d "$LIB/$SUBPATH" ]];
19-
then
20-
ln -s "$LIB/$SUBPATH" "$OUT"
21-
else
22-
echo "Error: $LIB/$SUBPATH doesn't exist"
29+
case $OPTARG in
30+
-*) echo "Option $opt needs to be one of -o, -f."
2331
exit 1
24-
fi
32+
;;
33+
esac
34+
done
35+
36+
LIB=$(python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')
37+
38+
# delimiter ,
39+
export IFS=","
40+
41+
for SUBPATH in $FILES; do
42+
if [[ -f "$LIB/$SUBPATH" ]] || [[ -d "$LIB/$SUBPATH" ]];
43+
then
44+
ln -s "$LIB/$SUBPATH" "$OUT"
45+
else
46+
echo "Error: $LIB/$SUBPATH doesn't exist"
47+
exit 1
48+
fi
49+
done

0 commit comments

Comments
 (0)