Skip to content

Commit 90a69e9

Browse files
vam-googlecopybara-github
authored andcommitted
Use hermetic Python in TSL and XLA
PiperOrigin-RevId: 634094641
1 parent 5f70248 commit 90a69e9

35 files changed

+981
-601
lines changed

WORKSPACE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ workspace(name = "xla")
77
# restriction that load() statements need to be at the top of .bzl files.
88
# E.g. we can not retrieve a new repository with http_archive and then load()
99
# a macro from that repository in the same file.
10+
11+
# Initialize hermetic Python
12+
load("//third_party/py:python_init_rules.bzl", "python_init_rules")
13+
14+
python_init_rules()
15+
16+
load("//third_party/py:python_init_repositories.bzl", "python_init_repositories")
17+
18+
python_init_repositories(
19+
requirements = {
20+
"3.11": "//:requirements_lock_3_11.txt",
21+
},
22+
)
23+
24+
load("//third_party/py:python_init_toolchains.bzl", "python_init_toolchains")
25+
26+
python_init_toolchains()
27+
28+
load("//third_party/py:python_init_pip.bzl", "python_init_pip")
29+
30+
python_init_pip()
31+
32+
load("@pypi//:requirements.bzl", "install_deps")
33+
34+
install_deps()
35+
1036
load(":workspace4.bzl", "xla_workspace4")
1137

1238
xla_workspace4()

opensource_only.files

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ third_party/llvm_openmp/openmp.bzl:
1919
third_party/ortools/BUILD:
2020
third_party/ortools/glpk.BUILD:
2121
third_party/ortools/ortools.patch:
22-
third_party/py/non_hermetic/BUILD.tpl:
23-
third_party/py/non_hermetic/BUILD:
24-
third_party/py/non_hermetic/README:
25-
third_party/py/non_hermetic/ml_dtypes/BUILD:
26-
third_party/py/non_hermetic/ml_dtypes/LICENSE:
27-
third_party/py/non_hermetic/numpy/BUILD:
28-
third_party/py/non_hermetic/python_configure.bzl:
22+
third_party/py/BUILD.tpl:
23+
third_party/py/BUILD:
24+
third_party/py/ml_dtypes/BUILD:
25+
third_party/py/ml_dtypes/LICENSE:
26+
third_party/py/numpy/BUILD:
27+
third_party/py/python_configure.bzl:
28+
third_party/py/python_init_pip.bzl:
29+
third_party/py/python_init_repositories.bzl:
30+
third_party/py/python_init_rules.bzl:
31+
third_party/py/python_init_toolchains.bzl:
32+
third_party/py/python_repo.bzl:
2933
third_party/python_runtime/BUILD:
3034
third_party/repo.bzl:
3135
third_party/stablehlo/BUILD:

