Implementation:NVIDIA DALI Training Logger
| Knowledge Sources | |
|---|---|
| Domains | Vision, Training |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
Provides a hierarchical metrics logging framework with multiple aggregation levels for deep learning training experiments using dllogger.
Description
This module implements a comprehensive training metrics logging system built on top of NVIDIA's dllogger library. It features a three-level hierarchical aggregation architecture where metrics are tracked at iteration, epoch, and run levels. The core Meter class composes three aggregator objects (iteration, epoch, and run) and cascades values upward as each level resets: when an iteration resets, its aggregated value feeds into the epoch aggregator, and when an epoch resets, it feeds the run aggregator.
The module provides several aggregator implementations: AverageMeter for computing weighted averages (used for loss, throughput), MaxMeter for tracking maximum values (used for accuracy), MinMeter for tracking minimum values (used for best loss), LastMeter for recording only the most recent value (used for learning rate), and QuantileMeter for computing percentile statistics (used for latency at p95, p99, p100). Convenience factory lambdas (PERF_METER, LOSS_METER, ACC_METER, LR_METER, LAT_100, LAT_99, LAT_95) pre-configure standard meter combinations.
The Logger class manages the full lifecycle of metric tracking with methods for starting/ending iterations, epochs, and calibration runs. It integrates directly with dllogger backends for structured output. Higher-level classes TrainingMetrics and ValidationMetrics register standard training and validation metric sets respectively, providing a clean API via the log(**kwargs) method for recording values.
Usage
Use this module in the EfficientNet PyTorch training example to track and report training metrics. Initialize a Logger instance with dllogger backends, then create TrainingMetrics and ValidationMetrics wrappers. Use the epoch_generator_wrapper and iteration_generator_wrapper to automatically manage metric lifecycle around training loops.
Code Reference
Source Location
- Repository: NVIDIA_DALI
- File: docs/examples/use_cases/pytorch/efficientnet/image_classification/logger.py
- Lines: 1-495
Signature
class Meter(object):
def __init__(self, iteration_aggregator, epoch_aggregator, run_aggregator): ...
def record(self, val, n=1): ...
def get_iteration(self): ...
def get_epoch(self): ...
def get_run(self): ...
class AverageMeter(object): ...
class MaxMeter(object): ...
class MinMeter(object): ...
class LastMeter(object): ...
class QuantileMeter(object): ...
class Logger(object):
def __init__(self, print_interval, backends, start_epoch=-1, verbose=False): ...
def register_metric(self, metric_name, meter, verbosity=0, metadata={}): ...
def log_metric(self, metric_name, val, n=1): ...
def start_epoch(self): ...
def end_epoch(self): ...
def end(self): ...
class TrainingMetrics(Metrics): ...
class ValidationMetrics(Metrics): ...
Import
from image_classification.logger import Logger, TrainingMetrics, ValidationMetrics
I/O Contract
Inputs (Logger.__init__)
| Name | Type | Required | Description |
|---|---|---|---|
| print_interval | int | Yes | How often (in iterations) to log metrics to backends. |
| backends | list | Yes | List of dllogger backend instances for structured output. |
| start_epoch | int | No | Starting epoch index. Default: -1. |
| verbose | bool | No | Whether to print metric registration messages. Default: False. |
Outputs (Logger)
| Name | Type | Description |
|---|---|---|
| iteration metrics | dict | Per-iteration metric values logged via dllogger at each print_interval. |
| epoch metrics | dict | Epoch-aggregated metric values logged at end of each epoch. |
| run metrics | dict | Run-aggregated summary values logged at the end of training. |
Usage Examples
Setting up training logger
import dllogger
from image_classification.logger import Logger, TrainingMetrics, ValidationMetrics
# Initialize logger with JSON and stdout backends
backends = [
dllogger.JSONStreamBackend(verbosity=dllogger.Verbosity.DEFAULT, filename="log.json"),
dllogger.StdOutBackend(verbosity=dllogger.Verbosity.VERBOSE, step_format=format_step),
]
logger = Logger(print_interval=10, backends=backends)
# Register standard training metrics
train_metrics = TrainingMetrics(logger)
val_metrics = ValidationMetrics(logger, prefix="val", topk=5)
# Training loop with automatic metric lifecycle
for epoch in logger.epoch_generator_wrapper(range(90)):
for batch in logger.iteration_generator_wrapper(train_loader, mode="train"):
loss = train_step(batch)
train_metrics.log(loss=loss.item(), compute_ips=images_per_sec)
logger.end()