Skip to content

Commit

Permalink
[Serve] Require traffic weights to sum more closely to 1. (#8476)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertnishihara committed May 18, 2020
1 parent 0fadc11 commit 14aeb30
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion python/ray/serve/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,20 @@ async def set_traffic(self, endpoint_name, traffic_policy_dictionary):
dict), "Traffic policy must be dictionary"
prob = 0
for backend, weight in traffic_policy_dictionary.items():
if weight < 0:
raise ValueError(
"Attempted to assign a weight of {} to backend '{}'. "
"Weights cannot be negative.".format(weight, backend))
prob += weight
if backend not in self.backends:
raise ValueError(
"Attempted to assign traffic to a backend '{}' that "
"is not registered.".format(backend))

# These weights will later be plugged into np.random.choice, which
# uses a tolerance of 1e-8.
assert np.isclose(
prob, 1, atol=0.02
prob, 1, atol=1e-8
), "weights must sum to 1, currently they sum to {}".format(prob)

self.traffic_policies[endpoint_name] = traffic_policy_dictionary
Expand Down

0 comments on commit 14aeb30

Please sign in to comment.