Skip to content

Commit 748ac9b

Browse files
authored
Update XLA pin then fix up to make it compile (#9565)
Updates: * Modify call to some OpenXLA C++ functions because their calling convention changed. * bazel is now more strict: explicit header and explicit deps are enforced * removed FORTIFY_SOURCE defines via a patch, it is making gcc segfault on compile * updated gcc version to 11
1 parent 6b6ef5c commit 748ac9b

19 files changed

+110
-80
lines changed

.circleci/common.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ function build_torch_xla() {
112112
# Need to uncomment the line below.
113113
# Currently it fails upstream XLA CI.
114114
# pip install plugins/cuda -v
115-
pip install 'torch_xla[pallas]'
115+
pip install --pre torch_xla[pallas] --index-url https://us-python.pkg.dev/ml-oss-artifacts-published/jax/simple/ --find-links https://storage.googleapis.com/jax-releases/libtpu_releases.html
116+
116117
popd
117118
}
118119

.github/workflows/_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ jobs:
140140
set -x
141141
142142
pip install expecttest unittest-xml-reporting
143-
pip install 'torch_xla[pallas]'
143+
pip install --pre 'torch_xla[pallas]' --index-url https://us-python.pkg.dev/ml-oss-artifacts-published/jax/simple/ --find-links https://storage.googleapis.com/jax-releases/libtpu_releases.html
144144
145145
if [[ ! -z "$RUN_BENCHMARK_TESTS" ]]; then
146146
pip install -r pytorch/xla/benchmarks/requirements.txt

.github/workflows/_tpu_ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ jobs:
5252
pip install fsspec
5353
pip install rich
5454
# jax and libtpu is needed for pallas tests.
55-
pip install 'torch_xla[pallas]'
56-
pip install 'torch_xla[tpu]' -f https://storage.googleapis.com/libtpu-wheels/index.html -f https://storage.googleapis.com/libtpu-releases/index.html
55+
pip install --pre 'torch_xla[pallas]' --index-url https://us-python.pkg.dev/ml-oss-artifacts-published/jax/simple/ --find-links https://storage.googleapis.com/jax-releases/libtpu_releases.html'
56+
pip install --pre 'torch_xla[tpu]' --index-url https://us-python.pkg.dev/ml-oss-artifacts-published/jax/simple/ --find-links https://storage.googleapis.com/jax-releases/libtpu_releases.html'
5757
pip install --upgrade protobuf
5858
- name: Run Tests (${{ matrix.test_script }})
5959
if: inputs.has_code_changes == 'true'

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ commands on your Linux machine directly, outside of the container.
162162
-f https://storage.googleapis.com/libtpu-releases/index.html
163163
164164
# Optional: if you're using custom kernels, install pallas dependencies
165-
pip install torch_xla[pallas]
165+
pip install --pre torch_xla[pallas] --index-url https://us-python.pkg.dev/ml-oss-artifacts-published/jax/simple/ --find-links https://storage.googleapis.com/jax-releases/libtpu_releases.html
166166
```
167167

168168
1. If you are running on a TPU VM, ensure `torch` and `torch_xla` were built and

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Note: Builds are available for Python 3.8 to 3.11; please use one of the support
3535
pip install torch==2.8.0 'torch_xla[tpu]==2.8.0'
3636

3737
# Optional: if you're using custom kernels, install pallas dependencies
38-
pip install 'torch_xla[pallas]'
38+
pip install --pre torch_xla[pallas] --index-url https://us-python.pkg.dev/ml-oss-artifacts-published/jax/simple/ --find-links https://storage.googleapis.com/jax-releases/libtpu_releases.html
3939
```
4040
**As of 07/16/2025 and starting from Pytorch/XLA 2.8 release, PyTorch/XLA will
4141
provide nightly and release wheels for Python 3.11 to 3.13**

WORKSPACE

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ new_local_repository(
4646

4747
# To build PyTorch/XLA with a new revison of OpenXLA, update the xla_hash to
4848
# the openxla git commit hash and note the date of the commit.
49-
xla_hash = '3d5ece64321630dade7ff733ae1353fc3c83d9cc' # Committed on 2025-06-17.
49+
xla_hash = '92f7b5952dd585c5be17c9a5caad27407005b513' # Committed on 2025-08-15.
5050

5151
http_archive(
5252
name = "xla",
@@ -58,7 +58,7 @@ http_archive(
5858
patches = [
5959
"//openxla_patches:gpu_nvml.diff",
6060
"//openxla_patches:gpu_race_condition.diff",
61-
"//openxla_patches:count_down.diff",
61+
"//openxla_patches:no_fortify.diff",
6262
],
6363
strip_prefix = "xla-" + xla_hash,
6464
urls = [
@@ -81,6 +81,19 @@ http_archive(
8181
# path = "/path/to/openxla",
8282
# )
8383

84+
# Initialize OpenXLA's external dependencies. There is an specific order
85+
# which those dependencies are initialized, because for bazel it's the
86+
# first definition that takes precedence.
87+
# We follow what openxla/xla does exactly:
88+
# https://github.com/openxla/xla/blob/main/WORKSPACE#L37
89+
load("@xla//:workspace4.bzl", "xla_workspace4")
90+
91+
xla_workspace4()
92+
93+
load("@xla//:workspace3.bzl", "xla_workspace3")
94+
95+
xla_workspace3()
96+
8497
# Initialize hermetic Python
8598
load("@xla//third_party/py:python_init_rules.bzl", "python_init_rules")
8699

@@ -115,14 +128,6 @@ install_deps()
115128

116129

117130

118-
# Initialize OpenXLA's external dependencies.
119-
load("@xla//:workspace4.bzl", "xla_workspace4")
120-
121-
xla_workspace4()
122-
123-
load("@xla//:workspace3.bzl", "xla_workspace3")
124-
125-
xla_workspace3()
126131

127132
load("@xla//:workspace2.bzl", "xla_workspace2")
128133

bazel/rules_def.bzl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
"""Rules that simplify deps and compiler configuration for PyTorch/XLA."""
2-
3-
load(
4-
"@xla//xla:xla.default.bzl",
5-
"xla_cc_test",
6-
)
7-
82
def ptxla_cc_library(
93
deps = [],
104
copts = [],
@@ -22,7 +16,7 @@ def ptxla_cc_test(
2216
deps,
2317
copts = [],
2418
**kwargs):
25-
xla_cc_test(
19+
native.cc_test(
2620
linkstatic = True,
2721
copts = copts + [
2822
"-isystemexternal/torch", # Required for system includes.

openxla_patches/count_down.diff

Lines changed: 0 additions & 14 deletions
This file was deleted.

openxla_patches/no_fortify.diff

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
diff --git a/tools/toolchains/cross_compile/cc/BUILD b/tools/toolchains/cross_compile/cc/BUILD
2+
index be6e8968d5..51d15fa3c9 100644
3+
--- a/tools/toolchains/cross_compile/cc/BUILD
4+
+++ b/tools/toolchains/cross_compile/cc/BUILD
5+
@@ -80,7 +80,6 @@ cc_toolchain_config(
6+
opt_compile_flags = [
7+
"-g0",
8+
"-O2",
9+
- "-D_FORTIFY_SOURCE=1",
10+
"-DNDEBUG",
11+
"-ffunction-sections",
12+
"-fdata-sections",
13+
@@ -166,7 +165,6 @@ cc_toolchain_config(
14+
opt_compile_flags = [
15+
"-g0",
16+
"-O2",
17+
- "-D_FORTIFY_SOURCE=1",
18+
"-DNDEBUG",
19+
"-ffunction-sections",
20+
"-fdata-sections",
21+
@@ -263,7 +261,6 @@ cc_toolchain_config(
22+
opt_compile_flags = [
23+
"-g0",
24+
"-O2",
25+
- "-D_FORTIFY_SOURCE=1",
26+
"-DNDEBUG",
27+
"-ffunction-sections",
28+
"-fdata-sections",
29+
diff --git a/tools/toolchains/cross_compile/cc/cc_toolchain_config.bzl b/tools/toolchains/cross_compile/cc/cc_toolchain_config.bzl
30+
index de638c0159..f25c0cc0fe 100644
31+
--- a/tools/toolchains/cross_compile/cc/cc_toolchain_config.bzl
32+
+++ b/tools/toolchains/cross_compile/cc/cc_toolchain_config.bzl
33+
@@ -218,7 +218,6 @@ def _impl(ctx):
34+
flag_group(
35+
# Security hardening requires optimization.
36+
# We need to undef it as some distributions now have it enabled by default.
37+
- flags = ["-U_FORTIFY_SOURCE"],
38+
),
39+
],
40+
with_features = [

scripts/build_torch_wheels.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ function install_llvm_clang() {
139139
sudo update-alternatives --install /usr/bin/clang++ clang++ $(which clang++-8) 70
140140
}
141141

142-
function install_gcc10() {
143-
sudo apt-get -y install gcc-10 g++-10
144-
export CC=/usr/bin/gcc-10 export CXX=/usr/bin/g++-10
142+
function install_gcc() {
143+
sudo apt-get -y install gcc-11 g++-11
144+
export CC=/usr/bin/gcc-10 export CXX=/usr/bin/g++-11
145145
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
146146
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100
147147
}
@@ -332,7 +332,7 @@ function main() {
332332
if [[ $(uname -m) == "x86_64" ]]; then
333333
install_llvm_clang
334334
elif [[ $(uname -m) == "aarch64" ]]; then
335-
install_gcc10
335+
install_gcc
336336
fi
337337
install_and_setup_conda
338338
build_and_install_torch

0 commit comments

Comments
 (0)