TensorboardMetricsWriter
TensorboardMetricsWriter(log_dir: str | PathLike, purge_step: int | None = None) -> NoneMetrics writer that writes scalar values directly to TensorBoard via a SummaryWriter.
Uses torch's SummaryWriter rather than tensorboardX: tensorboardX hands every event to its writer thread through a multiprocessing.Queue, so each scalar pays a pickle plus an OS pipe round trip and producers block when the queue fills, which profiling showed stalling the training loop. torch's writer queues events in process.
Initialize the TensorboardMetricsWriter.
Parameters:
log_dir(str | PathLike) – The directory where TensorBoard logs will be written.purge_step(int | None) – Optional step from which to purge existing data (used when resuming).
Methods
close
close() -> NoneClose the underlying SummaryWriter.
flush
flush() -> NoneFlush buffered data to TensorBoard.
write
write(tag: str, value: float, step: int) -> NoneWrite a scalar metric value to TensorBoard.
Parameters:
tag(str) – The TensorBoard tag.value(float) – The scalar value.step(int) – The global step.
write_histogram
write_histogram(tag: str, bin_edges: Sequence[float], bin_counts: Sequence[float], step: int) -> NoneWrite a pre-binned histogram to TensorBoard.
TensorBoard's frontend redraws every histogram into a fixed 30 display bins across its range, spreading each bin's height over the display bins it covers in proportion to overlap. A 7-bin histogram therefore showed 23.3 on hover for a true height of 100. Scaling every height by 30 / bins first makes each display bin land on the true value: for fewer than 30 bins the spread cancels the scale, and for more the display bins that merge several real bins show their mean. Display bins straddling a boundary show a blend, which is the only cost. Histograms written this way should be read as "height = value", not as counts.
Parameters:
tag(str) – The TensorBoard tag.bin_edges(Sequence[float]) – Then + 1bin boundaries, ascending.bin_counts(Sequence[float]) – Thenbin heights.step(int) – The global step.
write_params
write_params(params: dict[str, Any]) -> NoneWrite configuration parameters to TensorBoard.
Note: TensorBoard SummaryWriter.add_hparams exists but has complex side effects (it creates a new event file), so this is a no-op to satisfy the contract.
Parameters:
params(dict[str, Any]) – A dictionary of parameter names and values.