Skip to content

Commit e7485f3

Browse files
basetenbotsquidarthVarun Shenoy
authored
Release 0.7.7 (#665)
* Always upgrade when pip installing during patch (#659) * Always upgrade when pip installing. * Bump pyproject. * Private `hf_cache` fix (#663) * add fix * bump pyproj * update cache to read secret from correct path * clean up pyproject.toml * add test to check for mount * template out hf token file name * Bump version to 0.7.7 --------- Co-authored-by: Sidharth Shanker <sid.shanker@baseten.co> Co-authored-by: Varun Shenoy <vnshenoy@stanford.edu>
1 parent ac16c0c commit e7485f3

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "truss"
3-
version = "0.7.6"
3+
version = "0.7.7"
44
description = "A seamless bridge from model development to model delivery"
55
license = "MIT"
66
readme = "README.md"

truss/contexts/image_builder/serving_image_builder.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
CONFIG_FILE = "config.yaml"
4646

4747
HF_ACCESS_TOKEN_SECRET_NAME = "hf_access_token"
48+
HF_ACCESS_TOKEN_FILE_NAME = "hf-access-token"
4849

4950

5051
def create_triton_build_dir(config: TrussConfig, build_dir: Path, truss_dir: Path):
@@ -234,7 +235,9 @@ def update_config_and_gather_files(
234235
return get_files_to_cache(config, truss_dir, build_dir)
235236

236237

237-
def create_tgi_build_dir(config: TrussConfig, build_dir: Path, truss_dir: Path):
238+
def create_tgi_build_dir(
239+
config: TrussConfig, build_dir: Path, truss_dir: Path, use_hf_secret: bool
240+
):
238241
copy_tree_path(truss_dir, build_dir)
239242

240243
if not build_dir.exists():
@@ -258,6 +261,8 @@ def create_tgi_build_dir(config: TrussConfig, build_dir: Path, truss_dir: Path):
258261
data_dir_exists=data_dir.exists(),
259262
credentials_exists=credentials_file.exists(),
260263
cached_files=cached_file_paths,
264+
use_hf_secret=use_hf_secret,
265+
hf_access_token_file_name=HF_ACCESS_TOKEN_FILE_NAME,
261266
)
262267
dockerfile_filepath = build_dir / "Dockerfile"
263268
dockerfile_filepath.write_text(dockerfile_content)
@@ -279,7 +284,9 @@ def create_tgi_build_dir(config: TrussConfig, build_dir: Path, truss_dir: Path):
279284
supervisord_filepath.write_text(supervisord_contents)
280285

281286

282-
def create_vllm_build_dir(config: TrussConfig, build_dir: Path, truss_dir: Path):
287+
def create_vllm_build_dir(
288+
config: TrussConfig, build_dir: Path, truss_dir: Path, use_hf_secret
289+
):
283290
copy_tree_path(truss_dir, build_dir)
284291

285292
server_endpoint_config = {
@@ -312,6 +319,8 @@ def create_vllm_build_dir(config: TrussConfig, build_dir: Path, truss_dir: Path)
312319
data_dir_exists=data_dir.exists(),
313320
credentials_exists=credentials_file.exists(),
314321
cached_files=cached_file_paths,
322+
use_hf_secret=use_hf_secret,
323+
hf_access_token_file_name=HF_ACCESS_TOKEN_FILE_NAME,
315324
)
316325
dockerfile_filepath = build_dir / "Dockerfile"
317326
dockerfile_filepath.write_text(dockerfile_content)
@@ -361,10 +370,10 @@ def prepare_image_build_dir(
361370
build_dir = build_truss_target_directory(model_framework_name)
362371

363372
if config.build.model_server is ModelServer.TGI:
364-
create_tgi_build_dir(config, build_dir, truss_dir)
373+
create_tgi_build_dir(config, build_dir, truss_dir, use_hf_secret)
365374
return
366375
elif config.build.model_server is ModelServer.VLLM:
367-
create_vllm_build_dir(config, build_dir, truss_dir)
376+
create_vllm_build_dir(config, build_dir, truss_dir, use_hf_secret)
368377
return
369378
elif config.build.model_server is ModelServer.TRITON:
370379
create_triton_build_dir(config, build_dir, truss_dir)
@@ -481,6 +490,7 @@ def _render_dockerfile(
481490
build_dir / REQUIREMENTS_TXT_FILENAME
482491
)
483492

493+
hf_access_token = config.secrets.get(HF_ACCESS_TOKEN_SECRET_NAME)
484494
dockerfile_contents = dockerfile_template.render(
485495
should_install_server_requirements=should_install_server_requirements,
486496
base_image_name_and_tag=base_image_name_and_tag,
@@ -497,6 +507,8 @@ def _render_dockerfile(
497507
cached_files=cached_files,
498508
credentials_exists=credentials_file.exists(),
499509
hf_cache=len(config.hf_cache.models) > 0,
510+
hf_access_token=hf_access_token,
511+
hf_access_token_file_name=HF_ACCESS_TOKEN_FILE_NAME,
500512
)
501513
docker_file_path = build_dir / MODEL_DOCKERFILE_NAME
502514
docker_file_path.write_text(dockerfile_contents)

truss/templates/cache.Dockerfile.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ RUN pip install -r /app/cache_requirements.txt --no-cache-dir && rm -rf /root/.c
1717
COPY ./cache_warmer.py /cache_warmer.py
1818
{% for repo, hf_dir in models.items() %}
1919
{% for file in hf_dir.files %}
20-
RUN python3 /cache_warmer.py {{file}} {{repo}} {% if hf_dir.revision != None %}{{hf_dir.revision}}{% endif %}
20+
{{ "RUN --mount=type=secret,id=" + hf_access_token_file_name + ",dst=/etc/secrets/" + hf_access_token_file_name if use_hf_secret else "RUN" }} python3 /cache_warmer.py {{file}} {{repo}} {% if hf_dir.revision != None %}{{hf_dir.revision}}{% endif %}
2121
{% endfor %}
2222
{% endfor %}

truss/templates/control/control/helpers/truss_patch/model_container_patch_applier.py

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def _apply_python_requirement_patch(
106106
self._pip_path,
107107
"install",
108108
python_requirement_patch.requirement,
109+
"--upgrade",
109110
],
110111
check=True,
111112
)

truss/tests/contexts/image_builder/test_serving_image_builder.py

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77
from truss.contexts.image_builder.serving_image_builder import (
8+
HF_ACCESS_TOKEN_FILE_NAME,
89
ServingImageBuilderContext,
910
get_files_to_cache,
1011
update_model_key,
@@ -243,3 +244,20 @@ def test_truss_server_caching_truss():
243244
)
244245
time.sleep(15)
245246
assert "Downloading model.safetensors:" not in container.logs()
247+
248+
249+
def test_hf_cache_dockerfile():
250+
truss_root = Path(__file__).parent.parent.parent.parent.parent.resolve() / "truss"
251+
truss_dir = truss_root / "test_data" / "test_truss_server_caching_truss"
252+
tr = TrussHandle(truss_dir)
253+
254+
builder_context = ServingImageBuilderContext
255+
image_builder = builder_context.run(tr.spec.truss_dir)
256+
257+
secret_mount = f"RUN --mount=type=secret,id={HF_ACCESS_TOKEN_FILE_NAME}"
258+
with TemporaryDirectory() as tmp_dir:
259+
tmp_path = Path(tmp_dir)
260+
image_builder.prepare_image_build_dir(tmp_path, use_hf_secret=True)
261+
with open(tmp_path / "Dockerfile", "r") as f:
262+
gen_docker_file = f.read()
263+
assert secret_mount in gen_docker_file

0 commit comments

Comments
 (0)