nvalchemi.hooks.collect_scalars#

nvalchemi.hooks.collect_scalars(ctx, stage, state=None, *, custom_scalars=None, include_losses=True, include_optimizer_lrs=True, include_dynamics=False, include_progress=False)[source]#

Collect scalar values from a hook context.

Parameters:
  • ctx (HookContext) – Workflow hook context.

  • stage (Enum) – Hook stage being reported.

  • state (ReportingState | None, optional) – Shared reporting state used for event count and elapsed time metadata.

  • custom_scalars (Mapping[str, ScalarCallback] | None, optional) – Additional scalar callbacks. Each callback receives (ctx, stage) and may return either a scalar value or a nested mapping of scalar values.

  • include_losses (bool, default True) – When True, extract ctx.loss and ctx.losses values.

  • include_optimizer_lrs (bool, default True) – When True, extract learning rates from optimizer parameter groups.

  • include_dynamics (bool, default False) – When True, extract default dynamics observables from the current batch and dynamics context.

  • include_progress (bool, default False) – When True, extract workflow progress, throughput, and ETA scalars from context counters and workflow metadata when available.

Returns:

Snapshot containing flat scalar keys and hook metadata.

Return type:

ScalarSnapshot

Raises:
  • TypeError – If a custom scalar or loss value has an unsupported type.

  • ValueError – If a value expected to be scalar contains multiple elements.