Skip to content

Add custom ops test to CI job #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
bash .ci/scripts/test.sh

# Test custom ops
bash examples/custom_ops/test_custom_ops.sh
bash examples/custom_ops/test_custom_ops.sh buck2

buck-build-test-macos:
name: buck-build-test-macos
Expand All @@ -49,6 +49,9 @@ jobs:

# Build and test Executorch
bash .ci/scripts/test.sh

# Test custom ops
bash examples/custom_ops/test_custom_ops.sh buck2
popd

cmake-build-test-linux:
Expand All @@ -68,3 +71,24 @@ jobs:

# Build and test Executorch
bash .ci/scripts/test-cmake.sh

# Build and test custom ops
bash examples/custom_ops/test_custom_ops.sh cmake

cmake-build-test-macos:
name: cmake-build-test-macos
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
with:
runner: macos-m1-12
submodules: 'true'
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
script: |
WORKSPACE=$(pwd)

pushd "${WORKSPACE}/pytorch/executorch"
# Setup MacOS dependencies as there is no Docker support on MacOS atm
bash .ci/scripts/setup-macos.sh

# Build and test custom ops
bash examples/custom_ops/test_custom_ops.sh cmake
popd
26 changes: 18 additions & 8 deletions examples/custom_ops/test_custom_ops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -e
test_buck2_custom_op_1() {
local model_name='custom_ops_1'
echo "Exporting ${model_name}.pte"
python3 -m "examples.custom_ops.${model_name}"
python -m "examples.custom_ops.${model_name}"
# should save file custom_ops_1.pte

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

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

buck2 run //examples/executor_runner:executor_runner \
Expand Down Expand Up @@ -92,14 +92,24 @@ test_cmake_custom_op_2() {

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

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

test_buck2_custom_op_1
test_cmake_custom_op_1
test_buck2_custom_op_2
test_cmake_custom_op_2
if [[ $1 == "cmake" ]];
then
test_cmake_custom_op_1
test_cmake_custom_op_2
elif [[ $1 == "buck2" ]];
then
test_buck2_custom_op_1
test_buck2_custom_op_2
else
test_cmake_custom_op_1
test_cmake_custom_op_2
test_buck2_custom_op_1
test_buck2_custom_op_2
fi
43 changes: 34 additions & 9 deletions third-party/link_torch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,39 @@

set -e

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

SUBPATH=$1
OUT=$2
if [[ -f "$LIB/$SUBPATH" ]] || [[ -d "$LIB/$SUBPATH" ]];
then
ln -s "$LIB/$SUBPATH" "$OUT"
else
echo "Error: $LIB/$SUBPATH doesn't exist"
case $OPTARG in
-*) echo "Option $opt needs to be one of -o, -f."
exit 1
fi
;;
esac
done

LIB=$(python3 -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')

# delimiter ,
export IFS=","

for SUBPATH in $FILES; do
if [[ -f "$LIB/$SUBPATH" ]] || [[ -d "$LIB/$SUBPATH" ]];
then
ln -s "$LIB/$SUBPATH" "$OUT"
else
echo "Error: $LIB/$SUBPATH doesn't exist"
exit 1
fi
done