Skip to content

Use a run

The Run object provides methods to inspect and control an execution.

Persist and refresh

save

Save the entity into the backend.

Returns:

Type Description
ContextEntity

Entity saved.

export

Export object as a YAML file in the context folder.

Returns:

Type Description
str

Exported filepath.

refresh

Refresh object from backend.

Returns:

Type Description
ContextEntity

Entity refreshed.

Control execution

run

Run run.

Returns:

Type Description
Run

Run object.

wait

Wait for run to finish.

Parameters:

Name Type Description Default
log_info bool

If True, log information.

True

Returns:

Type Description
Run

Run object.

stop

Stop run.

resume

Resume run.

Inspect logs and metrics

logs

Get run logs. If no logs are present, an empty list is returned. In case of local execution, logs are printed to console.

Returns:

Type Description
list[Log] | list[str]

List of run logs. If as_entity is True, returns a list of Log objects, otherwise returns a list of log texts.

log_metric

Log metric into entity status. A metric is named by a key and value (single number or list of numbers). The metric by default is put in a list or appended to an existing list. If single_value is True, the value will be a single number.

Parameters:

Name Type Description Default
key str

Key of the metric.

required
value MetricType

Value of the metric.

required
overwrite bool

If True, overwrite existing metric.

False
single_value bool

If True, value is a single value.

False

Examples:

Log a new value in a list

>>> entity.log_metric("loss", 0.002)

Append a new value in a list

>>> entity.log_metric("loss", 0.0019)

Log a list of values and append them to existing metric:

>>> entity.log_metric(
...     "loss",
...     [
...         0.0018,
...         0.0015,
...     ],
... )

Log a single value (not represented as list):

>>> entity.log_metric(
...     "accuracy",
...     0.9,
...     single_value=True,
... )

Log a list of values and overwrite existing metric:

>>> entity.log_metric(
...     "accuracy",
...     [0.8, 0.9],
...     overwrite=True,
... )
log_metrics

Log metrics into entity status. If a metric is a list, it will be logged as a list. Otherwise, it will be logged as a single value.

Parameters:

Name Type Description Default
metrics dict[str, MetricType]

Dict of metrics to log.

required
overwrite bool

If True, overwrite existing metrics.

False

Examples:

Log multiple metrics at once

>>> entity.log_metrics(
...     {
...         "loss": 0.002,
...         "accuracy": 0.95,
...     }
... )

Log metrics with lists and single values

>>> entity.log_metrics(
...     {
...         "loss": [
...             0.1,
...             0.05,
...         ],
...         "epoch": 10,
...     }
... )

Append to existing metrics (default behavior)

>>> entity.log_metrics(
...     {
...         "loss": 0.001,
...         "accuracy": 0.96,
...     }
... )  # Appends to existing

Overwrite existing metrics

>>> entity.log_metrics(
...     {
...         "loss": 0.0005,
...         "accuracy": 0.98,
...     },
...     overwrite=True,
... )
See Also

log_metric

Kind-specific methods

Run kinds are provided by runtimes. See the runtime documentation for the corresponding runtime behavior.