Shortcuts

fbresearch_logger#

FBResearch logger and its helper handlers.

Classes

FBResearchLogger

Logs training and validation metrics for research purposes.

class ignite.handlers.fbresearch_logger.FBResearchLogger(logger, delimiter='  ', show_output=False)[source]#

Logs training and validation metrics for research purposes.

This logger is designed to attach to an Ignite Engine and log various metrics and system stats at configurable intervals, including learning rates, iteration times, and GPU memory usage.

Parameters
  • logger (Any) – The logger to use for output.

  • delimiter (str) – The delimiter to use between metrics in the log output.

  • show_output (bool) – Flag to enable logging of the output from the engine’s process function.

Examples

import logging

import torch
import torch.nn as nn
import torch.optim as optim

from ignite.engine import create_supervised_trainer, Events
from ignite.handlers.fbresearch_logger import FBResearchLogger
from ignite.utils import setup_logger

model = nn.Linear(10, 5)
opt = optim.SGD(model.parameters(), lr=0.001)
criterion = nn.CrossEntropyLoss()

data = [(torch.rand(4, 10), torch.randint(0, 5, size=(4, ))) for _ in range(100)]

trainer = create_supervised_trainer(
    model, opt, criterion, output_transform=lambda x, y, y_pred, loss: {"total_loss": loss.item()}
)

logger = setup_logger("trainer", level=logging.INFO)
logger = FBResearchLogger(logger=logger, show_output=True)
logger.attach(trainer, name="Train", every=20, optimizer=opt)

trainer.run(data, max_epochs=4)

Output:

2024-04-22 12:05:47,843 trainer INFO: Train: start epoch [1/4]
... Epoch [1/4]  [20/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.5999  Iter time: 0.0008 s  Data prep ..
... Epoch [1/4]  [40/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.9297  Iter time: 0.0008 s  Data prep ..
... Epoch [1/4]  [60/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.9985  Iter time: 0.0008 s  Data prep ..
... Epoch [1/4]  [80/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.9785  Iter time: 0.0008 s  Data prep ..
... Epoch [1/4]  [100/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.6211  Iter time: 0.0008 s  Data prep .
... Train: Epoch [1/4]  Total time: 0:00:00  (0.0008 s / it)
... Train: start epoch [2/4]
... Epoch [2/4]  [19/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.5981  Iter time: 0.0009 s  Data prep ..
... Epoch [2/4]  [39/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.9013  Iter time: 0.0008 s  Data prep ..
... Epoch [2/4]  [59/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.9811  Iter time: 0.0008 s  Data prep ..
... Epoch [2/4]  [79/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.9434  Iter time: 0.0008 s  Data prep ..
... Epoch [2/4]  [99/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.6116  Iter time: 0.0008 s  Data prep ..
... Train: Epoch [2/4]  Total time: 0:00:00  (0.0009 s / it)
... Train: start epoch [3/4]
... Epoch [3/4]  [18/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.5972  Iter time: 0.0008 s  Data prep ..
... Epoch [3/4]  [38/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.8753  Iter time: 0.0008 s  Data prep ..
... Epoch [3/4]  [58/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.9657  Iter time: 0.0009 s  Data prep ..
... Epoch [3/4]  [78/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.9112  Iter time: 0.0008 s  Data prep ..
... Epoch [3/4]  [98/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.6035  Iter time: 0.0008 s  Data prep ..
... Train: Epoch [3/4]  Total time: 0:00:00  (0.0009 s / it)
... Train: start epoch [4/4]
... Epoch [4/4]  [17/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.5969  Iter time: 0.0008 s  Data prep ..
... Epoch [4/4]  [37/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.8516  Iter time: 0.0008 s  Data prep ..
... Epoch [4/4]  [57/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.9521  Iter time: 0.0008 s  Data prep ..
... Epoch [4/4]  [77/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.8816  Iter time: 0.0008 s  Data prep ..
... Epoch [4/4]  [97/100]:  ETA: 0:00:00  lr: 0.00100  total_loss: 1.5966  Iter time: 0.0009 s  Data prep ..
... Train: Epoch [4/4]  Total time: 0:00:00  (0.0009 s / it)
... Train: run completed  Total time: 0:00:00
attach(engine, name, every=1, output_transform=None, state_attributes=None, optimizer=None)[source]#

Attaches all the logging handlers to the given engine.

Parameters
  • engine (Engine) – The engine to attach the logging handlers to.

  • name (str) – The name of the engine (e.g., “Train”, “Validate”) to include in log messages.

  • every (int) – Frequency of iterations to log information. Logs are generated every ‘every’ iterations.

  • output_transform (Optional[Callable]) – A function to select the value to log.

  • state_attributes (Optional[List[str]]) – A list of attributes to log.

  • optimizer (Optional[Optimizer]) – The optimizer used during training to log current learning rates.

Return type

None

log_completed(engine, name)[source]#

Logs the completion of a run.

Parameters
  • engine (Engine) – The engine object representing the training/validation loop.

  • name (str) – The name of the run.

Return type

None

log_epoch_completed(engine, name)[source]#

Logs the completion of an epoch.

Parameters
  • engine (Engine) – The engine object that triggered the event.

  • name (str) – The name of the event.

Returns

None

Return type

None

log_epoch_started(engine, name)[source]#

Logs the start of an epoch.

Parameters
  • engine (Engine) – The engine object.

  • name (str) – The name of the epoch.

Return type

None

log_every(engine, optimizer=None)[source]#

Logs the training progress at regular intervals.

Parameters
  • engine (Engine) – The training engine.

  • optimizer (Optional[Optimizer]) – The optimizer used for training. Defaults to None.

Return type

None