-
Notifications
You must be signed in to change notification settings - Fork 82
Improve build-te for build-jax step in CI #2245
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
base: main
Are you sure you want to change the base?
Changes from all commits
1f26ca8
5a1e934
b96b3e0
e833330
311474e
8a93efd
d1d2e9f
ef16a29
f60c112
3448da0
6285bfc
cb1317d
8bdc9e8
27debea
3ca389a
3920991
95ab9f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
| # Never trace this script: it handles credentials mounted by BuildKit. | ||
| set +x | ||
|
|
||
| compiler_cache_args=() | ||
| case "${ENABLE_NVTE_SCCACHE:-0}" in | ||
| 1) | ||
| required_sccache_secrets=( | ||
| AWS_ACCESS_KEY_ID | ||
| AWS_SECRET_ACCESS_KEY | ||
| AWS_SESSION_TOKEN | ||
| SCCACHE_BUCKET | ||
| ) | ||
| for secret_name in "${required_sccache_secrets[@]}"; do | ||
| if [[ ! -s "/run/secrets/${secret_name}" ]]; then | ||
| echo "ENABLE_NVTE_SCCACHE=1 requires the ${secret_name} BuildKit secret" >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| for secret_name in "${required_sccache_secrets[@]}"; do | ||
| printf -v "${secret_name}" '%s' "$(<"/run/secrets/${secret_name}")" | ||
| export "${secret_name}" | ||
| done | ||
|
|
||
| : "${SCCACHE_REGION:?ENABLE_NVTE_SCCACHE=1 requires SCCACHE_REGION}" | ||
| : "${TARGETARCH:?BuildKit did not provide TARGETARCH}" | ||
| export NVTE_CCACHE_BIN=sccache | ||
| export SCCACHE_REGION | ||
| export SCCACHE_S3_KEY_PREFIX="sccache/${TARGETARCH}" | ||
| export SCCACHE_S3_USE_SSL=true | ||
| compiler_cache_args+=(--ccache) | ||
| ;; | ||
| 0) | ||
| ;; | ||
| *) | ||
| echo "ENABLE_NVTE_SCCACHE must be 0 or 1" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| exec build-te.sh "${compiler_cache_args[@]}" "$@" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ usage() { | |
| echo " OPTIONS DESCRIPTION" | ||
| echo " --clean Clear build caches under --src-path-te." | ||
| echo " -h, --help Print usage." | ||
| echo " --ccache Use ccache to build TransformerEngine. It will be installed, but the caller should configure it." | ||
| echo " --ccache Use a compiler cache to build TransformerEngine." | ||
| echo " --no-install Only build a wheel; do not install." | ||
| echo " --src-path-te Path to TransformerEngine source code." | ||
| echo " --src-path-xla Path to XLA source code." | ||
|
|
@@ -148,25 +148,78 @@ subprocess.run( | |
| + [f"nvidia-cudnn-frontend=={os.environ['CUDNN_FRONTEND_VERSION']}"] | ||
| ) | ||
| EOF | ||
| # Transformer Engine adds NVTE_CCACHE_BIN as both its C++ and CUDA CMake | ||
| # compiler launcher when NVTE_USE_CCACHE is set. Do not also wrap CXX: that | ||
| # would produce a recursive "ccache ccache g++" invocation. | ||
| if [[ "${CCACHE}" == "1" ]]; then | ||
| # Install ccache if not present (needs >= 4.1 for Redis remote storage support) | ||
| if ! command -v ccache &> /dev/null; then | ||
| apt-get update && apt-get install -y --no-install-recommends ccache | ||
| NVTE_CCACHE_BIN="${NVTE_CCACHE_BIN:-ccache}" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to use sscache, then we need the install script |
||
| CACHE_PROGRAM="$(basename -- "${NVTE_CCACHE_BIN}")" | ||
|
|
||
| if ! command -v "${NVTE_CCACHE_BIN}" &> /dev/null; then | ||
| # Keep direct callers backwards compatible while the Docker build | ||
| # installs its selected cache explicitly. | ||
| CACHE_INSTALLER="${SCRIPT_DIR}/install-compiler-cache.sh" | ||
| if [[ ! -x "${CACHE_INSTALLER}" ]]; then | ||
| CACHE_INSTALLER="$(command -v install-compiler-cache.sh || true)" | ||
| fi | ||
| if [[ -z "${CACHE_INSTALLER}" || ! -x "${CACHE_INSTALLER}" ]]; then | ||
| echo "${NVTE_CCACHE_BIN} is not installed and install-compiler-cache.sh is unavailable" | ||
| exit 1 | ||
| fi | ||
| "${CACHE_INSTALLER}" "${NVTE_CCACHE_BIN}" | ||
| fi | ||
| if ! command -v "${NVTE_CCACHE_BIN}" &> /dev/null; then | ||
| echo "Compiler cache installation did not provide ${NVTE_CCACHE_BIN}" | ||
| exit 1 | ||
| fi | ||
| export CXX="ccache g++" | ||
|
|
||
| export NVTE_USE_CCACHE=1 | ||
| ccache --zero-stats | ||
| export NVTE_CCACHE_BIN | ||
| case "${CACHE_PROGRAM}" in | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we're initializing the compiler-cache backend. For sccache, we explicitly start the daemon, disable its idle shutdown for the |
||
| sccache) | ||
| # Keep the daemon alive for long CUDA builds and retain an error log | ||
| # so backend failures are visible alongside the cache statistics. | ||
| export SCCACHE_IDLE_TIMEOUT="${SCCACHE_IDLE_TIMEOUT:-0}" | ||
| export SCCACHE_ERROR_LOG="${SCCACHE_ERROR_LOG:-/tmp/sccache-server.log}" | ||
| rm -f -- "${SCCACHE_ERROR_LOG}" | ||
| "${NVTE_CCACHE_BIN}" --start-server | ||
| "${NVTE_CCACHE_BIN}" --zero-stats | ||
| ;; | ||
| ccache) | ||
| export CCACHE_DIR="${CCACHE_DIR:-/root/.cache/ccache}" | ||
| "${NVTE_CCACHE_BIN}" --zero-stats | ||
| ;; | ||
| *) | ||
| echo "Unsupported compiler cache: ${NVTE_CCACHE_BIN}" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| echo "Transformer Engine compiler cache: ${CACHE_PROGRAM}" | ||
| fi | ||
|
|
||
| # The wheel filename includes the TE commit; if this has changed since the last | ||
| # incremental build then we would end up with multiple wheels. | ||
| rm -fv dist/*.whl | ||
| python setup.py bdist_wheel | ||
| ls dist/ | ||
| popd | ||
|
|
||
| CACHE_STATUS=0 | ||
| if [[ "${CCACHE}" == "1" ]]; then | ||
| ccache --show-stats --verbose | ||
| case "${CACHE_PROGRAM}" in | ||
| sccache) | ||
| "${NVTE_CCACHE_BIN}" --show-stats || CACHE_STATUS=$? | ||
| if [[ -s "${SCCACHE_ERROR_LOG}" ]]; then | ||
| echo "WARNING: sccache reported backend errors:" | ||
| tail -n 200 "${SCCACHE_ERROR_LOG}" | ||
| fi | ||
| # Stopping the daemon drains any in-flight cache uploads. | ||
| "${NVTE_CCACHE_BIN}" --stop-server || true | ||
| rm -f -- "${SCCACHE_ERROR_LOG}" | ||
| ;; | ||
| ccache) | ||
| "${NVTE_CCACHE_BIN}" --show-stats --verbose || CACHE_STATUS=$? | ||
| ;; | ||
| esac | ||
| fi | ||
|
|
||
| ## Install the built packages | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #!/bin/bash | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0.17.0 is released, can this all be dropped?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet, I tried to get this script in a better shape though. |
||
| set -euo pipefail | ||
|
|
||
| usage() { | ||
| echo "Install a compiler cache used by build-te.sh" | ||
| echo "" | ||
| echo " Usage: $0 [ccache|sccache]" | ||
| echo "" | ||
| echo " If no argument is provided, NVTE_CCACHE_BIN selects the cache." | ||
| exit "${1}" | ||
| } | ||
|
|
||
| if [[ "$#" -gt 1 ]]; then | ||
| usage 1 | ||
| fi | ||
| if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then | ||
| usage 0 | ||
| fi | ||
|
|
||
| CACHE_BINARY="${1:-${NVTE_CCACHE_BIN:-ccache}}" | ||
| case "${CACHE_BINARY}" in | ||
| ccache) | ||
| if command -v ccache &> /dev/null; then | ||
| echo "Compiler cache already installed: $(command -v ccache)" | ||
| exit 0 | ||
| fi | ||
| export DEBIAN_FRONTEND=noninteractive | ||
| apt-get update | ||
| apt-get install -y --no-install-recommends ccache | ||
| rm -rf /var/lib/apt/lists/* | ||
| ;; | ||
| sccache) | ||
| readonly SCCACHE_SOURCE_URL="https://github.com/mozilla/sccache.git" | ||
| readonly SCCACHE_SOURCE_COMMIT="e9b15a35f7240a7edd1b9644583edb388c6cb5f9" | ||
| readonly SCCACHE_RUST_TOOLCHAIN="1.88.0" | ||
| readonly SCCACHE_RUSTUP_VERSION="1.29.0" | ||
|
|
||
| case "$(dpkg --print-architecture)" in | ||
| amd64) | ||
| SCCACHE_RUSTUP_HOST="x86_64-unknown-linux-gnu" | ||
| ;; | ||
| arm64) | ||
| SCCACHE_RUSTUP_HOST="aarch64-unknown-linux-gnu" | ||
| ;; | ||
| *) | ||
| echo "Unsupported architecture for sccache: $(dpkg --print-architecture)" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| SCCACHE_TMPDIR="$(mktemp -d)" | ||
| cleanup() { | ||
| rm -rf -- "${SCCACHE_TMPDIR}" | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| export DEBIAN_FRONTEND=noninteractive | ||
| apt-get update | ||
| apt-get install -y --no-install-recommends libssl-dev pkg-config | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| export CARGO_HOME="${SCCACHE_TMPDIR}/cargo" | ||
| export RUSTUP_HOME="${SCCACHE_TMPDIR}/rustup" | ||
| SCCACHE_RUSTUP_INIT="${SCCACHE_TMPDIR}/rustup-init" | ||
| SCCACHE_RUSTUP_URL="https://static.rust-lang.org/rustup/archive/${SCCACHE_RUSTUP_VERSION}/${SCCACHE_RUSTUP_HOST}/rustup-init" | ||
|
|
||
| wget -nv --tries=5 --retry-connrefused \ | ||
| -O "${SCCACHE_RUSTUP_INIT}" "${SCCACHE_RUSTUP_URL}" | ||
| wget -nv --tries=5 --retry-connrefused \ | ||
| -O- "${SCCACHE_RUSTUP_URL}.sha256" \ | ||
| | awk -v binary="${SCCACHE_RUSTUP_INIT}" '{print $1" "binary}' \ | ||
| | sha256sum -c - | ||
| chmod 755 "${SCCACHE_RUSTUP_INIT}" | ||
| "${SCCACHE_RUSTUP_INIT}" \ | ||
| -y \ | ||
| --no-modify-path \ | ||
| --profile minimal \ | ||
| --default-toolchain "${SCCACHE_RUST_TOOLCHAIN}" | ||
|
|
||
| "${CARGO_HOME}/bin/cargo" install sccache \ | ||
| --git "${SCCACHE_SOURCE_URL}" \ | ||
| --rev "${SCCACHE_SOURCE_COMMIT}" \ | ||
| --locked \ | ||
| --no-default-features \ | ||
| --features=s3 \ | ||
| --bin sccache \ | ||
| --root /usr/local \ | ||
| --no-track \ | ||
| --force | ||
| ;; | ||
| *) | ||
| echo "${CACHE_BINARY} is not installed; automatic installation supports only ccache and sccache" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| if ! command -v "${CACHE_BINARY}" &> /dev/null; then | ||
| echo "Compiler cache installation did not provide ${CACHE_BINARY}" | ||
| exit 1 | ||
| fi | ||
| echo "Installed compiler cache: $(command -v "${CACHE_BINARY}")" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build-te-with-sccache.shis a thin BuildKit-specific wrapper aroundbuild-te.sh. It keeps Docker secret handling separate from the normalTransformer Engine build logic.
When
ENABLE_NVTE_SCCACHE=1, the wrapper:process tree.
--ccacheto thebuild-te.shinvocation.