Skip to content

Commit 8ee9da4

Browse files
adamomainzfacebook-github-bot
authored andcommitted
removing outliers from data
Summary: tritonbench variance is extremely high. Adding a filter on the latency values we get so that we remove outliers. this is done by taking the distance between the 1st and 3rd quartile -+ 1.5x the inter quartile range as a filter. Reviewed By: FindHao Differential Revision: D70978162 fbshipit-source-id: a7d6104a504a151277ff664e2a7211b042b12ad8
1 parent 551d5be commit 8ee9da4

File tree

1 file changed

+35
-2
lines changed
  • tritonbench/components/do_bench

1 file changed

+35
-2
lines changed

tritonbench/components/do_bench/run.py

+35-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,48 @@ class Latency:
1010
times: List[float]
1111

1212
def __init__(self, times):
13-
self.times = times
13+
self.times = self._remove_outliers_iqr(times)
1414

1515
def __str__(self):
1616
"""By default, use p50"""
1717
return self.to_str()
1818

19+
def _remove_outliers_iqr(self, data):
20+
"""
21+
Removes outliers from a list of floats using the IQR method.
22+
23+
Args:
24+
data: A list of floats.
25+
26+
Returns:
27+
A new list with outliers removed.
28+
"""
29+
starting_length = len(data)
30+
if starting_length <= 3:
31+
return data
32+
if not data:
33+
return []
34+
35+
data.sort()
36+
quantiles = statistics.quantiles(data, n=100)
37+
q1 = quantiles[25]
38+
q3 = quantiles[75]
39+
iqr = q3 - q1
40+
41+
lower_bound = q1 - (1.5 * iqr)
42+
upper_bound = q3 + (1.5 * iqr)
43+
44+
filtered_data = [x for x in data if lower_bound <= x and x <= upper_bound]
45+
end_len = len(filtered_data)
46+
if end_len != starting_length:
47+
print(
48+
f"Removed {starting_length - end_len} outliers from {starting_length} samples"
49+
)
50+
return filtered_data
51+
1952
@property
2053
def p50(self):
21-
return statistics.median(self.times)
54+
return statistics.median_low(self.times)
2255

2356
def __add__(self, other):
2457
return self.p50 + other.p50 if isinstance(other, Latency) else self.p50 + other

0 commit comments

Comments
 (0)