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, clear_on_reduce: bool = False, with_throughput: bool = False) None [source]#
Overrides the logged values under
key
withvalue
.The internal values list under
key
is cleared and reset to [value
]. Ifkey
already 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 underkey
in a list (and also return that list upon callingself.reduce()
). Note that this is only applied ifkey
does not exist inself
yet.window – An optional window size to reduce over. If not None, then the reduction operation is only applied to the most recent
window
items, and - after reduction - the internal values list underkey
is shortened to hold at mostwindow
items (the most recent ones). Must be None ifema_coeff
is provided. If None (andema_coeff
is None), reduction must not be “mean”. Note that this is only applied ifkey
does not exist inself
yet.ema_coeff – An optional EMA coefficient to use if
reduce
is “mean” and nowindow
is provided. Note that if bothwindow
andema_coeff
are provided, an error is thrown. Also, ifema_coeff
is provided,reduce
must 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 ifkey
does not exist inself
yet.clear_on_reduce – If True, all values under
key
will 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 nowindow
provided. Note that this is only applied ifkey
does not exist inself
yet.with_throughput – Whether to track a throughput estimate together with this metric. This is only supported for
reduce=sum
andclear_on_reduce=False
metrics (aka. “lifetime counts”). TheStats
object 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).