ray.rllib.utils.metrics.metrics_logger.MetricsLogger.set_value#
- MetricsLogger.set_value(key: str | Tuple[str, ...], value: Any, *, reduce: str | None = 'mean', window: int | float | None = None, ema_coeff: float | None = None, percentiles: List[int] | bool = False, clear_on_reduce: bool = False, with_throughput: bool = False, throughput_ema_coeff: float = 0.05, reduce_per_index_on_aggregate: bool = False) None[source]#
Overrides the logged values under
keywithvalue.The internal values list under
keyis cleared and reset to [value]. Ifkeyalready exists, this method will NOT alter the reduce settings. Otherwise, it will apply the provided reduce settings (reduce,window,ema_coeff, andclear_on_reduce).- Parameters:
key – The key to override.
value – The new value to set the internal values list to (will be set to a list containing a single item
value).reduce – The reduction method to apply, once
self.reduce()is called. If None, will collect all logged values underkeyin a list (and also return that list upon callingself.reduce()). Note that this is only applied ifkeydoes not exist inselfyet.window – An optional window size to reduce over. If not None, then the reduction operation is only applied to the most recent
windowitems, and - after reduction - the internal values list underkeyis shortened to hold at mostwindowitems (the most recent ones). Must be None ifema_coeffis provided. If None (andema_coeffis None), reduction must not be “mean”. Note that this is only applied ifkeydoes not exist inselfyet.ema_coeff – An optional EMA coefficient to use if
reduceis “mean” and nowindowis provided. Note that if bothwindowandema_coeffare provided, an error is thrown. Also, ifema_coeffis provided,reducemust be “mean”. The reduction formula for EMA is: EMA(t1) = (1.0 - ema_coeff) * EMA(t0) + ema_coeff * new_value Note that this is only applied ifkeydoes not exist inselfyet.percentiles – If reduce is
None, we can compute the percentiles of the values list given bypercentiles. Defaults to [0, 0.5, 0.75, 0.9, 0.95, 0.99, 1] if set to True. When using percentiles, a window must be provided. This window should be chosen carefully. RLlib computes exact percentiles and the computational complexity is O(m*n*log(n/m)) where n is the window size and m is the number of parallel metrics loggers involved (for example, m EnvRunners).clear_on_reduce – If True, all values under
keywill be emptied afterself.reduce()is called. Setting this to True is useful for cases, in which the internal values list would otherwise grow indefinitely, for example if reduce is None and there is nowindowprovided. Note that this is only applied ifkeydoes not exist inselfyet.with_throughput – Whether to track a throughput estimate together with this metric. This is only supported for
reduce=sumandclear_on_reduce=Falsemetrics (aka. “lifetime counts”). TheStatsobject under the logged key then keeps track of the time passed between two consecutive calls toreduce()and update its throughput estimate. The current throughput estimate of a key can be obtained through: peeked_value, throuthput_per_sec = <MetricsLogger>.peek([key], throughput=True).throughput_ema_coeff – The EMA coefficient to use for throughput tracking. Only used if with_throughput=True. Defaults to 0.05.
reduce_per_index_on_aggregate – If True, when merging Stats objects, we reduce incoming values per index such that the new value at index
nwill be the reduced value of all incoming values at indexn. If False, when reducingnStats, the firstnmerged values will be the reduced value of all incoming values at index0, the nextnmerged values will be the reduced values of all incoming values at index1, etc. Note that this is only applied ifkeydoes not exist inselfyet.