Skip to content

Commit 3e1fb6d

Browse files
authored
build-jax.sh: --bazel-cache-namespace option (#1141)
When building the JAX container, set this to the name of the base container to provide some isolation within the shared cache between builds using different base containers. Bazel does not track system dependencies.
1 parent b1103a0 commit 3e1fb6d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.github/container/Dockerfile.base

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@ ARG CLANG_VERSION=18
88
## Obtain GCP's NCCL TCPx plugin
99
###############################################################################
1010

11-
FROM us-docker.pkg.dev/gce-ai-infra/gpudirect-tcpx/nccl-plugin-gpudirecttcpx:v3.1.10 as tcpx-installer-amd64
11+
FROM us-docker.pkg.dev/gce-ai-infra/gpudirect-tcpx/nccl-plugin-gpudirecttcpx:v3.1.10 AS tcpx-installer-amd64
1212

1313
# make a stub arm64 container because GCP does not provide an arm64 version of the plugin
14-
FROM ubuntu as tcpx-installer-arm64
14+
FROM ubuntu AS tcpx-installer-arm64
1515
RUN <<"OUTEREOF" bash -ex
1616
mkdir -p /scripts /var/lib/tcpx/lib64
1717
echo '#!/bin/bash' > /scripts/container_entry.sh
1818
chmod +x /scripts/container_entry.sh
1919
OUTEREOF
2020

21-
FROM tcpx-installer-${TARGETARCH} as tcpx-installer
21+
FROM tcpx-installer-${TARGETARCH} AS tcpx-installer
2222
RUN /scripts/container_entry.sh install
2323

2424
###############################################################################
2525
## Build base image
2626
###############################################################################
2727

2828
FROM ${BASE_IMAGE}
29+
ARG BASE_IMAGE
2930
ARG GIT_USER_EMAIL
3031
ARG GIT_USER_NAME
3132
ARG CLANG_VERSION
33+
ENV CUDA_BASE_IMAGE=${BASE_IMAGE}
3234

3335
###############################################################################
3436
## Install Python and essential tools

.github/container/build-jax.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ usage() {
2929
echo ""
3030
echo " OPTIONS DESCRIPTION"
3131
echo " --bazel-cache URI Path for local bazel cache or URL of remote bazel cache"
32+
echo " --bazel-cache-namespace NAME Namespace for bazel cache content"
3233
echo " --build-param PARAM Param passed to the jaxlib build command. Can be passed many times."
3334
echo " --build-path-jaxlib PATH Editable install prefix for jaxlib and plugins"
3435
echo " --clean Delete local configuration and bazel cache"
@@ -51,6 +52,7 @@ usage() {
5152

5253
# Set defaults
5354
BAZEL_CACHE=""
55+
BAZEL_CACHE_NAMESPACE="jax${CUDA_BASE_IMAGE:+:}${CUDA_BASE_IMAGE}"
5456
BUILD_PATH_JAXLIB="/opt/jaxlibs"
5557
BUILD_PARAM=""
5658
CLEAN=0
@@ -64,7 +66,7 @@ SRC_PATH_JAX="/opt/jax"
6466
SRC_PATH_XLA="/opt/xla"
6567
XLA_ARM64_PATCH_LIST=""
6668

67-
args=$(getopt -o h --long bazel-cache:,build-param:,build-path-jaxlib:,clean,cpu-arch:,debug,jaxlib_only,no-clean,clean-only,dry,help,src-path-jax:,src-path-xla:,sm:,xla-arm64-patch: -- "$@")
69+
args=$(getopt -o h --long bazel-cache:,bazel-cache-namespace:,build-param:,build-path-jaxlib:,clean,cpu-arch:,debug,jaxlib_only,no-clean,clean-only,dry,help,src-path-jax:,src-path-xla:,sm:,xla-arm64-patch: -- "$@")
6870
if [[ $? -ne 0 ]]; then
6971
exit 1
7072
fi
@@ -76,6 +78,10 @@ while [ : ]; do
7678
BAZEL_CACHE=$2
7779
shift 2
7880
;;
81+
--bazel-cache-namespace)
82+
BAZEL_CACHE_NAMESPACE=$2
83+
shift 2
84+
;;
7985
--build-param)
8086
BUILD_PARAM="$BUILD_PARAM $2"
8187
shift 2
@@ -196,6 +202,9 @@ fi
196202
if [[ "${BAZEL_CACHE}" == http://* ]] || \
197203
[[ "${BAZEL_CACHE}" == grpc://* ]]; then
198204
BUILD_PARAM="${BUILD_PARAM} --bazel_options=--remote_cache=${BAZEL_CACHE}"
205+
if [[ -n "${BAZEL_CACHE_NAMESPACE}" ]]; then
206+
BUILD_PARAM="${BUILD_PARAM} --bazel_options=--remote_instance_name=${BAZEL_CACHE_NAMESPACE}"
207+
fi
199208
elif [[ ! -z "${BAZEL_CACHE}" ]] ; then
200209
BUILD_PARAM="${BUILD_PARAM} --bazel_options=--disk_cache=${BAZEL_CACHE}"
201210
fi

0 commit comments

Comments
 (0)