Skip to content

Commit 031c0ac

Browse files
nitins17Google-ML-Automation
authored andcommitted
Add new CI scripts for running Pytests
This commit adds the new CI scripts for running Pytests. It makes use of the pytest envs inside the "ci/envs/run_tests" folder to control the build behavior. For e.g: for running the GPU tests with Pytest, we will need to run `./ci/run_pytest.sh ./ci/envs/run_tests/pytest_gpu.env`. Note that Pytests need JAX wheels to be installed on the system to work. The `install_wheels_locally.sh` script installs these wheels in CI builds. PiperOrigin-RevId: 701331411
1 parent c3c21c7 commit 031c0ac

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-0
lines changed

ci/envs/default.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,13 @@ export JAXCI_MAX_TESTS_PER_GPU=${JAXCI_MAX_TESTS_PER_GPU:-12}
5757
# Sets the value of `JAX_ENABLE_X64` in the test scripts. CI builds override
5858
# this value in the Github action workflow files.
5959
export JAXCI_ENABLE_X64=${JAXCI_ENABLE_X64:-0}
60+
61+
# Pytest specific environment variables below. Used in run_pytest_*.sh scripts.
62+
# Sets the number of TPU cores for the TPU machine type. These values are
63+
# defined in the TPU GitHub Actions workflow.
64+
export JAXCI_TPU_CORES=${JAXCI_TPU_CORES:-}
65+
66+
# JAXCI_PYTHON points to the Python interpreter to use for installing JAX wheels
67+
# on the system. By default, it is set to match the version of the hermetic
68+
# Python used by Bazel for building the wheels.
69+
export JAXCI_PYTHON=${JAXCI_PYTHON:-python${JAXCI_HERMETIC_PYTHON_VERSION}}

ci/run_pytest_cpu.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# Copyright 2024 The JAX Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
# Runs Pyest CPU tests. Requires a jaxlib wheel to be present
17+
# inside the $JAXCI_OUTPUT_DIR (../dist)
18+
#
19+
# -e: abort script if one command fails
20+
# -u: error if undefined variable used
21+
# -x: log all commands
22+
# -o history: record shell history
23+
# -o allexport: export all functions and variables to be available to subscripts
24+
set -exu -o history -o allexport
25+
26+
# Source default JAXCI environment variables.
27+
source ci/envs/default.env
28+
29+
# Install jaxlib wheel inside the $JAXCI_OUTPUT_DIR directory on the system.
30+
echo "Installing wheels locally..."
31+
source ./ci/utilities/install_wheels_locally.sh
32+
33+
# Set up the build environment.
34+
source "ci/utilities/setup_build_environment.sh"
35+
36+
"$JAXCI_PYTHON" -c "import jax; print(jax.default_backend()); print(jax.devices()); print(len(jax.devices()))"
37+
38+
# Set up all test environment variables
39+
export PY_COLORS=1
40+
export JAX_SKIP_SLOW_TESTS=true
41+
export TF_CPP_MIN_LOG_LEVEL=0
42+
# End of test environment variable setup
43+
44+
echo "Running CPU tests..."
45+
"$JAXCI_PYTHON" -m pytest -n auto --tb=short --maxfail=20 tests examples

ci/run_pytest_gpu.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# Copyright 2024 The JAX Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
# Runs Pyest CPU tests. Requires the jaxlib, jax-cuda-plugin, and jax-cuda-pjrt
17+
# wheels to be present inside $JAXCI_OUTPUT_DIR (../dist)
18+
#
19+
# -e: abort script if one command fails
20+
# -u: error if undefined variable used
21+
# -x: log all commands
22+
# -o history: record shell history
23+
# -o allexport: export all functions and variables to be available to subscripts
24+
set -exu -o history -o allexport
25+
26+
# Source default JAXCI environment variables.
27+
source ci/envs/default.env
28+
29+
# Install jaxlib, jax-cuda-plugin, and jax-cuda-pjrt wheels inside the
30+
# $JAXCI_OUTPUT_DIR directory on the system.
31+
echo "Installing wheels locally..."
32+
source ./ci/utilities/install_wheels_locally.sh
33+
34+
# Set up the build environment.
35+
source "ci/utilities/setup_build_environment.sh"
36+
37+
"$JAXCI_PYTHON" -c "import jax; print(jax.default_backend()); print(jax.devices()); print(len(jax.devices()))"
38+
39+
nvidia-smi
40+
41+
# Set up all test environment variables
42+
export PY_COLORS=1
43+
export JAX_SKIP_SLOW_TESTS=true
44+
export NCCL_DEBUG=WARN
45+
export TF_CPP_MIN_LOG_LEVEL=0
46+
47+
# Set the number of processes to run to be 4x the number of GPUs.
48+
export gpu_count=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
49+
export num_processes=`expr 4 \* $gpu_count`
50+
51+
export XLA_PYTHON_CLIENT_ALLOCATOR=platform
52+
export XLA_FLAGS=--xla_gpu_force_compilation_parallelism=1
53+
# End of test environment variable setup
54+
55+
echo "Running GPU tests..."
56+
"$JAXCI_PYTHON" -m pytest -n $num_processes --tb=short --maxfail=20 \
57+
tests examples \
58+
--deselect=tests/multi_device_test.py::MultiDeviceTest::test_computation_follows_data \
59+
--deselect=tests/xmap_test.py::XMapTest::testCollectivePermute2D \
60+
--deselect=tests/multiprocess_gpu_test.py::MultiProcessGpuTest::test_distributed_jax_visible_devices \
61+
--deselect=tests/compilation_cache_test.py::CompilationCacheTest::test_task_using_cache_metric

