Unverified Commit e4601811 authored by hhzhang16's avatar hhzhang16 Committed by GitHub
Browse files

feat: use model_fields_set to distinguish ttft/itl default usage (#6814)


Signed-off-by: default avatarHannah Zhang <hannahz@nvidia.com>
parent 8055b7dd
......@@ -117,9 +117,14 @@ class SLASpec(BaseModel):
@model_validator(mode="after")
def _validate_sla_options(self) -> "SLASpec":
"""Ensure at most one SLA mode is active."""
has_ttft_itl = self.ttft is not None and self.itl is not None
has_e2e = self.e2eLatency is not None
has_opt = self.optimizationType is not None
ttft_itl_touched = (
"ttft" in self.model_fields_set or "itl" in self.model_fields_set
)
has_ttft_itl = (self.ttft is not None and self.itl is not None) and (
ttft_itl_touched or (not has_e2e and not has_opt)
)
options_count = sum([has_ttft_itl, has_e2e, has_opt])
if options_count > 1:
raise ValueError(
......
......@@ -67,9 +67,12 @@ _STRUCT_EXTRAS: dict = {
@model_validator(mode="after")
def _validate_sla_options(self) -> "SLASpec":
\"\"\"Ensure at most one SLA mode is active.\"\"\"
has_ttft_itl = self.ttft is not None and self.itl is not None
has_e2e = self.e2eLatency is not None
has_opt = self.optimizationType is not None
ttft_itl_touched = "ttft" in self.model_fields_set or "itl" in self.model_fields_set
has_ttft_itl = (self.ttft is not None and self.itl is not None) and (
ttft_itl_touched or (not has_e2e and not has_opt)
)
options_count = sum([has_ttft_itl, has_e2e, has_opt])
if options_count > 1:
raise ValueError(
......
......@@ -187,6 +187,13 @@ def test_sla_defaults_and_validation():
# optimizationType mode: OK (null out ttft/itl)
SLASpec(ttft=None, itl=None, optimizationType=OptimizationType.Throughput)
# optimizationType mode: OK without explicitly nulling defaults (TC-2.5 / TC-2.6)
SLASpec(optimizationType=OptimizationType.Throughput)
SLASpec(optimizationType=OptimizationType.Latency)
# e2eLatency mode: OK without explicitly nulling defaults
SLASpec(e2eLatency=500.0)
# mixing modes should raise
try:
SLASpec(ttft=100.0, itl=10.0, e2eLatency=500.0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment