Skip to content

Commit daac073

Browse files
committed
Minor updates for pydantic objects
1 parent 41e3895 commit daac073

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/guidellm/backend/objects.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def preferred_output_tokens(
141141
return self.response_output_tokens or self.request_output_tokens
142142

143143

144+
@SchedulerMessagingPydanticRegistry.register()
144145
@MeasuredRequestTimings.register("generation_request_timings")
145146
class GenerationRequestTimings(MeasuredRequestTimings):
146147
"""Timing model for tracking generation request lifecycle events."""
@@ -154,9 +155,3 @@ class GenerationRequestTimings(MeasuredRequestTimings):
154155
default=None,
155156
description="Unix timestamp when the last generation iteration completed.",
156157
)
157-
158-
159-
# Rebuild ScheduledRequestInfo to recognize MeasuredRequestTimings schema change
160-
ScheduledRequestInfo.model_rebuild(force=True)
161-
162-
SchedulerMessagingPydanticRegistry.register_decorator(GenerationRequestTimings)

src/guidellm/utils/pydantic_utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def reload_parent_schemas(cls):
7878
are Pydantic models and triggers schema rebuilding on each to ensure
7979
that any changes in child models are reflected in parent schemas.
8080
"""
81-
potential_parents: set[BaseModel] = {BaseModel}
82-
stack: list[BaseModel] = [BaseModel]
81+
potential_parents: set[type[BaseModel]] = {BaseModel}
82+
stack: list[type[BaseModel]] = [BaseModel]
8383

8484
while stack:
8585
current = stack.pop()
@@ -108,13 +108,17 @@ def _reload_schemas_depending_on(cls, target: type[BaseModel], types: set[type])
108108
and any(
109109
cls._uses_type(target, field_info.annotation)
110110
for field_info in candidate.model_fields.values()
111+
if field_info.annotation is not None
111112
)
112113
):
113-
before = candidate.model_json_schema()
114+
try:
115+
before = candidate.model_json_schema()
116+
except Exception: # noqa: BLE001
117+
before = None
114118
candidate.model_rebuild(force=True)
115-
after = candidate.model_json_schema()
116-
if before != after:
117-
changed = True
119+
if before is not None:
120+
after = candidate.model_json_schema()
121+
changed |= before != after
118122

119123
@classmethod
120124
def _uses_type(cls, target: type, candidate: type) -> bool:

0 commit comments

Comments
 (0)