Skip to content

Commit 1938df8

Browse files
fpetrini15mc-nv
andauthored
build: RHEL8 Python Backend (#7744)
Co-authored-by: Misha Chornyi <[email protected]>
1 parent 09cb1e5 commit 1938df8

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

build.py

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"2024.0.0", # Standalone OpenVINO
7979
"3.2.6", # DCGM version
8080
"0.5.3.post1", # vLLM version
81+
"3.12.3", # RHEL Python version
8182
)
8283
}
8384

@@ -950,7 +951,6 @@ def create_dockerfile_buildbase_rhel(ddir, dockerfile_name, argmap):
950951
libb64-devel \\
951952
gperftools-devel \\
952953
patchelf \\
953-
python3.11-devel \\
954954
python3-pip \\
955955
python3-setuptools \\
956956
rapidjson-devel \\
@@ -963,6 +963,10 @@ def create_dockerfile_buildbase_rhel(ddir, dockerfile_name, argmap):
963963
libxml2-devel \\
964964
numactl-devel \\
965965
wget
966+
"""
967+
# Requires openssl-devel to be installed first for pyenv build to be successful
968+
df += change_default_python_version_rhel(TRITON_VERSION_MAP[FLAGS.version][7])
969+
df += """
966970
967971
RUN pip3 install --upgrade pip \\
968972
&& pip3 install --upgrade \\
@@ -1389,7 +1393,29 @@ def dockerfile_prepare_container_linux(argmap, backends, enable_gpu, target_mach
13891393

13901394
# Add dependencies needed for python backend
13911395
if "python" in backends:
1392-
df += """
1396+
if target_platform() == "rhel":
1397+
df += """
1398+
# python3, python3-pip and some pip installs required for the python backend
1399+
RUN yum install -y \\
1400+
libarchive-devel \\
1401+
python3-pip \\
1402+
openssl-devel \\
1403+
readline-devel
1404+
"""
1405+
# Requires openssl-devel to be installed first for pyenv build to be successful
1406+
df += change_default_python_version_rhel(
1407+
TRITON_VERSION_MAP[FLAGS.version][7]
1408+
)
1409+
df += """
1410+
RUN pip3 install --upgrade pip \\
1411+
&& pip3 install --upgrade \\
1412+
wheel \\
1413+
setuptools \\
1414+
\"numpy<2\" \\
1415+
virtualenv
1416+
"""
1417+
else:
1418+
df += """
13931419
# python3, python3-pip and some pip installs required for the python backend
13941420
RUN apt-get update \\
13951421
&& apt-get install -y --no-install-recommends \\
@@ -1514,6 +1540,34 @@ def add_cpu_libs_to_linux_dockerfile(backends, target_machine):
15141540
return df
15151541

15161542

1543+
def change_default_python_version_rhel(version):
1544+
df = """
1545+
# The python library version available for install via 'yum install python3.X-devel' does not
1546+
# match the version of python inside the RHEL base container. This means that python packages
1547+
# installed within the container will not be picked up by the python backend stub process pybind
1548+
# bindings. It must instead must be installed via pyenv.
1549+
ENV PYENV_ROOT=/opt/pyenv_build
1550+
RUN curl https://pyenv.run | bash
1551+
ENV PATH="${{PYENV_ROOT}}/bin:$PATH"
1552+
RUN eval "$(pyenv init -)"
1553+
RUN CONFIGURE_OPTS=\"--with-openssl=/usr/lib64\" && pyenv install {} \\
1554+
&& cp ${{PYENV_ROOT}}/versions/{}/lib/libpython3* /usr/lib64/""".format(
1555+
version, version
1556+
)
1557+
df += """
1558+
# RHEL image has several python versions. It's important
1559+
# to set the correct version, otherwise, packages that are
1560+
# pip installed will not be found during testing.
1561+
ENV PYVER={} PYTHONPATH=/opt/python/v
1562+
RUN ln -sf ${{PYENV_ROOT}}/versions/${{PYVER}}* ${{PYTHONPATH}}
1563+
ENV PYBIN=${{PYTHONPATH}}/bin
1564+
ENV PYTHON_BIN_PATH=${{PYBIN}}/python${{PYVER}} PATH=${{PYBIN}}:${{PATH}}
1565+
""".format(
1566+
version
1567+
)
1568+
return df
1569+
1570+
15171571
def create_dockerfile_windows(
15181572
ddir, dockerfile_name, argmap, backends, repoagents, caches
15191573
):
@@ -1958,6 +2012,19 @@ def backend_build(
19582012
cmake_script.mkdir(os.path.join(install_dir, "backends"))
19592013
cmake_script.rmdir(os.path.join(install_dir, "backends", be))
19602014

2015+
# The python library version available for install via 'yum install python3.X-devel' does not
2016+
# match the version of python inside the RHEL base container. This means that python packages
2017+
# installed within the container will not be picked up by the python backend stub process pybind
2018+
# bindings. It must instead must be installed via pyenv. We package it here for better usability.
2019+
if target_platform() == "rhel" and be == "python":
2020+
major_minor_version = ".".join(
2021+
(TRITON_VERSION_MAP[FLAGS.version][7]).split(".")[:2]
2022+
)
2023+
version_matched_files = "/usr/lib64/libpython" + major_minor_version + "*"
2024+
cmake_script.cp(
2025+
version_matched_files, os.path.join(repo_install_dir, "backends", be)
2026+
)
2027+
19612028
cmake_script.cpdir(
19622029
os.path.join(repo_install_dir, "backends", be),
19632030
os.path.join(install_dir, "backends"),

0 commit comments

Comments
 (0)