Skip to content

Commit

Permalink
Merge pull request #2086 from FedML-AI/dimitris/pydantic_conflict_res…
Browse files Browse the repository at this point in the history
…olution

Removing field validator for resolving spacy and pydantic conflict.
  • Loading branch information
alaydshah committed May 7, 2024
2 parents 69707c4 + c6cb5b0 commit 5e41f65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, field_validator, NonNegativeInt, NonNegativeFloat
from pydantic import BaseModel, NonNegativeInt, NonNegativeFloat, validator


class AutoscalingPolicy(BaseModel):
Expand Down Expand Up @@ -70,9 +70,10 @@ class EWMPolicy(AutoscalingPolicy):
ub_threshold: NonNegativeFloat # recommended value: 0.5
lb_threshold: NonNegativeFloat # recommended value: 0.5

@field_validator("metric")
def validate_option(cls, v):
assert v in ["ewm_latency", "ewm_qps"]
@validator("metric")
def metric_match(cls, v) -> str:
if v not in ["ewm_latency", "ewm_qps"]:
raise ValueError("Wrong metric name.")
return v


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ def test_validate_scaling_bounds(self):

# Validate scale up.
scale_up = autoscaler.validate_scaling_bounds(ScaleOp.UP_OUT_OP, autoscaling_policy)
self.assertEquals(scale_up, ScaleOp.UP_OUT_OP)
self.assertEqual(scale_up, ScaleOp.UP_OUT_OP)

# Validate scale down.
scale_down = autoscaler.validate_scaling_bounds(ScaleOp.DOWN_IN_OP, autoscaling_policy)
self.assertEquals(scale_down, ScaleOp.DOWN_IN_OP)
self.assertEqual(scale_down, ScaleOp.DOWN_IN_OP)

# Validate max out-of-bounds.
autoscaling_policy.current_replicas = 3
scale_oob_max = autoscaler.validate_scaling_bounds(ScaleOp.UP_OUT_OP, autoscaling_policy)
self.assertEquals(scale_oob_max, ScaleOp.NO_OP)
self.assertEqual(scale_oob_max, ScaleOp.NO_OP)

# Validate min out-of-bounds.
autoscaling_policy.current_replicas = 1
scale_oob_min = autoscaler.validate_scaling_bounds(ScaleOp.DOWN_IN_OP, autoscaling_policy)
self.assertEquals(scale_oob_min, ScaleOp.NO_OP)
self.assertEqual(scale_oob_min, ScaleOp.NO_OP)

def test_enforce_scaling_down_delay_interval(self):
self.populate_redis_with_dummy_metrics()
Expand All @@ -140,15 +140,15 @@ def test_enforce_scaling_down_delay_interval(self):

autoscaling_policy.scaledown_delay_secs = 0.0
scale_down = autoscaler.enforce_scaling_down_delay_interval(ENV_ENDPOINT_ID_1, autoscaling_policy)
self.assertEquals(scale_down, ScaleOp.DOWN_IN_OP)
self.assertEqual(scale_down, ScaleOp.DOWN_IN_OP)

autoscaling_policy.scaledown_delay_secs = 1
scale_noop = autoscaler.enforce_scaling_down_delay_interval(ENV_ENDPOINT_ID_1, autoscaling_policy)
self.assertEquals(scale_noop, ScaleOp.NO_OP)
self.assertEqual(scale_noop, ScaleOp.NO_OP)

time.sleep(2)
scale_down = autoscaler.enforce_scaling_down_delay_interval(ENV_ENDPOINT_ID_1, autoscaling_policy)
self.assertEquals(scale_down, ScaleOp.DOWN_IN_OP)
self.assertEqual(scale_down, ScaleOp.DOWN_IN_OP)
self.clear_redis()


Expand Down

0 comments on commit 5e41f65

Please sign in to comment.