Metric#

Named metric channels the user pushes values into.

A Metric is a named channel opened inside the user’s experiment function. Values are recorded one (step, value) sample at a time:

loss = Metric("loss", dtype=float)
for step in range(n_steps):
    simulation.step()
    loss.push(step, simulation.loss())

A Metric is a write handle, not a store: the samples do not live on the metric object. Each push is routed to the Orchestrator driving the current run – found through the ambient run state tracked in krum.orchestration.orchestrator – which owns and assembles the data. This lets one channel name accumulate samples across many runs even though a fresh Metric is created on every run.

class krum.orchestration.metric.Metric(name: str, dtype: type = <class 'float'>)[source]#

Bases: object

A named channel of (step, value) samples written during a run.

The channel is identified by its name, which is unique per orchestrator and case-sensitive (loss and Loss are distinct). On each push the value is recorded together with the current run’s parameters, so that get() can return every sample tagged with the parameters that produced it.

property dtype: type#

The channel’s declared value type.

property name: str#

The channel’s name.

push(step: int, value: Any, skip_if_exists: bool = False) None[source]#

Record one sample, tagged with the current run’s parameters.

Parameters:
  • step – The step (e.g. training iteration) the value belongs to.

  • value – The recorded value. Must be an instance of the declared dtype.

  • skip_if_exists – If True, the sample is ignored when a value for the same run and step has already been recorded for this channel. Lets a partially-completed experiment be re-run without producing duplicate rows.

Raises: