Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ckmadhira authored Nov 21, 2024
2 parents f75206b + 43555d2 commit e4df82c
Show file tree
Hide file tree
Showing 456 changed files with 848,489 additions and 3,650 deletions.
5 changes: 5 additions & 0 deletions .ci/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ case "${IMAGE_NAME}" in
ARM_SDK=yes
CLANG_VERSION=12
;;
executorch-ubuntu-22.04-qnn-sdk)
QNN_SDK=yes
CLANG_VERSION=12
;;
executorch-ubuntu-22.04-clang12-android)
LINTRUNNER=""
CLANG_VERSION=12
Expand Down Expand Up @@ -72,6 +76,7 @@ docker build \
--build-arg "LINTRUNNER=${LINTRUNNER:-}" \
--build-arg "BUILD_DOCS=${BUILD_DOCS}" \
--build-arg "ARM_SDK=${ARM_SDK:-}" \
--build-arg "QNN_SDK=${QNN_SDK:-}" \
--build-arg "ANDROID_NDK_VERSION=${ANDROID_NDK_VERSION:-}" \
-f "${OS}"/Dockerfile \
"$@" \
Expand Down
2 changes: 1 addition & 1 deletion .ci/docker/ci_commit_pins/pytorch.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c8a648d4dffb9f0133ff4a2ea0e660b42105d3ad
19eff28ff3f19b50da46f5a9ff5f4d4d213806fe
1 change: 0 additions & 1 deletion .ci/docker/ci_commit_pins/torchao.txt

This file was deleted.

52 changes: 45 additions & 7 deletions .ci/docker/common/install_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ set -ex
# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"

install_ubuntu() {
echo "Preparing to build sccache from source"
apt-get update
# libssl-dev will not work as it is upgraded to libssl3 in Ubuntu-22.04.
# Instead use lib and headers from OpenSSL1.1 installed in `install_openssl.sh``
apt-get install -y cargo
echo "Checking out sccache repo"
git clone https://github.com/mozilla/sccache -b v0.8.2

cd sccache
echo "Building sccache"
cargo build --release
cp target/release/sccache /opt/cache/bin
echo "Cleaning up"
cd ..
rm -rf sccache
apt-get remove -y cargo rustc
apt-get autoclean && apt-get clean
}

