Skip to content

Commit

Permalink
add default values for resource threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
fregataa committed Oct 21, 2024
1 parent 7d8d24d commit 88b02c9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/ai/backend/manager/idle.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
List,
NamedTuple,
Optional,
Self,
Type,
TypedDict,
cast,
Expand Down Expand Up @@ -844,6 +845,15 @@ class ResourceThresholdValue(BaseModel):


class ResourceThresholds(dict[str, ResourceThresholdValue]):
@classmethod
def default_factory(cls) -> Self:
return cls(
cpu_util=ResourceThresholdValue(average=None, name=None),
mem=ResourceThresholdValue(average=None, name=None),
cuda_util=ResourceThresholdValue(average=None, name=None),
cuda_mem=ResourceThresholdValue(average=None, name=None),
)

@property
def unique_resource_name_map(self) -> Mapping[str, ResourceThresholdValue]:
ret: dict[str, ResourceThresholdValue] = {}
Expand All @@ -855,8 +865,8 @@ def unique_resource_name_map(self) -> Mapping[str, ResourceThresholdValue]:
return ret

@classmethod
def threshold_validator(cls, value: dict[str, Any]) -> ResourceThresholds:
return ResourceThresholds({k: ResourceThresholdValue(**v) for k, v in value.items()})
def threshold_validator(cls, value: dict[str, Any]) -> Self:
return cls({k: ResourceThresholdValue(**v) for k, v in value.items()})

@classmethod
def __get_pydantic_core_schema__(
Expand Down Expand Up @@ -890,7 +900,7 @@ class UtilizationConfig(BaseSchema):
resource_thresholds: Annotated[
ResourceThresholds,
Field(
default_factory=ResourceThresholds,
default_factory=ResourceThresholds.default_factory,
description="Resource thresholds used to check utilization idleness.",
),
]
Expand Down

0 comments on commit 88b02c9

Please sign in to comment.