truss 0.11.8rc5__py3-none-any.whl → 0.11.8rc7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of truss might be problematic. Click here for more details.
- truss/templates/control/control/application.py +31 -50
- truss/templates/control/control/endpoints.py +1 -5
- {truss-0.11.8rc5.dist-info → truss-0.11.8rc7.dist-info}/METADATA +1 -1
- {truss-0.11.8rc5.dist-info → truss-0.11.8rc7.dist-info}/RECORD +7 -7
- {truss-0.11.8rc5.dist-info → truss-0.11.8rc7.dist-info}/WHEEL +0 -0
- {truss-0.11.8rc5.dist-info → truss-0.11.8rc7.dist-info}/entry_points.txt +0 -0
- {truss-0.11.8rc5.dist-info → truss-0.11.8rc7.dist-info}/licenses/LICENSE +0 -0
|
@@ -4,11 +4,11 @@ import logging.config
|
|
|
4
4
|
import re
|
|
5
5
|
import traceback
|
|
6
6
|
from pathlib import Path
|
|
7
|
-
from typing import Dict
|
|
7
|
+
from typing import Awaitable, Callable, Dict
|
|
8
8
|
|
|
9
9
|
import httpx
|
|
10
10
|
from endpoints import control_app
|
|
11
|
-
from fastapi import FastAPI, Request
|
|
11
|
+
from fastapi import FastAPI, Request, Response
|
|
12
12
|
from fastapi.responses import JSONResponse
|
|
13
13
|
from helpers.errors import ModelLoadFailed, PatchApplicatonError
|
|
14
14
|
from helpers.inference_server_controller import InferenceServerController
|
|
@@ -22,52 +22,40 @@ from starlette.middleware.base import BaseHTTPMiddleware
|
|
|
22
22
|
SANITIZED_EXCEPTION_FRAMES = 2
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
class SanitizedException(Exception):
|
|
26
|
-
def __init__(self, original_error: Exception, num_frames: int):
|
|
27
|
-
self.original_error = original_error
|
|
28
|
-
tb_lines = traceback.format_tb(original_error.__traceback__)
|
|
29
|
-
if tb_lines and num_frames > 0:
|
|
30
|
-
# NB(nikhil): Take the last num_frames, join them, and strip extra whitespace
|
|
31
|
-
selected_frames = tb_lines[-num_frames:]
|
|
32
|
-
self.concise_msg = "".join(selected_frames).rstrip()
|
|
33
|
-
else:
|
|
34
|
-
self.concise_msg = f"{type(original_error).__name__}: {original_error}"
|
|
35
|
-
|
|
36
|
-
def __str__(self):
|
|
37
|
-
return self.concise_msg
|
|
38
|
-
|
|
39
|
-
def __repr__(self):
|
|
40
|
-
return self.concise_msg
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
# NB(nikhil): SanitizedExceptionMiddleware runs on every request and cleans up the verbose stack traces
|
|
44
|
-
# that are very noisy for users.
|
|
45
25
|
class SanitizedExceptionMiddleware(BaseHTTPMiddleware):
|
|
46
|
-
def __init__(self, app, num_frames: int):
|
|
26
|
+
def __init__(self, app, num_frames: int = SANITIZED_EXCEPTION_FRAMES):
|
|
47
27
|
super().__init__(app)
|
|
48
28
|
self.num_frames = num_frames
|
|
49
29
|
|
|
50
|
-
async def dispatch(
|
|
30
|
+
async def dispatch(
|
|
31
|
+
self, request: Request, call_next: Callable[[Request], Awaitable[Response]]
|
|
32
|
+
) -> Response:
|
|
51
33
|
try:
|
|
52
34
|
return await call_next(request)
|
|
53
|
-
except Exception as
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
35
|
+
except Exception as exc:
|
|
36
|
+
sanitized_traceback = self._create_sanitized_traceback(exc)
|
|
37
|
+
if hasattr(request.app.state, "logger"):
|
|
38
|
+
request.app.state.logger.error(f"Error:\n{sanitized_traceback}")
|
|
39
|
+
|
|
40
|
+
if isinstance(exc, ModelLoadFailed):
|
|
41
|
+
return JSONResponse({"error": str(exc)}, status_code=503)
|
|
42
|
+
elif isinstance(exc, PatchApplicatonError):
|
|
43
|
+
error_type = _camel_to_snake_case(type(exc).__name__)
|
|
44
|
+
return JSONResponse(
|
|
45
|
+
{"error": {"type": error_type, "msg": str(exc)}}, status_code=400
|
|
46
|
+
)
|
|
47
|
+
else:
|
|
48
|
+
return JSONResponse(
|
|
49
|
+
{"error": {"type": "unknown", "msg": str(exc)}}, status_code=500
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def _create_sanitized_traceback(self, error: Exception) -> str:
|
|
53
|
+
tb_lines = traceback.format_tb(error.__traceback__)
|
|
54
|
+
if tb_lines and self.num_frames > 0:
|
|
55
|
+
selected_frames = tb_lines[-self.num_frames :]
|
|
56
|
+
return "".join(selected_frames).rstrip()
|
|
57
|
+
else:
|
|
58
|
+
return f"{type(error).__name__}: {error}"
|
|
71
59
|
|
|
72
60
|
|
|
73
61
|
def create_app(base_config: Dict):
|
|
@@ -118,17 +106,10 @@ def create_app(base_config: Dict):
|
|
|
118
106
|
app = FastAPI(
|
|
119
107
|
title="Truss Live Reload Server",
|
|
120
108
|
on_startup=[start_background_inference_startup],
|
|
121
|
-
exception_handlers={
|
|
122
|
-
PatchApplicatonError: handle_patch_error,
|
|
123
|
-
ModelLoadFailed: handle_model_load_failed,
|
|
124
|
-
Exception: generic_error_handler,
|
|
125
|
-
},
|
|
126
109
|
)
|
|
127
110
|
app.state = app_state
|
|
128
111
|
app.include_router(control_app)
|
|
129
|
-
app.add_middleware(
|
|
130
|
-
SanitizedExceptionMiddleware, num_frames=SANITIZED_EXCEPTION_FRAMES
|
|
131
|
-
)
|
|
112
|
+
app.add_middleware(SanitizedExceptionMiddleware)
|
|
132
113
|
|
|
133
114
|
@app.on_event("shutdown")
|
|
134
115
|
def on_shutdown():
|
|
@@ -5,6 +5,7 @@ from typing import Any, Callable, Dict, Optional, Protocol
|
|
|
5
5
|
import httpx
|
|
6
6
|
from fastapi import APIRouter, WebSocket
|
|
7
7
|
from fastapi.responses import JSONResponse, StreamingResponse
|
|
8
|
+
from helpers.errors import ModelLoadFailed, ModelNotReady
|
|
8
9
|
from httpx_ws import AsyncWebSocketSession, WebSocketDisconnect, aconnect_ws
|
|
9
10
|
from httpx_ws import _exceptions as httpx_ws_exceptions
|
|
10
11
|
from starlette.requests import ClientDisconnect, Request
|
|
@@ -13,11 +14,6 @@ from starlette.websockets import WebSocketDisconnect as StartletteWebSocketDisco
|
|
|
13
14
|
from tenacity import RetryCallState, Retrying, retry_if_exception_type, wait_fixed
|
|
14
15
|
from wsproto.events import BytesMessage, TextMessage
|
|
15
16
|
|
|
16
|
-
from truss.templates.control.control.helpers.errors import (
|
|
17
|
-
ModelLoadFailed,
|
|
18
|
-
ModelNotReady,
|
|
19
|
-
)
|
|
20
|
-
|
|
21
17
|
INFERENCE_SERVER_START_WAIT_SECS = 60
|
|
22
18
|
BASE_RETRY_EXCEPTIONS = (
|
|
23
19
|
retry_if_exception_type(httpx.ConnectError)
|
|
@@ -73,8 +73,8 @@ truss/templates/copy_cache_files.Dockerfile.jinja,sha256=Os5zFdYLZ_AfCRGq4RcpVTO
|
|
|
73
73
|
truss/templates/docker_server_requirements.txt,sha256=PyhOPKAmKW1N2vLvTfLMwsEtuGpoRrbWuNo7tT6v2Mc,18
|
|
74
74
|
truss/templates/server.Dockerfile.jinja,sha256=CUYnF_hgxPGq2re7__0UPWlwzOHMoFkxp6NVKi3U16s,7071
|
|
75
75
|
truss/templates/control/requirements.txt,sha256=nqqNmlTwFeV8sV4fqwItwzzd_egADBP_e-cEopXBJ4k,358
|
|
76
|
-
truss/templates/control/control/application.py,sha256=
|
|
77
|
-
truss/templates/control/control/endpoints.py,sha256=
|
|
76
|
+
truss/templates/control/control/application.py,sha256=XfA5udraulB0z6s4J_S05w0y1TJGcoMuC3jJOjbPVu4,4839
|
|
77
|
+
truss/templates/control/control/endpoints.py,sha256=KzqsLVNJE6r6TCPW8D5FMCtsfHadTwR15A3z_viGxmM,11782
|
|
78
78
|
truss/templates/control/control/server.py,sha256=R4Y219i1dcz0kkksN8obLoX-YXWGo9iW1igindyG50c,3128
|
|
79
79
|
truss/templates/control/control/helpers/context_managers.py,sha256=W6dyFgLBhPa5meqrOb3w_phMtKfaJI-GhwUfpiycDc8,413
|
|
80
80
|
truss/templates/control/control/helpers/custom_types.py,sha256=n_lTudtLTpy4oPV3aDdJ4X2rh3KCV5btYO9UnTeUouQ,5471
|
|
@@ -368,8 +368,8 @@ truss_train/deployment.py,sha256=lWWANSuzBWu2M4oK4qD7n-oVR1JKdmw2Pn5BJQHg-Ck,307
|
|
|
368
368
|
truss_train/loader.py,sha256=0o66EjBaHc2YY4syxxHVR4ordJWs13lNXnKjKq2wq0U,1630
|
|
369
369
|
truss_train/public_api.py,sha256=9N_NstiUlmBuLUwH_fNG_1x7OhGCytZLNvqKXBlStrM,1220
|
|
370
370
|
truss_train/restore_from_checkpoint.py,sha256=8hdPm-WSgkt74HDPjvCjZMBpvA9MwtoYsxVjOoa7BaM,1176
|
|
371
|
-
truss-0.11.
|
|
372
|
-
truss-0.11.
|
|
373
|
-
truss-0.11.
|
|
374
|
-
truss-0.11.
|
|
375
|
-
truss-0.11.
|
|
371
|
+
truss-0.11.8rc7.dist-info/METADATA,sha256=37bkH41Vl6H2ftd6R4aJZWnxqanKAupqM4uOgFNmYlA,6680
|
|
372
|
+
truss-0.11.8rc7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
373
|
+
truss-0.11.8rc7.dist-info/entry_points.txt,sha256=-MwKfHHQHQ6j0HqIgvxrz3CehCmczDLTD-OsRHnjjuU,130
|
|
374
|
+
truss-0.11.8rc7.dist-info/licenses/LICENSE,sha256=FTqGzu85i-uw1Gi8E_o0oD60bH9yQ_XIGtZbA1QUYiw,1064
|
|
375
|
+
truss-0.11.8rc7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|