install_binary() {
echo "Downloading sccache binary from S3 repo"
curl --retry 3 https://s3.amazonaws.com/ossci-linux/sccache -o /opt/cache/bin/sccache
Expand All @@ -22,15 +42,33 @@ mkdir -p /opt/cache/bin
sed -e 's|PATH="\(.*\)"|PATH="/opt/cache/bin:\1"|g' -i /etc/environment
export PATH="/opt/cache/bin:$PATH"

# NB: Install the pre-built binary from S3 as building from source
# https://github.com/pytorch/sccache has started failing mysteriously
# in which sccache server couldn't start with the following error:
# sccache: error: Invalid argument (os error 22)
install_binary
install_ubuntu

function write_sccache_stub() {
BINARY=$1
printf "#!/bin/sh\nif [ \$(env -u LD_PRELOAD ps -p \$PPID -o comm=) != sccache ]; then\n exec sccache %s \"\$@\"\nelse\n exec %s \"\$@\"\nfi" "$(which "${BINARY}")" "$(which "${BINARY}")" > "/opt/cache/bin/${BINARY}"
if [ $1 == "gcc" ]; then
# Do not call sccache recursively when dumping preprocessor argument
# For some reason it's very important for the first cached nvcc invocation
cat >"/opt/cache/bin/$1" <<EOF
#!/bin/sh
if [ "\$1" = "-E" ] || [ "\$2" = "-E" ]; then
exec $(which $1) "\$@"
elif [ \$(env -u LD_PRELOAD ps -p \$PPID -o comm=) != sccache ]; then
exec sccache $(which $1) "\$@"
else
exec $(which $1) "\$@"
fi
EOF
else
cat >"/opt/cache/bin/$1" <<EOF
#!/bin/sh
if [ \$(env -u LD_PRELOAD ps -p \$PPID -o comm=) != sccache ]; then
exec sccache $(which $1) "\$@"
else
exec $(which $1) "\$@"
fi
EOF
fi
chmod a+x "/opt/cache/bin/${BINARY}"
}

Expand All @@ -44,7 +82,7 @@ init_sccache() {

# NB: This function is adopted from PyTorch core at
# https://github.com/pytorch/pytorch/blob/main/.ci/pytorch/common-build.sh
as_ci_user sccache --stop-server > /dev/null 2>&1 || true
as_ci_user sccache --stop-server >/dev/null 2>&1 || true
rm -f "${SCCACHE_ERROR_LOG}" || true

# Clear sccache stats before using it
Expand Down
3 changes: 3 additions & 0 deletions .ci/docker/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ COPY ./common/utils.sh utils.sh
RUN bash ./install_cache.sh && rm install_cache.sh utils.sh
ENV SCCACHE_BUCKET ossci-compiler-cache-circleci-v2
ENV SCCACHE_S3_KEY_PREFIX executorch
ENV SCCACHE_REGION us-east-1

ARG TORCH_VERSION
COPY ./common/install_pytorch.sh install_pytorch.sh
Expand All @@ -82,5 +83,7 @@ COPY --chown=ci-user:ci-user ./arm /opt/arm
# Set up ARM SDK if needed
RUN if [ -n "${ARM_SDK}" ]; then git config --global user.email "[email protected]"; git config --global user.name "OSS CI"; bash /opt/arm/setup.sh --i-agree-to-the-contained-eula /opt/arm-sdk; chown -R ci-user:ci-user /opt/arm-sdk; fi

ARG QNN_SDK

USER ci-user
CMD ["bash"]
6 changes: 4 additions & 2 deletions .ci/scripts/gather_test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"ic4": "linux.12xlarge",
"resnet50": "linux.12xlarge",
"llava": "linux.12xlarge",
"llama3_2_vision_encoder": "linux.12xlarge",
# "llama3_2_text_decoder": "linux.12xlarge", # TODO: re-enable test when Huy's change is in / model gets smaller.
# This one causes timeout on smaller runner, the root cause is unclear (T161064121)
"dl3": "linux.12xlarge",
"emformer_join": "linux.12xlarge",
Expand Down Expand Up @@ -88,8 +90,8 @@ def model_should_run_on_event(model: str, event: str) -> bool:
if event == "pull_request":
return model in ["mv3", "vit"]
elif event == "push":
# 'emformer_predict' is running super slow. Only run it periodically
return model not in ["emformer_predict"]
# These are super slow. Only run it periodically
return model not in ["dl3", "edsr", "emformer_predict"]
else:
return True

Expand Down
1 change: 1 addition & 0 deletions .ci/scripts/setup-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ fi
# of nightly. This allows CI to test against latest commits from PyTorch
install_executorch "use-pt-pinned-commit"
build_executorch_runner "${BUILD_TOOL}"
do_not_use_nightly_on_ci
42 changes: 36 additions & 6 deletions .ci/scripts/test_llama.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,41 @@ set -exu
# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"

MODEL_NAME=$1 # stories110M
BUILD_TOOL=$2 # buck2 or cmake
DTYPE=$3 # fp16, bf16, or fp32
MODE=${4:-"xnnpack+custom"} # portable or xnnpack+custom or xnnpack+custom+qe
UPLOAD_DIR=${5:-}
while [[ $# -gt 0 ]]; do
case "$1" in
-model)
MODEL_NAME="$2" # stories110M
shift 2
;;
-build_tool)
BUILD_TOOL="$2" # buck2 or cmake
shift 2
;;
-dtype)
DTYPE="$2" # fp16, bf16, or fp32
shift 2
;;
-mode)
MODE="$2" # portable or xnnpack+custom or xnnpack+custom+qe
shift 2
;;
-upload)
UPLOAD_DIR="$2"
shift 2
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done

# Default mode to xnnpack+custom if not set
MODE=${MODE:-"xnnpack+custom"}

