Skip to content

Test MV3 model in CI wheel builds #9192

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

Merged
merged 2 commits into from
Mar 18, 2025
Merged
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
Empty file added .ci/scripts/wheel/__init__.py
Empty file.
File renamed without changes.
11 changes: 11 additions & 0 deletions .ci/scripts/wheel/envvar_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# This file is sourced into the environment before building a pip wheel. It
# should typically only contain shell variable assignments. Be sure to export
# any variables so that subprocesses will see them.

source "${GITHUB_WORKSPACE}/${REPOSITORY}/.ci/scripts/wheel/envvar_base.sh"
11 changes: 1 addition & 10 deletions build/packaging/env_var_script_macos.sh → .ci/scripts/wheel/envvar_macos.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@
# should typically only contain shell variable assignments. Be sure to export
# any variables so that subprocesses will see them.

# Enable pybindings so that users can execute ExecuTorch programs from python.
export EXECUTORCH_BUILD_PYBIND=1

# Ensure that CMAKE_ARGS is defined before referencing it. Defaults to empty
# if not defined.
export CMAKE_ARGS="${CMAKE_ARGS:-}"

# Link the XNNPACK backend into the pybindings runtime so that users can execute
# ExecuTorch programs that delegate to it.
CMAKE_ARGS="${CMAKE_ARGS} -DEXECUTORCH_BUILD_XNNPACK=ON"
source "${GITHUB_WORKSPACE}/${REPOSITORY}/.ci/scripts/wheel/envvar_base.sh"

# When building for macOS, link additional backends into the pybindings runtime.
CMAKE_ARGS="${CMAKE_ARGS} -DEXECUTORCH_BUILD_COREML=ON"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion build/packaging/pre_build_script.sh → .ci/scripts/wheel/pre_build_script.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ set -euxo pipefail
# which does install them. Though we'd need to disable build isolation to be
# able to see the installed torch package.

pip install --progress-bar off -r requirements-dev.txt
"${GITHUB_WORKSPACE}/${REPOSITORY}/install_requirements.sh"
66 changes: 66 additions & 0 deletions .ci/scripts/wheel/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import os
import subprocess
import sys
from dataclasses import dataclass
from functools import cache
from typing import List


@cache
def _unsafe_get_env(key: str) -> str:
value = os.getenv(key)
if value is None:
raise RuntimeError(f"environment variable '{key}' is not set")
return value


@cache
def _repository_root_dir() -> str:
return os.path.join(
_unsafe_get_env("GITHUB_WORKSPACE"),
_unsafe_get_env("REPOSITORY"),
)


# For some reason, we are unable to see the entire repo in the python path.
# So manually add it.
sys.path.append(_repository_root_dir())
from examples.models import Backend, Model


@dataclass
class ModelTest:
model: Model
backend: Backend


def run_tests(model_tests: List[ModelTest]) -> None:
# Why are we doing this envvar shenanigans? Since we build the testers, which
# uses buck, we cannot run as root. This is a sneaky of getting around that
# test.
#
# This can be reverted if either:
# - We remove usage of buck in our builds
# - We stop running the Docker image as root: https://github.com/pytorch/test-infra/issues/5091
envvars = os.environ.copy()
envvars.pop("HOME")

for model_test in model_tests:
subprocess.run(
[
os.path.join(_repository_root_dir(), ".ci/scripts/test_model.sh"),
str(model_test.model),
# What to build `executor_runner` with for testing.
Comment on lines +57 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need so many redirections?

Can we just call this command directly in the .yml file?

"cmake",
str(model_test.backend),
],
env=envvars,
check=True,
cwd=_repository_root_dir(),
)
19 changes: 19 additions & 0 deletions .ci/scripts/wheel/test_linux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import test_base
from examples.models import Backend, Model

if __name__ == "__main__":
test_base.run_tests(
model_tests=[
test_base.ModelTest(
model=Model.Mv3,
backend=Backend.XnnpackQuantizationDelegation,
)
]
)
19 changes: 19 additions & 0 deletions .ci/scripts/wheel/test_macos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import test_base
from examples.models import Backend, Model

if __name__ == "__main__":
test_base.run_tests(
model_tests=[
test_base.ModelTest(
model=Model.Mv3,
backend=Backend.XnnpackQuantizationDelegation,
)
]
)
15 changes: 6 additions & 9 deletions .github/workflows/build-wheels-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Build Linux Wheels
on:
pull_request:
paths:
- build/packaging/**
- .ci/**/*
- .github/workflows/build-wheels-linux.yml
push:
branches:
Expand Down Expand Up @@ -39,9 +39,9 @@ jobs:
matrix:
include:
- repository: pytorch/executorch
pre-script: build/packaging/pre_build_script.sh
post-script: build/packaging/post_build_script.sh
smoke-test-script: build/packaging/smoke_test.py
pre-script: .ci/scripts/wheel/pre_build_script.sh
post-script: .ci/scripts/wheel/post_build_script.sh
smoke-test-script: .ci/scripts/wheel/test_linux.py
package-name: executorch
name: ${{ matrix.repository }}
uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main
Expand All @@ -51,11 +51,8 @@ jobs:
test-infra-repository: pytorch/test-infra
test-infra-ref: main
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
# ExecuTorch only needs the first layer of submodules; override the
# "recursive" default to do less work, and to give the buck daemon fewer
# files to look at.
submodules: true
env-var-script: build/packaging/env_var_script_linux.sh
submodules: recursive
env-var-script: .ci/scripts/wheel/envvar_linux.sh
pre-script: ${{ matrix.pre-script }}
post-script: ${{ matrix.post-script }}
package-name: ${{ matrix.package-name }}
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/build-wheels-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Build macOS Wheels
on:
pull_request:
paths:
- build/packaging/**
- .ci/**/*
- .github/workflows/build-wheels-macos.yml
push:
branches:
Expand Down Expand Up @@ -39,9 +39,9 @@ jobs:
matrix:
include:
- repository: pytorch/executorch
pre-script: build/packaging/pre_build_script.sh
post-script: build/packaging/post_build_script.sh
smoke-test-script: build/packaging/smoke_test.py
pre-script: .ci/scripts/wheel/pre_build_script.sh
post-script: .ci/scripts/wheel/post_build_script.sh
smoke-test-script: .ci/scripts/wheel/test_macos.py
package-name: executorch
name: ${{ matrix.repository }}
uses: pytorch/test-infra/.github/workflows/build_wheels_macos.yml@main
Expand All @@ -51,12 +51,9 @@ jobs:
test-infra-repository: pytorch/test-infra
test-infra-ref: main
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
# ExecuTorch only needs the first layer of submodules; override the
# "recursive" default to do less work, and to give the buck daemon fewer
# files to look at.
submodules: true
submodules: recursive
delocate-wheel: false
env-var-script: build/packaging/env_var_script_macos.sh
env-var-script: .ci/scripts/wheel/envvar_macos.sh
pre-script: ${{ matrix.pre-script }}
post-script: ${{ matrix.post-script }}
package-name: ${{ matrix.package-name }}
Expand Down
121 changes: 0 additions & 121 deletions build/packaging/smoke_test.py

This file was deleted.

Loading
Loading