From 4d53362d25f762d32ea65f06167166ab057371a3 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Mon, 17 Jul 2023 18:57:44 -0700 Subject: [PATCH 1/9] Create a placeholder for pull workflow --- .github/workflows/pull.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/pull.yml diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml new file mode 100644 index 00000000000..942d574e021 --- /dev/null +++ b/.github/workflows/pull.yml @@ -0,0 +1,25 @@ +name: pull + +on: + pull_request: + push: + branches: + - main + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }} + cancel-in-progress: true + +jobs: + buck-build-test: + name: buck-build-test + uses: pytorch/test-infra/.github/workflows/linux_job.yml@use-shareable-gha-calculate-docker-image + with: + runner: linux.2xlarge + docker-image: executorch-ubuntu-22.04-clang12 + fetch-depth: 0 + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + script: | + # TODO: A placeholder for future build and test steps + echo "Thank You Mario, But Our Princess is in Another Castle" From 1e07892c208fc34c8cbc0efbb35551154339e110 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 21 Jul 2023 14:01:03 -0700 Subject: [PATCH 2/9] Try out buck2 --- .github/workflows/pull.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 942d574e021..0b3f1f1f7a8 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -23,3 +23,4 @@ jobs: script: | # TODO: A placeholder for future build and test steps echo "Thank You Mario, But Our Princess is in Another Castle" + sleep 300 From f9206537bce9096288db4da752977d80f4ea7932 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 21 Jul 2023 16:07:24 -0700 Subject: [PATCH 3/9] Setup conda and pip --- .ci/docker/build.sh | 6 ++++- .ci/docker/common/install_conda.sh | 41 ++++++++++++++++++++++++++++++ .ci/docker/common/utils.sh | 24 +++++++++++++++++ .ci/docker/requirements-ci.txt | 1 + .ci/docker/ubuntu/Dockerfile | 9 +++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100755 .ci/docker/common/install_conda.sh create mode 100644 .ci/docker/common/utils.sh create mode 100644 .ci/docker/requirements-ci.txt diff --git a/.ci/docker/build.sh b/.ci/docker/build.sh index 260b3e23407..98bd9f14ef8 100755 --- a/.ci/docker/build.sh +++ b/.ci/docker/build.sh @@ -7,15 +7,19 @@ shift echo "Building ${IMAGE_NAME} Docker image" -OS="ubuntu" +OS=ubuntu OS_VERSION=22.04 CLANG_VERSION=12 +PYTHON_VERSION=3.10 +MINICONDA_VERSION='23.5.1-0' docker build \ --no-cache \ --progress=plain \ --build-arg "OS_VERSION=${OS_VERSION}" \ --build-arg "CLANG_VERSION=${CLANG_VERSION}" \ + --build-arg "PYTHON_VERSION=${PYTHON_VERSION}" \ + --build-arg "MINICONDA_VERSION=${MINICONDA_VERSION}" \ -f "${OS}"/Dockerfile \ "$@" \ . diff --git a/.ci/docker/common/install_conda.sh b/.ci/docker/common/install_conda.sh new file mode 100755 index 00000000000..3f0801e5fdf --- /dev/null +++ b/.ci/docker/common/install_conda.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +set -ex + +source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" + +install_miniconda() { + BASE_URL="https://repo.anaconda.com/miniconda" + CONDA_FILE="Miniconda3-py${PYTHON_VERSION//./}_${MINICONDA_VERSION}-Linux-x86_64.sh" + + mkdir -p /opt/conda + chown ci-user:ci-user /opt/conda + + pushd /tmp + wget -q "${BASE_URL}/${CONDA_FILE}" + # Install miniconda + as_ci_user bash "${CONDA_FILE}" -b -f -p "/opt/conda" + popd + + sed -e 's|PATH="\(.*\)"|PATH="/opt/conda/bin:\1"|g' -i /etc/environment + export PATH="/opt/conda/bin:$PATH" +} + +install_python() { + pushd /opt/conda + # Install the correct Python version + as_ci_user conda create -n py_$PYTHON_VERSION -y python="$PYTHON_VERSION" + popd +} + +install_pip_dependencies() { + pushd /opt/conda + # Install all Python dependencies, including PyTorch + pip_install -r /opt/conda/requirements-ci.txt + pip_install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu + popd +} + +install_miniconda +install_python +install_pip_dependencies diff --git a/.ci/docker/common/utils.sh b/.ci/docker/common/utils.sh new file mode 100644 index 00000000000..dfaff614f70 --- /dev/null +++ b/.ci/docker/common/utils.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +as_ci_user() { + # NB: unsetting the environment variables works around a conda bug + # https://github.com/conda/conda/issues/6576 + # NB: Pass on PATH and LD_LIBRARY_PATH to sudo invocation + # NB: This must be run from a directory that the user has access to + sudo -E -H -u ci-user env -u SUDO_UID -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER env "PATH=$PATH" "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" $* +} + +conda_install() { + # Ensure that the install command don't upgrade/downgrade Python + # This should be called as + # conda_install pkg1 pkg2 ... [-c channel] + as_ci_user conda install -q -n py_$PYTHON_VERSION -y python="$PYTHON_VERSION" $* +} + +conda_run() { + as_ci_user conda run -n py_$PYTHON_VERSION --no-capture-output $* +} + +pip_install() { + as_ci_user conda run -n py_$PYTHON_VERSION pip install --progress-bar off $* +} diff --git a/.ci/docker/requirements-ci.txt b/.ci/docker/requirements-ci.txt new file mode 100644 index 00000000000..9c97e401d3f --- /dev/null +++ b/.ci/docker/requirements-ci.txt @@ -0,0 +1 @@ +flatbuffers==2.0 diff --git a/.ci/docker/ubuntu/Dockerfile b/.ci/docker/ubuntu/Dockerfile index 5ad25de1af7..504ca77b06b 100644 --- a/.ci/docker/ubuntu/Dockerfile +++ b/.ci/docker/ubuntu/Dockerfile @@ -23,5 +23,14 @@ RUN bash ./install_buck.sh && rm install_buck.sh COPY ./common/install_user.sh install_user.sh RUN bash ./install_user.sh && rm install_user.sh +# Install conda and other dependencies +ARG PYTHON_VERSION +ENV PYTHON_VERSION=$PYTHON_VERSION +ENV PATH /opt/conda/envs/py_$PYTHON_VERSION/bin:/opt/conda/bin:$PATH +COPY requirements-ci.txt requirements-docs.txt /opt/conda/ +COPY ./common/install_conda.sh install_conda.sh +COPY ./common/utils.sh utils.sh +RUN bash ./install_conda.sh && rm install_conda.sh utils.sh /opt/conda/requirements-ci.txt + USER ci-user CMD ["bash"] From ed52c42ed1dc92b0b914573409c5fe7e58a3bc7c Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 21 Jul 2023 16:12:33 -0700 Subject: [PATCH 4/9] Remove requirements-docs.txt --- .ci/docker/ubuntu/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/docker/ubuntu/Dockerfile b/.ci/docker/ubuntu/Dockerfile index 504ca77b06b..b677c1b4bad 100644 --- a/.ci/docker/ubuntu/Dockerfile +++ b/.ci/docker/ubuntu/Dockerfile @@ -27,7 +27,7 @@ RUN bash ./install_user.sh && rm install_user.sh ARG PYTHON_VERSION ENV PYTHON_VERSION=$PYTHON_VERSION ENV PATH /opt/conda/envs/py_$PYTHON_VERSION/bin:/opt/conda/bin:$PATH -COPY requirements-ci.txt requirements-docs.txt /opt/conda/ +COPY requirements-ci.txt /opt/conda/ COPY ./common/install_conda.sh install_conda.sh COPY ./common/utils.sh utils.sh RUN bash ./install_conda.sh && rm install_conda.sh utils.sh /opt/conda/requirements-ci.txt From 6f3996425f46f6609b6d8845c1592d8039b9ff4e Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 21 Jul 2023 16:15:01 -0700 Subject: [PATCH 5/9] Add MINICONDA_VERSION --- .ci/docker/ubuntu/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/docker/ubuntu/Dockerfile b/.ci/docker/ubuntu/Dockerfile index b677c1b4bad..117c4fd1a15 100644 --- a/.ci/docker/ubuntu/Dockerfile +++ b/.ci/docker/ubuntu/Dockerfile @@ -24,6 +24,7 @@ COPY ./common/install_user.sh install_user.sh RUN bash ./install_user.sh && rm install_user.sh # Install conda and other dependencies +ARG MINICONDA_VERSION ARG PYTHON_VERSION ENV PYTHON_VERSION=$PYTHON_VERSION ENV PATH /opt/conda/envs/py_$PYTHON_VERSION/bin:/opt/conda/bin:$PATH From f7777a28a96294dd4773b6843d151ec765c639d0 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 21 Jul 2023 16:34:38 -0700 Subject: [PATCH 6/9] Run install.sh --- .ci/docker/common/install_base.sh | 3 ++- .ci/docker/common/install_conda.sh | 2 ++ .ci/docker/requirements-ci.txt | 2 ++ .github/workflows/pull.yml | 13 ++++++++++--- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.ci/docker/common/install_base.sh b/.ci/docker/common/install_base.sh index 34e4d383585..b4ff57515db 100755 --- a/.ci/docker/common/install_base.sh +++ b/.ci/docker/common/install_base.sh @@ -16,7 +16,8 @@ install_ubuntu() { jq \ vim \ unzip \ - gdb + gdb \ + rsync # Cleanup package manager apt-get autoclean && apt-get clean diff --git a/.ci/docker/common/install_conda.sh b/.ci/docker/common/install_conda.sh index 3f0801e5fdf..ec0e0204720 100755 --- a/.ci/docker/common/install_conda.sh +++ b/.ci/docker/common/install_conda.sh @@ -15,6 +15,8 @@ install_miniconda() { wget -q "${BASE_URL}/${CONDA_FILE}" # Install miniconda as_ci_user bash "${CONDA_FILE}" -b -f -p "/opt/conda" + # Clean up the download file + rm "${CONDA_FILE}" popd sed -e 's|PATH="\(.*\)"|PATH="/opt/conda/bin:\1"|g' -i /etc/environment diff --git a/.ci/docker/requirements-ci.txt b/.ci/docker/requirements-ci.txt index 9c97e401d3f..be5c3a37843 100644 --- a/.ci/docker/requirements-ci.txt +++ b/.ci/docker/requirements-ci.txt @@ -1 +1,3 @@ flatbuffers==2.0 +PyYAML==6.0.1 +ruamel.yaml==0.17.32 diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 0b3f1f1f7a8..28e3a38f306 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -21,6 +21,13 @@ jobs: fetch-depth: 0 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} script: | - # TODO: A placeholder for future build and test steps - echo "Thank You Mario, But Our Princess is in Another Castle" - sleep 300 + WORKSPACE=$(pwd) + + pushd "${HOME}" + # Create the softlink to the workspace as install.sh requires to run from its parent directory + ln -s "${WORKSPACE}" executorch + # Install executorch + source executorch/install.sh + + # Just print out the list of packages for debugging + pip list From c12c206b4ad019c9beaa8a4d859a996eab241c24 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 21 Jul 2023 16:41:54 -0700 Subject: [PATCH 7/9] Add sympy and mpmath --- .ci/docker/requirements-ci.txt | 2 ++ install.sh | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.ci/docker/requirements-ci.txt b/.ci/docker/requirements-ci.txt index be5c3a37843..9b35a5621b9 100644 --- a/.ci/docker/requirements-ci.txt +++ b/.ci/docker/requirements-ci.txt @@ -1,3 +1,5 @@ flatbuffers==2.0 +mpmath==1.3.0 PyYAML==6.0.1 ruamel.yaml==0.17.32 +sympy==1.12 diff --git a/install.sh b/install.sh index 4c58a648498..9416d9f53df 100755 --- a/install.sh +++ b/install.sh @@ -51,11 +51,12 @@ main() { "${PIP}" uninstall -y executorch # Install the tree as a pip package. - cd "${et_root}/../../" + pushd "${et_root}/../../" "${PIP}" install . # Clean up. rm -rf "${pip_root}" + popd } main "$@" From 83e1e26b39d01d560c79cb906b94023e3ec80ab9 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 21 Jul 2023 19:05:32 -0700 Subject: [PATCH 8/9] Fix lint --- .ci/docker/README.md | 4 +++- .ci/docker/common/install_conda.sh | 3 ++- .ci/docker/common/utils.sh | 8 ++++---- install.sh | 10 ++++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.ci/docker/README.md b/.ci/docker/README.md index b74bb835aff..aa455fff484 100644 --- a/.ci/docker/README.md +++ b/.ci/docker/README.md @@ -1,7 +1,9 @@ # Docker images for Executorch CI This directory contains everything needed to build the Docker images -that are used in Executorch CI. +that are used in Executorch CI. The content of this directory are copied +from PyTorch CI https://github.com/pytorch/pytorch/tree/main/.ci/docker. +It also uses the same directory structure as PyTorch. ## Contents diff --git a/.ci/docker/common/install_conda.sh b/.ci/docker/common/install_conda.sh index ec0e0204720..2d6dd4cf2f4 100755 --- a/.ci/docker/common/install_conda.sh +++ b/.ci/docker/common/install_conda.sh @@ -2,6 +2,7 @@ set -ex +# shellcheck source=/dev/null source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" install_miniconda() { @@ -26,7 +27,7 @@ install_miniconda() { install_python() { pushd /opt/conda # Install the correct Python version - as_ci_user conda create -n py_$PYTHON_VERSION -y python="$PYTHON_VERSION" + as_ci_user conda create -n "py_${PYTHON_VERSION}" -y python="${PYTHON_VERSION}" popd } diff --git a/.ci/docker/common/utils.sh b/.ci/docker/common/utils.sh index dfaff614f70..2e37986fa48 100644 --- a/.ci/docker/common/utils.sh +++ b/.ci/docker/common/utils.sh @@ -5,20 +5,20 @@ as_ci_user() { # https://github.com/conda/conda/issues/6576 # NB: Pass on PATH and LD_LIBRARY_PATH to sudo invocation # NB: This must be run from a directory that the user has access to - sudo -E -H -u ci-user env -u SUDO_UID -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER env "PATH=$PATH" "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" $* + sudo -E -H -u ci-user env -u SUDO_UID -u SUDO_GID -u SUDO_COMMAND -u SUDO_USER env "PATH=${PATH}" "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" "$@" } conda_install() { # Ensure that the install command don't upgrade/downgrade Python # This should be called as # conda_install pkg1 pkg2 ... [-c channel] - as_ci_user conda install -q -n py_$PYTHON_VERSION -y python="$PYTHON_VERSION" $* + as_ci_user conda install -q -n "py_${PYTHON_VERSION}" -y python="${PYTHON_VERSION}" "$@" } conda_run() { - as_ci_user conda run -n py_$PYTHON_VERSION --no-capture-output $* + as_ci_user conda run -n "py_${PYTHON_VERSION}" --no-capture-output "$@" } pip_install() { - as_ci_user conda run -n py_$PYTHON_VERSION pip install --progress-bar off $* + as_ci_user conda run -n "py_${PYTHON_VERSION}" pip install --progress-bar off "$@" } diff --git a/install.sh b/install.sh index 9416d9f53df..30be87770a0 100755 --- a/install.sh +++ b/install.sh @@ -50,13 +50,15 @@ main() { # Uninstall older pip package if present. "${PIP}" uninstall -y executorch - # Install the tree as a pip package. - pushd "${et_root}/../../" - "${PIP}" install . + ( + # Install the tree as a pip package. + pushd "${et_root}/../../" + "${PIP}" install . + popd + ) # Clean up. rm -rf "${pip_root}" - popd } main "$@" From da8fc57584c1d556656e33227406c57cf608ecc2 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 21 Jul 2023 19:17:11 -0700 Subject: [PATCH 9/9] Use main Linux job --- .github/workflows/pull.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 28e3a38f306..e54cff092f1 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -14,7 +14,7 @@ concurrency: jobs: buck-build-test: name: buck-build-test - uses: pytorch/test-infra/.github/workflows/linux_job.yml@use-shareable-gha-calculate-docker-image + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main with: runner: linux.2xlarge docker-image: executorch-ubuntu-22.04-clang12