# Default UPLOAD_DIR to empty string if not set
UPLOAD_DIR="${UPLOAD_DIR:-}"

if [[ $# -lt 4 ]]; then # Assuming 4 mandatory args
echo "Expecting atleast 4 positional arguments"
echo "Usage: [...]"
Expand Down Expand Up @@ -150,7 +180,7 @@ cleanup_files() {
}

prepare_artifacts_upload() {
if [ -n "$UPLOAD_DIR" ]; then
if [ -n "${UPLOAD_DIR}" ]; then
echo "Preparing for uploading generated artifacs"
zip -j model.zip "${EXPORTED_MODEL_NAME}" tokenizer.bin
mkdir -p "${UPLOAD_DIR}"
Expand Down
3 changes: 2 additions & 1 deletion .ci/scripts/test_llama_runner_eager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ run_and_verify() {
-d fp32 \
--max_seq_length 32 \
--temperature 0 \
--show_tokens \
--prompt "Once upon a time," > result.txt

# Verify result.txt
RESULT=$(cat result.txt)
EXPECTED_RESULT="there was a little girl"
EXPECTED_RESULT="727, 471, 263, 2217, 7826, 4257, 365, 2354, 29889, 2296, 18012, 304, 1708, 5377, 297, 278, 6575, 845, 457, 29889, 3118, 2462, 29892, 1183, 4446, 263"
if [[ "${RESULT}" == *"${EXPECTED_RESULT}"* ]]; then
echo "Actual result: ${RESULT}"
echo "Success"
Expand Down
6 changes: 5 additions & 1 deletion .ci/scripts/test_model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test_model() {
# Install requirements for export_llama
bash examples/models/llama/install_requirements.sh
# Test export_llama script: python3 -m examples.models.llama.export_llama
"${PYTHON_EXECUTABLE}" -m examples.models.llama.export_llama -c examples/models/llama/params/demo_rand_params.pth -p examples/models/llama/params/demo_config.json
"${PYTHON_EXECUTABLE}" -m examples.models.llama.export_llama --model "${MODEL_NAME}" -c examples/models/llama/params/demo_rand_params.pth -p examples/models/llama/params/demo_config.json
run_portable_executor_runner
rm "./${MODEL_NAME}.pte"
fi
Expand All @@ -87,6 +87,10 @@ test_model() {
bash examples/models/llava/install_requirements.sh
STRICT="--no-strict"
fi
if [[ "$MODEL_NAME" == "llama3_2_vision_encoder" || "$MODEL_NAME" == "llama3_2_text_decoder" ]]; then
# Install requirements for llama vision.
bash examples/models/llama3_2_vision/install_requirements.sh
fi
# python3 -m examples.portable.scripts.export --model_name="llama2" should works too
"${PYTHON_EXECUTABLE}" -m examples.portable.scripts.export --model_name="${MODEL_NAME}" "${STRICT}"
run_portable_executor_runner
Expand Down
18 changes: 17 additions & 1 deletion .ci/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,26 @@ cmake_install_executorch_lib() {
}

download_stories_model_artifacts() {
# Download stories110M.pt and tokenizer from Github
# Download stories110M.pt and tokenizer from Github
curl -Ls "https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.pt" --output stories110M.pt
curl -Ls "https://raw.githubusercontent.com/karpathy/llama2.c/master/tokenizer.model" --output tokenizer.model
# Create params.json file
touch params.json
echo '{"dim": 768, "multiple_of": 32, "n_heads": 12, "n_layers": 12, "norm_eps": 1e-05, "vocab_size": 32000}' > params.json
}

do_not_use_nightly_on_ci() {
# An assert to make sure that we are not using PyTorch nightly on CI to prevent
# regression as documented in https://github.com/pytorch/executorch/pull/6564
TORCH_VERSION=$(pip list | grep -w 'torch ' | awk -F ' ' {'print $2'} | tr -d '\n')

# The version of PyTorch building from source looks like 2.6.0a0+gitc8a648d that
# includes the commit while nightly (2.6.0.dev20241019+cpu) or release (2.6.0)
# won't have that. Note that we couldn't check for the exact commit from the pin
# ci_commit_pins/pytorch.txt here because the value will be different when running
# this on PyTorch CI
if [[ "${TORCH_VERSION}" != *"+git"* ]]; then
echo "Unexpected torch version. Expected binary built from source, got ${TORCH_VERSION}"
exit 1
fi
}
62 changes: 62 additions & 0 deletions .github/scripts/check_labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3
"""Check whether a PR has required labels."""

import sys
from typing import Any

from github_utils import gh_delete_comment, gh_post_pr_comment
from gitutils import get_git_remote_name, get_git_repo_dir, GitRepo
from label_utils import has_required_labels, is_label_err_comment, LABEL_ERR_MSG
from trymerge import GitHubPR


def delete_all_label_err_comments(pr: "GitHubPR") -> None:
for comment in pr.get_comments():
if is_label_err_comment(comment):
gh_delete_comment(pr.org, pr.project, comment.database_id)


def add_label_err_comment(pr: "GitHubPR") -> None:
# Only make a comment if one doesn't exist already
if not any(is_label_err_comment(comment) for comment in pr.get_comments()):
gh_post_pr_comment(pr.org, pr.project, pr.pr_num, LABEL_ERR_MSG)


def parse_args() -> Any:
from argparse import ArgumentParser

parser = ArgumentParser("Check PR labels")
parser.add_argument("pr_num", type=int)
# add a flag to return a non-zero exit code if the PR does not have the required labels
parser.add_argument(
"--exit-non-zero",
action="store_true",
help="Return a non-zero exit code if the PR does not have the required labels",
)

return parser.parse_args()


def main() -> None:
args = parse_args()
repo = GitRepo(get_git_repo_dir(), get_git_remote_name())
org, project = repo.gh_owner_and_name()
pr = GitHubPR(org, project, args.pr_num)

try:
if not has_required_labels(pr):
print(LABEL_ERR_MSG, flush=True)
add_label_err_comment(pr)
if args.exit_non_zero:
raise RuntimeError("PR does not have required labels")
else:
delete_all_label_err_comments(pr)
except Exception as e:
if args.exit_non_zero:
raise RuntimeError(f"Error checking labels: {e}") from e

sys.exit(0)


if __name__ == "__main__":
main()
6 changes: 3 additions & 3 deletions .github/scripts/github_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def gh_fetch_url(
headers: Optional[Dict[str, str]] = None,
data: Union[Optional[Dict[str, Any]], str] = None,
method: Optional[str] = None,
reader: Callable[[Any], Any] = lambda x: x.read(),
reader: Callable[[Any], Any] = json.load,
) -> Any:
return gh_fetch_url_and_headers(
url, headers=headers, data=data, reader=json.load, method=method
url, headers=headers, data=data, reader=reader, method=method
)[1]


Expand Down Expand Up @@ -169,7 +169,7 @@ def gh_post_commit_comment(

def gh_delete_comment(org: str, repo: str, comment_id: int) -> None:
url = f"{GITHUB_API_URL}/repos/{org}/{repo}/issues/comments/{comment_id}"
gh_fetch_url(url, method="DELETE")
gh_fetch_url(url, method="DELETE", reader=lambda x: x.read())


def gh_fetch_merge_base(org: str, repo: str, base: str, head: str) -> str:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/_android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ jobs:
curl -O https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/llm_demo/app-debug.apk
curl -O https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/llm_demo/app-debug-androidTest.apk
curl -O https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/fp32-xnnpack-custom/model.zip
curl -o android-test-debug.apk https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/library_test_dir/executorch-debug.apk
curl -o android-test-debug-androidTest.apk https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/library_test_dir/executorch-debug-androidTest.apk
unzip model.zip
mv *.pte model.pte
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/android-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
fail-fast: false
with:
runner: linux.4xlarge
docker-image: executorch-ubuntu-22.04-clang12-android
docker-image: executorch-ubuntu-22.04-qnn-sdk
submodules: 'true'
timeout: 60
upload-artifact: android-models
Expand Down
Loading

0 comments on commit e4df82c

Please sign in to comment.