Skip to content

Commit bee837a

Browse files
authored
Upgrade base images for py3.9 through py3.13 (#1704)
1 parent 3637328 commit bee837a

File tree

8 files changed

+61
-36
lines changed

8 files changed

+61
-36
lines changed

.github/actions/setup-python/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ runs:
4545
id: cache
4646
with:
4747
path: .venv
48-
key: venv-${{ runner.os }}-${{ env.version }}-${{ hashFiles('**/poetry.lock') }}
48+
key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
4949

5050
- name: Ensure cache is healthy
5151
if: steps.cache.outputs.cache-hit == 'true'

docker/base_images/base_image.Dockerfile.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{% if use_gpu %}
2-
FROM nvidia/cuda:12.2.2-base-ubuntu20.04
2+
FROM nvidia/cuda:12.2.2-base-ubuntu22.04
33
ENV CUDNN_VERSION="8.9.5.29"
44
ENV CUDA="12.2"
55
ENV LD_LIBRARY_PATH="/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH"
66

7-
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub && \
7+
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub && \
88
apt-get update && apt-get install -y --no-install-recommends \
99
ca-certificates \
1010
cuda-command-line-tools-12-2 \

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "truss"
3-
version = "0.9.102"
3+
version = "0.9.103rc001"
44
description = "A seamless bridge from model development to model delivery"
55
license = "MIT"
66
readme = "README.md"

truss/contexts/image_builder/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# This needs to be updated whenever we want to update
77
# base images on a merge. Updating this version will cause
88
# base images to be pushed with this tag.
9-
TRUSS_BASE_IMAGE_VERSION_TAG = "v0.9.0"
9+
TRUSS_BASE_IMAGE_VERSION_TAG = "v0.9.103"
1010

1111

1212
def file_is_empty(path: Path, ignore_hash_style_comments: bool = True) -> bool:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{%- if requires_live_reload %}
2+
FROM python:{{ control_python_version }}-slim as control-server-venv
3+
4+
RUN echo "Creating venv for py{{ control_python_version }}";
5+
RUN python -m pip install --upgrade pip
6+
RUN python -m venv --copies /control/.env
7+
RUN echo "Created venv for py{{ control_python_version }}";
8+
{%- endif %} {#- endif requires_live_reload #}

truss/templates/server.Dockerfile.jinja

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
{%- include "cache.Dockerfile.jinja" %}
33
{%- endif %} {#- endif model_cache_v1 #}
44

5+
{%- set requires_live_reload = config.live_reload and not config.docker_server %}
6+
7+
{%- if requires_live_reload %}
8+
{% include "control_venv.Dockerfile.jinja" %}
9+
{%- endif %} {#- endif requires_live_reload #}
10+
511
{% extends "base.Dockerfile.jinja" %}
612

13+
714
{% block base_image_patch %}
815
{# If user base image is supplied in config, apply build commands from truss base image #}
916
{% if config.base_image %}
@@ -27,14 +34,14 @@ COPY ./{{ base_server_requirements_filename }} {{ base_server_requirements_filen
2734
RUN pip install -r {{ base_server_requirements_filename }} --no-cache-dir && rm -rf /root/.cache/pip
2835
{%- endif %} {#- endif not config.docker_server #}
2936

30-
{%- if config.live_reload and not config.docker_server %}
37+
{%- if requires_live_reload %}
3138
{# Create symlink for inference server IF a user base image is supplied and live_reload is enabled. #}
3239
{# This links the base images primary python executable path to /usr/local/bin/python. #}
3340
{# This is specific to the user-provided base image scenario. #}
3441
RUN readlink {{ config.base_image.python_executable_path }} &>/dev/null \
3542
&& echo "WARNING: Overwriting existing link at /usr/local/bin/python"
3643
RUN ln -sf {{ config.base_image.python_executable_path }} /usr/local/bin/python
37-
{%- endif %} {#- endif config.live_reload and not config.docker_server (for symlink) #}
44+
{%- endif %} {#- endif requires_live_reload #}
3845
{% endif %} {#- endif config.base_image #}
3946

4047
{% endblock %} {#- endblock base_image_patch #}
@@ -91,34 +98,24 @@ COPY ./truss /app/truss
9198
{%- endif %} {#- endif use_local_src #}
9299

93100
COPY ./config.yaml /app/config.yaml
94-
{%- if config.live_reload and not config.docker_server %}
101+
{%- if requires_live_reload %}
95102
COPY ./control /control
96-
# Step 1: Ensure a usable python{{ control_python_version }} is available
97-
RUN if python{{ control_python_version }} -c 'import venv; venv.EnvBuilder(with_pip=True).create("/tmp/__probe_env")' > /dev/null 2>&1; then \
98-
echo "Using system python{{ control_python_version }}"; \
99-
python{{ control_python_version }} -m pip install --upgrade pip virtualenv && \
100-
python{{ control_python_version }} -m virtualenv /control/.env; \
101-
else \
102-
echo "Installing Miniforge-based python{{ control_python_version }}..."; \
103-
curl -fsSL -o miniforge.sh https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh && \
104-
bash miniforge.sh -b -p /opt/conda-control && \
105-
rm miniforge.sh && \
106-
/opt/conda-control/bin/conda create -y -p /opt/conda-control/envs/py{{ control_python_version }} python={{ control_python_version }} && \
107-
/opt/conda-control/envs/py{{ control_python_version }}/bin/pip install --upgrade pip virtualenv && \
108-
/opt/conda-control/bin/conda clean -afy && \
109-
rm -rf /opt/conda-control/pkgs && \
110-
/opt/conda-control/envs/py{{ control_python_version }}/bin/python -m virtualenv /control/.env; \
111-
fi
112-
113-
# Step 2: Install requirements into the freshly created venv
103+
104+
# NB(nikhil): Copy the virtual env, and system dependencies for the
105+
# python version specific to the control server. We need to run ldconfig
106+
# so dynamic linking works.
107+
COPY --from=control-server-venv /usr/local/lib/ /usr/local/lib/
108+
COPY --from=control-server-venv /control/.env /control/.env
109+
RUN ldconfig
110+
114111
RUN /control/.env/bin/pip install -r /control/requirements.txt
115-
{%- endif %} {#- endif config.live_reload and not config.docker_server (for control server setup) #}
112+
{%- endif %} {#- endif requires_live_reload #}
113+
116114
{%- if model_dir_exists %}
117115
COPY ./{{ config.model_module_dir }} /app/model
118116
{%- endif %} {#- endif model_dir_exists #}
119117
{% endblock %} {#- endblock app_copy #}
120118

121-
122119
{% block run %}
123120
{%- if config.docker_server %}
124121
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
@@ -136,7 +133,7 @@ COPY supervisord.conf {{ supervisor_config_path }}
136133
ENV SUPERVISOR_SERVER_URL="{{ supervisor_server_url }}"
137134
ENV SERVER_START_CMD="supervisord -c {{ supervisor_config_path }}"
138135
ENTRYPOINT ["supervisord", "-c", "{{ supervisor_config_path }}"]
139-
{%- elif config.live_reload %} {#- elif config.live_reload #}
136+
{%- elif requires_live_reload %} {#- elif requires_live_reload #}
140137
ENV HASH_TRUSS="{{ truss_hash }}"
141138
ENV CONTROL_SERVER_PORT="8080"
142139
ENV INFERENCE_SERVER_PORT="8090"

truss/templates/server/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ joblib>=1.2.0
99
loguru>=0.7.2
1010
msgpack-numpy==0.4.8
1111
msgpack==1.1.0 # Numpy/msgpack versions are finniky (1.0.2 breaks), double check when changing.
12-
numpy>=1.23.5
12+
numpy>=1.23.5,<2.0 # 2.x versions of numpy are incompatible with many libraries we depend on.
1313
opentelemetry-api>=1.25.0
1414
opentelemetry-exporter-otlp>=1.25.0
1515
opentelemetry-sdk>=1.25.0

truss/tests/test_truss_handle.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
from python_on_whales.exceptions import DockerException
99
from tenacity import RetryError
1010

11+
from truss.base.constants import SUPPORTED_PYTHON_VERSIONS
1112
from truss.base.custom_types import Example
1213
from truss.base.errors import ContainerIsDownError, ContainerNotFoundError
1314
from truss.base.truss_config import map_local_to_supported_python_version
15+
from truss.contexts.image_builder.util import TRUSS_BASE_IMAGE_VERSION_TAG
1416
from truss.local.local_config_handler import LocalConfigHandler
1517
from truss.templates.control.control.helpers.custom_types import (
1618
Action,
@@ -100,15 +102,33 @@ def test_build_docker_image(custom_model_truss_dir_with_pre_and_post):
100102
assert image.repo_tags[0] == tag
101103

102104

105+
def _generate_base_image_variations(
106+
base_template="baseten/truss-server-base:{}-{}",
107+
base_py3_path="/usr/local/bin/python3",
108+
gpu_py3_path="/usr/bin/python3",
109+
python_versions=SUPPORTED_PYTHON_VERSIONS,
110+
version_tag=TRUSS_BASE_IMAGE_VERSION_TAG,
111+
):
112+
variations = []
113+
for version in python_versions:
114+
variations.append(
115+
(base_template.format(version, version_tag), base_py3_path, False)
116+
)
117+
118+
# NB(nikhil): Python 3.8 base images currently don't have support for development models
119+
# on GPUs.
120+
fail = False if version != "3.8" else True
121+
variations.append(
122+
(base_template.format(f"{version}-gpu", version_tag), gpu_py3_path, fail)
123+
)
124+
return variations
125+
126+
103127
@pytest.mark.integration
104128
@pytest.mark.parametrize(
105129
"base_image, path, expected_fail",
106-
[
107-
("baseten/truss-server-base:3.9-v0.9.0", "/usr/local/bin/python3", False),
108-
("baseten/truss-server-base:3.10-v0.9.0", "/usr/local/bin/python3", False),
109-
("baseten/truss-server-base:3.11-v0.9.0", "/usr/local/bin/python3", False),
110-
("baseten/truss-server-base:3.12-v0.9.0", "/usr/local/bin/python3", False),
111-
("baseten/truss-server-base:3.13-v0.9.0", "/usr/local/bin/python3", False),
130+
_generate_base_image_variations()
131+
+ [
112132
("python:3.8", "/usr/local/bin/python3", False),
113133
("python:3.10", "/usr/local/bin/python3", False),
114134
("python:3.11", "/usr/local/bin/python3", False),

0 commit comments

Comments
 (0)