Skip to content

TensorboardMetricsWriter ​

python
TensorboardMetricsWriter(log_dir: str | PathLike, purge_step: int | None = None) -> None

Metrics 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).

Source

Methods ​

close ​

python
close() -> None

Close the underlying SummaryWriter.

Source

flush ​

python
flush() -> None

Flush buffered data to TensorBoard.

Source

write ​

python
write(tag: str, value: float, step: int) -> None

Write a scalar metric value to TensorBoard.

Parameters:

  • tag (str) – The TensorBoard tag.
  • value (float) – The scalar value.
  • step (int) – The global step.

Source

write_histogram ​

python
write_histogram(tag: str, bin_edges: Sequence[float], bin_counts: Sequence[float], step: int) -> None

Write 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]) – The n + 1 bin boundaries, ascending.
  • bin_counts (Sequence[float]) – The n bin heights.
  • step (int) – The global step.

Source

write_params ​

python
write_params(params: dict[str, Any]) -> None

Write 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.

Source