-
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 14 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 | ||
|
|
||
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.