requirements_lock_3_11.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
numpy==1.24.3 \
2+
--hash=sha256:0ec87a7084caa559c36e0a2309e4ecb1baa03b687201d0a847c8b0ed476a7187 \
3+
--hash=sha256:1a7d6acc2e7524c9955e5c903160aa4ea083736fde7e91276b0e5d98e6332812 \
4+
--hash=sha256:202de8f38fc4a45a3eea4b63e2f376e5f2dc64ef0fa692838e31a808520efaf7 \
5+
--hash=sha256:210461d87fb02a84ef243cac5e814aad2b7f4be953b32cb53327bb49fd77fbb4 \
6+
--hash=sha256:2d926b52ba1367f9acb76b0df6ed21f0b16a1ad87c6720a1121674e5cf63e2b6 \
7+
--hash=sha256:352ee00c7f8387b44d19f4cada524586f07379c0d49270f87233983bc5087ca0 \
8+
--hash=sha256:35400e6a8d102fd07c71ed7dcadd9eb62ee9a6e84ec159bd48c28235bbb0f8e4 \
9+
--hash=sha256:3c1104d3c036fb81ab923f507536daedc718d0ad5a8707c6061cdfd6d184e570 \
10+
--hash=sha256:4719d5aefb5189f50887773699eaf94e7d1e02bf36c1a9d353d9f46703758ca4 \
11+
--hash=sha256:4749e053a29364d3452c034827102ee100986903263e89884922ef01a0a6fd2f \
12+
--hash=sha256:5342cf6aad47943286afa6f1609cad9b4266a05e7f2ec408e2cf7aea7ff69d80 \
13+
--hash=sha256:56e48aec79ae238f6e4395886b5eaed058abb7231fb3361ddd7bfdf4eed54289 \
14+
--hash=sha256:76e3f4e85fc5d4fd311f6e9b794d0c00e7002ec122be271f2019d63376f1d385 \
15+
--hash=sha256:7776ea65423ca6a15255ba1872d82d207bd1e09f6d0894ee4a64678dd2204078 \
16+
--hash=sha256:784c6da1a07818491b0ffd63c6bbe5a33deaa0e25a20e1b3ea20cf0e43f8046c \
17+
--hash=sha256:8535303847b89aa6b0f00aa1dc62867b5a32923e4d1681a35b5eef2d9591a463 \
18+
--hash=sha256:9a7721ec204d3a237225db3e194c25268faf92e19338a35f3a224469cb6039a3 \
19+
--hash=sha256:a1d3c026f57ceaad42f8231305d4653d5f05dc6332a730ae5c0bea3513de0950 \
20+
--hash=sha256:ab344f1bf21f140adab8e47fdbc7c35a477dc01408791f8ba00d018dd0bc5155 \
21+
--hash=sha256:ab5f23af8c16022663a652d3b25dcdc272ac3f83c3af4c02eb8b824e6b3ab9d7 \
22+
--hash=sha256:ae8d0be48d1b6ed82588934aaaa179875e7dc4f3d84da18d7eae6eb3f06c242c \
23+
--hash=sha256:c91c4afd8abc3908e00a44b2672718905b8611503f7ff87390cc0ac3423fb096 \
24+
--hash=sha256:d5036197ecae68d7f491fcdb4df90082b0d4960ca6599ba2659957aafced7c17 \
25+
--hash=sha256:d6cc757de514c00b24ae8cf5c876af2a7c3df189028d68c0cb4eaa9cd5afc2bf \
26+
--hash=sha256:d933fabd8f6a319e8530d0de4fcc2e6a61917e0b0c271fded460032db42a0fe4 \
27+
--hash=sha256:ea8282b9bcfe2b5e7d491d0bf7f3e2da29700cec05b49e64d6246923329f2b02 \
28+
--hash=sha256:ecde0f8adef7dfdec993fd54b0f78183051b6580f606111a6d789cd14c61ea0c \
29+
--hash=sha256:f21c442fdd2805e91799fbe044a7b999b8571bb0ab0f7850d0cb9641a687092b
30+
lit==17.0.6 \
31+
--hash=sha256:dfa9af9b55fc4509a56be7bf2346f079d7f4a242d583b9f2e0b078fd0abae31b
32+
ml-dtypes==0.3.2 \
33+
--hash=sha256:2c34f2ba9660b21fe1034b608308a01be82bbef2a92fb8199f24dc6bad0d5226 \
34+
--hash=sha256:3a17ef2322e60858d93584e9c52a5be7dd6236b056b7fa1ec57f1bb6ba043e33 \
35+
--hash=sha256:533059bc5f1764fac071ef54598db358c167c51a718f68f5bb55e3dee79d2967 \
36+
--hash=sha256:6604877d567a29bfe7cc02969ae0f2425260e5335505cf5e7fefc3e5465f5655 \
37+
--hash=sha256:6b35c4e8ca957c877ac35c79ffa77724ecc3702a1e4b18b08306c03feae597bb \
38+
--hash=sha256:763697ab8a88d47443997a7cdf3aac7340049aed45f7521f6b0ec8a0594821fe \
39+
--hash=sha256:7a4c3fcbf86fa52d0204f07cfd23947ef05b4ad743a1a988e163caa34a201e5e \
40+
--hash=sha256:7afde548890a92b41c0fed3a6c525f1200a5727205f73dc21181a2726571bb53 \
41+
--hash=sha256:7ba8e1fafc7fff3e643f453bffa7d082df1678a73286ce8187d3e825e776eb94 \
42+
--hash=sha256:91f8783fd1f2c23fd3b9ee5ad66b785dafa58ba3cdb050c4458021fa4d1eb226 \
43+
--hash=sha256:93b78f53431c93953f7850bb1b925a17f0ab5d97527e38a7e865b5b4bc5cfc18 \
44+
--hash=sha256:961134ea44c7b8ca63eda902a44b58cd8bd670e21d62e255c81fba0a8e70d9b7 \
45+
--hash=sha256:b89b194e9501a92d289c1ffd411380baf5daafb9818109a4f49b0a1b6dce4462 \
46+
--hash=sha256:c7b3fb3d4f6b39bcd4f6c4b98f406291f0d681a895490ee29a0f95bab850d53c \
47+
--hash=sha256:d1a746fe5fb9cd974a91070174258f0be129c592b93f9ce7df6cc336416c3fbd \
48+
--hash=sha256:e8505946df1665db01332d885c2020b4cb9e84a8b1241eb4ba69d59591f65855 \
49+
--hash=sha256:f47619d978ab1ae7dfdc4052ea97c636c6263e1f19bd1be0e42c346b98d15ff4

