MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / trim_mean

Function trim_mean

deepspeed/utils/timer.py:296–316  ·  view source on GitHub ↗

Compute the trimmed mean of a list of numbers. Args: data (list): List of numbers. trim_percent (float): Percentage of data to trim. Returns: float: Trimmed mean.

(data, trim_percent)

Source from the content-addressed store, hash-verified

294
295
296def trim_mean(data, trim_percent):
297 """Compute the trimmed mean of a list of numbers.
298
299 Args:
300 data (list): List of numbers.
301 trim_percent (float): Percentage of data to trim.
302
303 Returns:
304 float: Trimmed mean.
305 """
306 assert 0.0 <= trim_percent <= 1.0
307 n = len(data)
308 # Account for edge case of empty list
309 if len(data) == 0:
310 return 0
311 # sorted(), not data.sort(): CommsLogger passes its stored latency/algbw/busbw
312 # lists straight in, and sorting them in place reorders each independently and
313 # destroys the index correspondence between them.
314 data = sorted(data)
315 k = int(round(n * (trim_percent)))
316 return mean(data[k:n - k])

Callers 4

get_operation_summaryMethod · 0.90
log_allMethod · 0.90
meanMethod · 0.85

Calls

no outgoing calls