Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion truss/base/truss_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,23 @@ class TrussConfig(custom_types.ConfigModel):
default_factory=lambda: CacheInternal([])
)
live_reload: bool = False
apply_library_patches: bool = True
spec_version: str = "2.0"

class Config:
protected_namespaces = () # Silence warnings about fields starting with `model_`.

@pydantic.model_validator(mode="before")
@classmethod
def _drop_apply_library_patches(cls, values: object) -> object:
# Backward compatibility: accept and ignore removed key with a warning
if isinstance(values, dict) and "apply_library_patches" in values:
logger.warning(
"`apply_library_patches` is removed and has no effect; please remove it from config."
)
values = dict(values)
values.pop("apply_library_patches", None)
return values

@property
def canonical_python_version(self) -> str:
return to_dotted_python_version(self.python_version)
Expand Down
4 changes: 0 additions & 4 deletions truss/base/truss_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ def python_executable_path(self) -> Optional[str]:
else None
)

@property
def apply_library_patches(self) -> bool:
return self._config.apply_library_patches

@property
def hash_ignore_patterns(self) -> List[str]:
"""By default, data directory contents are ignored when hashing,
Expand Down
2 changes: 0 additions & 2 deletions truss/contexts/local_loader/load_model_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
signature_accepts_keyword_arg,
)
from truss.contexts.truss_context import TrussContext
from truss.templates.server.common.patches import apply_patches


class LoadModelLocal(TrussContext):
Expand Down Expand Up @@ -38,7 +37,6 @@ def run(truss_dir: Path):
model_init_params["data_dir"] = truss_dir / "data"
if signature_accepts_keyword_arg(model_class_signature, "secrets"):
model_init_params["secrets"] = prepare_secrets(spec)
apply_patches(spec.apply_library_patches, spec.requirements)
model = model_class(**model_init_params)
if hasattr(model, "load"):
model.load()
Expand Down
32 changes: 0 additions & 32 deletions truss/templates/server/common/patches.py

This file was deleted.

69 changes: 0 additions & 69 deletions truss/templates/server/common/patches/whisper/patch.py

This file was deleted.

5 changes: 0 additions & 5 deletions truss/templates/server/model_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import starlette.responses
from anyio import Semaphore, to_thread
from common import errors, tracing
from common.patches import apply_patches
from common.retry import retry
from common.schema import TrussSchema
from fastapi import HTTPException, WebSocket
Expand Down Expand Up @@ -474,10 +473,6 @@ def _load_impl(self):
secrets = SecretsResolver.get_secrets(self._config)
lazy_data_resolver = LazyDataResolverV2(data_dir)

apply_patches(
self._config.get("apply_library_patches", True),
self._config["requirements"],
)

extensions = _init_extensions(
self._config, data_dir, secrets, lazy_data_resolver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
apply_library_patches: true
base_image:
docker_auth: null
image: vllm/vllm-openai:latest
Expand Down
23 changes: 10 additions & 13 deletions truss/tests/patch/test_calc_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,20 +779,17 @@ def config_op(config: TrussConfig):
)


def test_calc_config_patches_toggle_apply_library_patches(custom_model_truss_dir: Path):
def config_op(config: TrussConfig):
config.apply_library_patches = False
def test_removed_apply_library_patches_key_has_no_effect(custom_model_truss_dir: Path):
config_path = custom_model_truss_dir / "config.yaml"
config_yaml = yaml.safe_load(config_path.open())
config_yaml["apply_library_patches"] = False
with config_path.open("w") as f:
yaml.safe_dump(config_yaml, f)

patches = _apply_config_change_and_calc_patches(custom_model_truss_dir, config_op)
assert len(patches) == 1
patch = patches[0]
assert patch == Patch(
type=PatchType.CONFIG,
body=ConfigPatch(
action=Action.UPDATE,
config=yaml.safe_load((custom_model_truss_dir / "config.yaml").open()),
),
)
prev_sign = calc_truss_signature(custom_model_truss_dir)
# Rewriting config without any material changes should not produce patches
patches = calc_truss_patch(custom_model_truss_dir, prev_sign)
assert patches == []


def test_calc_config_patches_add_external_data(
Expand Down
10 changes: 10 additions & 0 deletions truss/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ def test_default_config_not_crowded_end_to_end():
assert config_yaml.strip() == yaml.dump(config.to_dict(verbose=False)).strip()


def test_apply_library_patches_is_ignored_with_warning(tmp_path, caplog):
config_path = tmp_path / "config.yaml"
yaml.safe_dump({"apply_library_patches": False}, open(config_path, "w"))
with caplog.at_level("WARNING"):
cfg = TrussConfig.from_yaml(config_path)
# Key should be dropped and not present in serialized output
dumped = cfg.to_dict(verbose=False)
assert "apply_library_patches" not in dumped


def test_null_cache_internal_key():
config_yaml_dict = {"cache_internal": None}
with tempfile.NamedTemporaryFile(mode="w", delete=False) as tmp_file:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
apply_library_patches: true
base_image: null
build:
arguments: {}
Expand Down
Loading