third_party/llvm/toolchains.patch

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llv
22
index c43ab727e285..7d848d2dffae 100644
33
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
44
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
5-
@@ -30,6 +30,30 @@ exports_files([
5+
@@ -30,6 +30,36 @@ exports_files([
66
"utils/lit/lit.py",
77
])
88

@@ -22,6 +22,12 @@ index c43ab727e285..7d848d2dffae 100644
2222
+ },
2323
+)
2424
+
25+
+py_library(
26+
+ name = "lit_lib",
27+
+ testonly = True,
28+
+ srcs = ["utils/lit/lit.py"] + glob(["utils/lit/lit/**/*.py"]),
29+
+)
30+
+
2531
+config_setting(
2632
+ name = "macos_x86_64",
2733
+ values = {

third_party/py/BUILD

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
load("@python//:defs.bzl", "compile_pip_requirements")
2+
load("@python_version_repo//:py_version.bzl", "REQUIREMENTS")
3+
4+
compile_pip_requirements(
5+
name = "requirements",
6+
extra_args = [
7+
"--allow-unsafe",
8+
"--build-isolation",
9+
],
10+
generate_hashes = True,
11+
requirements_in = "requirements.in",
12+
requirements_txt = REQUIREMENTS,
13+
)
14+
15+
compile_pip_requirements(
16+
name = "requirements_nightly",
17+
data = ["test-requirements.txt"],
18+
extra_args = [
19+
"--allow-unsafe",
20+
"--build-isolation",
21+
"--extra-index-url=https://pypi.anaconda.org/scientific-python-nightly-wheels/simple",
22+
"--pre",
23+
"--upgrade",
24+
],
25+
generate_hashes = False,
26+
requirements_in = "requirements.in",
27+
requirements_txt = REQUIREMENTS,
28+
)
29+
30+
compile_pip_requirements(
31+
name = "requirements_dev",
32+
extra_args = [
33+
"--allow-unsafe",
34+
"--build-isolation",
35+
"--upgrade",
36+
],
37+
generate_hashes = False,
38+
requirements_in = "requirements.in",
39+
requirements_txt = REQUIREMENTS,
40+
)

third_party/py/BUILD.tpl

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ package(default_visibility = ["//visibility:public"])
55
# Point both runtimes to the same python binary to ensure we always
66
# use the python binary specified by ./configure.py script.
77
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
8+
load("@python//:defs.bzl", "interpreter")
89

910
py_runtime(
1011
name = "py2_runtime",
11-
interpreter_path = "%{PYTHON_BIN_PATH}",
12+
interpreter_path = interpreter,
1213
python_version = "PY2",
1314
)
1415

1516
py_runtime(
1617
name = "py3_runtime",
17-
interpreter_path = "%{PYTHON_BIN_PATH}",
18+
interpreter_path = interpreter,
1819
python_version = "PY3",
1920
)
2021

@@ -32,27 +33,8 @@ toolchain(
3233
exec_compatible_with = [%{PLATFORM_CONSTRAINT}],
3334
)
3435

35-
# To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib
36-
# See https://docs.python.org/3/extending/windows.html
37-
cc_import(
38-
name = "python_lib",
39-
interface_library = select({
40-
":windows": ":python_import_lib",
41-
# A placeholder for Unix platforms which makes --no_build happy.
42-
"//conditions:default": "not-existing.lib",
43-
}),
44-
system_provided = 1,
45-
)
46-
47-
cc_library(
48-
name = "python_headers",
49-
hdrs = [":python_include"],
50-
deps = select({
51-
":windows": [":python_lib"],
52-
"//conditions:default": [],
53-
}),
54-
includes = ["python_include"],
55-
)
36+
alias(name = "python_headers",
37+
actual = "@python//:python_headers")
5638

5739
# This alias is exists for the use of targets in the @llvm-project dependency,
5840
# which expect a python_headers target called @python_runtime//:headers. We use
@@ -63,18 +45,9 @@ alias(
6345
actual = ":python_headers",
6446
)
6547

66-
cc_library(
67-
name = "numpy_headers",
68-
hdrs = [":numpy_include"],
69-
includes = ["numpy_include"],
70-
)
7148

7249
config_setting(
7350
name = "windows",
7451
values = {"cpu": "x64_windows"},
7552
visibility = ["//visibility:public"],
76-
)
77-
78-
%{PYTHON_INCLUDE_GENRULE}
79-
%{NUMPY_INCLUDE_GENRULE}
80-
%{PYTHON_IMPORT_LIB_GENRULE}
53+
)

third_party/py/README

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

third_party/py/numpy/BUILD

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ licenses(["restricted"])
22

33
package(default_visibility = ["//visibility:public"])
44

5-
py_library(
5+
alias(
66
name = "numpy",
7-
srcs = ["tf_numpy_dummy.py"],
8-
srcs_version = "PY3",
7+
actual = "@pypi_numpy//:pkg",
98
)
109

1110
alias(
1211
name = "headers",
13-
actual = "@local_config_python//:numpy_headers",
12+
actual = "@pypi_numpy//:numpy_headers",
1413
)
1514

1615
genrule(

third_party/py/numpy/LICENSE

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Copyright (c) 2005-2019, NumPy Developers.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of the NumPy Developers nor the names of any
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
33+
34+
The NumPy repository and source distributions bundle several libraries that are
35+
compatibly licensed. We list these here.
36+
37+
Name: Numpydoc
38+
Files: doc/sphinxext/numpydoc/*
39+
License: 2-clause BSD
40+
For details, see doc/sphinxext/LICENSE.txt
41+
42+
Name: scipy-sphinx-theme
43+
Files: doc/scipy-sphinx-theme/*
44+
License: 3-clause BSD, PSF and Apache 2.0
45+
For details, see doc/scipy-sphinx-theme/LICENSE.txt
46+
47+
Name: lapack-lite
48+
Files: numpy/linalg/lapack_lite/*
49+
License: 3-clause BSD
50+
For details, see numpy/linalg/lapack_lite/LICENSE.txt
51+
52+
Name: tempita
53+
Files: tools/npy_tempita/*
54+
License: BSD derived
55+
For details, see tools/npy_tempita/license.txt
56+
57+
Name: dragon4
58+
Files: numpy/core/src/multiarray/dragon4.c
59+
License: One of a kind
60+
For license text, see numpy/core/src/multiarray/dragon4.c

third_party/py/numpy/tf_numpy_api/tensorflow.experimental.numpy.pbtxt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ tf_module {
390390
}
391391
member_method {
392392
name: "experimental_enable_numpy_behavior"
393-
argspec: "args=[\'prefer_float32\'], varargs=None, keywords=None, defaults=[\'False\'], "
393+
argspec: "args=[\'prefer_float32\', \'dtype_conversion_mode\'], varargs=None, keywords=None, defaults=[\'False\', \'legacy\'], "
394394
}
395395
member_method {
396396
name: "expm1"

0 commit comments

Comments
 (0)