ResourceUtilizationLogger#
- class ResourceUtilizationLogger(log_frequency=10, prefix='resources', log_per_gpu=False, log_cpu=True, log_system_memory=True, per_process=True)[source]#
Bases:
HookBaseLog GPU and CPU/RAM utilization to the writer over the course of training.
In
before_trainit probes optional dependencies (psutilfor CPU/RAM,pynvmlfor system-wide GPU stats), warning/falling back totorch.cudawhen unavailable. Runs inafter_stepeverylog_frequencysteps on rank 0: collects GPU memory (and, system-wide, utilization %) plus CPU and system/process memory metrics and writes them to the writer under{prefix}/....after_trainshuts down NVML if it was initialized. Registered asResourceUtilizationLogger.- Parameters:
log_frequency (int) – Log metrics every this many steps. Defaults to
10.prefix (str) – Namespace prefix for the logged keys. Defaults to
"resources".log_per_gpu (bool) – In system-wide mode, log metrics for every visible GPU instead of just the local one. Defaults to
False.log_cpu (bool) – Log CPU utilization metrics. Defaults to
True.log_system_memory (bool) – Log RAM usage metrics. Defaults to
True.per_process (bool) – If
True, report only this process’s CPU/RAM andtorch.cudaGPU memory (recommended on shared nodes); ifFalse, report system-wide metrics (usingpynvmlfor GPU when available). Defaults toTrue.
Note
Logs on rank 0 only and no-ops when
trainer.writeris absent/None.per_process=Trueignoreslog_per_gpu/pynvmland usestorch.cudamemory counters for this process.Example
Add to
cfg.hooks; everylog_frequencysteps (rank 0) it writes GPU/CPU/RAM utilization to the writer:hooks = [dict(type="ResourceUtilizationLogger", log_frequency=50)] # → every 50 steps writes "resources/gpu_memory_allocated_gb", # "resources/gpu_memory_reserved_gb", "resources/process_cpu_percent", # "resources/process_rss_gb", … to the writer (per-process by default)