log_on_epoch

health_ml.utils.log_on_epoch(module, name=None, value=None, metrics=None, reduce_fx=<built-in method mean of type object>, sync_dist=None, sync_dist_op='mean')[source]

Write a dictionary with metrics and/or an individual metric as a name/value pair to the loggers of the given module. Metrics are always logged upon epoch completion. The metrics in question first synchronized across GPUs if DDP with >1 node is used, using the sync_dist_op (default: mean). Afterwards, they are aggregated across all steps via the reduce_fx (default: mean). Metrics that are fed in as plain numbers rather than tensors (for example, plain Python integers) are converted to tensors before logging, to enable synchronization across GPUs if needed.

Parameters
  • name (Optional[str]) – The name of the metric to log.

  • value (Optional[Any]) – The actual value of the metric to log.

  • metrics (Optional[Mapping[str, Any]]) – A dictionary with metrics to log.

  • module (LightningModule) – The PyTorch Lightning module where the metrics should be logged.

  • sync_dist (Optional[bool]) – If not None, use this value for the sync_dist argument to module.log. If None, set it automatically depending on the use of DDP. Set this to False if you want to log metrics that are only available on Rank 0 of a DDP job.

  • reduce_fx (Callable) – The reduce function to apply to the per-step values, after synchronizing the tensors across GPUs. Default: torch.mean

  • sync_dist_op (Any) – The reduce operation to use when synchronizing the tensors across GPUs. This must be a value recognized by sync_ddp: ‘sum’, ‘mean’, ‘avg’

Return type

None