ci/run_pytest_tpu.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# Copyright 2024 The JAX Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
# Runs Pyest CPU tests. Requires a jaxlib wheel to be present
17+
# inside $JAXCI_OUTPUT_DIR (../dist)
18+
#
19+
# -e: abort script if one command fails
20+
# -u: error if undefined variable used
21+
# -x: log all commands
22+
# -o history: record shell history
23+
# -o allexport: export all functions and variables to be available to subscripts
24+
set -exu -o history -o allexport
25+
26+
# Source default JAXCI environment variables.
27+
source ci/envs/default.env
28+
29+
# Install jaxlib wheel inside the $JAXCI_OUTPUT_DIR directory on the system.
30+
echo "Installing wheels locally..."
31+
source ./ci/utilities/install_wheels_locally.sh
32+
33+
# Set up the build environment.
34+
source "ci/utilities/setup_build_environment.sh"
35+
36+
export PY_COLORS=1
37+
export JAX_SKIP_SLOW_TESTS=true
38+
39+
"$JAXCI_PYTHON" -c "import jax; print(jax.default_backend()); print(jax.devices()); print(len(jax.devices()))"
40+
41+
"$JAXCI_PYTHON" -c 'import sys; print("python version:", sys.version)'
42+
"$JAXCI_PYTHON" -c 'import jax; print("jax version:", jax.__version__)'
43+
"$JAXCI_PYTHON" -c 'import jaxlib; print("jaxlib version:", jaxlib.__version__)'
44+
strings /usr/local/lib/"$JAXCI_PYTHON"/site-packages/libtpu/libtpu.so | grep 'Built on'
45+
"$JAXCI_PYTHON" -c 'import jax; print("libtpu version:",jax.lib.xla_bridge.get_backend().platform_version)'
46+
47+
echo "Running TPU tests..."
48+
export JAX_PLATFORMS=tpu,cpu
49+
# Run single-accelerator tests in parallel
50+
export JAX_ENABLE_TPU_XDIST=true
51+
52+
"$JAXCI_PYTHON" -m pytest -n="$JAXCI_TPU_CORES" --tb=short \
53+
--deselect=tests/pallas/tpu_pallas_test.py::PallasCallPrintTest \
54+
--maxfail=20 -m "not multiaccelerator" tests examples
55+
56+
# Run Pallas printing tests, which need to run with I/O capturing disabled.
57+
export TPU_STDERR_LOG_LEVEL=0
58+
"$JAXCI_PYTHON" -m pytest -s tests/pallas/tpu_pallas_test.py::PallasCallPrintTest
59+
60+
# Run multi-accelerator across all chips
61+
"$JAXCI_PYTHON" -m pytest --tb=short --maxfail=20 -m "multiaccelerator" tests
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# Copyright 2024 The JAX Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
#
17+
# Install wheels stored in `JAXCI_OUTPUT_DIR` on the system using the Python
18+
# binary set in JAXCI_PYTHON. Use the absolute path to the `find` utility to
19+
# avoid using the Windows version of `find` on Msys.
20+
WHEELS=( $(/usr/bin/find "$JAXCI_OUTPUT_DIR/" -type f \( -name "*jaxlib*" -o -name "*jax*cuda*pjrt*" -o -name "*jax*cuda*plugin*" \)) )
21+
22+
if [[ -z "$WHEELS" ]]; then
23+
echo "ERROR: No wheels found under $JAXCI_OUTPUT_DIR"
24+
exit 1
25+
fi
26+
27+
echo "Installing the following wheels:"
28+
echo "${WHEELS[@]}"
29+
"$JAXCI_PYTHON" -m pip install "${WHEELS[@]}"
30+
31+
echo "Installing the JAX package in editable mode at the current commit..."
32+
# Install JAX package at the current commit.
33+
"$JAXCI_PYTHON" -m pip install -U -e .

0 commit comments

Comments
 (0)