nemo_rl.utils.logger
#
Module Contents#
Classes#
Abstract base class for logger backends. |
|
Tensorboard logger backend. |
|
Weights & Biases logger backend. |
|
Monitor GPU utilization across a Ray cluster and log metrics to a parent logger. |
|
Main logger class that delegates to multiple backend loggers. |
Functions#
Flatten a nested dictionary. |
|
Configure rich logging for more visually appealing log output. |
|
Visualization for message logs and rewards using a more visual approach with emoji indicators and horizontal layout. |
|
Create a new experiment directory with an incremented ID. |
Data#
API#
- nemo_rl.utils.logger._rich_logging_configured#
False
- class nemo_rl.utils.logger.WandbConfig[source]#
Bases:
typing.TypedDict
- project: str#
None
- name: str#
None
- class nemo_rl.utils.logger.GPUMonitoringConfig[source]#
Bases:
typing.TypedDict
- collection_interval: int | float#
None
- flush_interval: int | float#
None
- class nemo_rl.utils.logger.LoggerConfig[source]#
Bases:
typing.TypedDict
- log_dir: str#
None
- wandb_enabled: bool#
None
- tensorboard_enabled: bool#
None
- wandb: nemo_rl.utils.logger.WandbConfig#
None
- tensorboard: nemo_rl.utils.logger.TensorboardConfig#
None
- monitor_gpus: bool#
None
- gpu_monitoring: nemo_rl.utils.logger.GPUMonitoringConfig#
None
- class nemo_rl.utils.logger.LoggerInterface[source]#
Bases:
abc.ABC
Abstract base class for logger backends.
- class nemo_rl.utils.logger.TensorboardLogger(
- cfg: nemo_rl.utils.logger.TensorboardConfig,
- log_dir: Optional[str] = None,
Bases:
nemo_rl.utils.logger.LoggerInterface
Tensorboard logger backend.
Initialization
- log_metrics(
- metrics: Dict[str, Any],
- step: int,
- prefix: Optional[str] = '',
- step_metric: Optional[str] = None,
Log metrics to Tensorboard.
- Parameters:
metrics β Dict of metrics to log
step β Global step value
prefix β Optional prefix for metric names
step_metric β Optional step metric name (ignored in TensorBoard)
- class nemo_rl.utils.logger.WandbLogger(
- cfg: nemo_rl.utils.logger.WandbConfig,
- log_dir: Optional[str] = None,
Bases:
nemo_rl.utils.logger.LoggerInterface
Weights & Biases logger backend.
Initialization
- define_metric(
- name: str,
- step_metric: Optional[str] = None,
Define a metric with custom step metric.
- Parameters:
name β Name of the metric or pattern (e.g. βray/*β)
step_metric β Optional name of the step metric to use
- log_metrics(
- metrics: Dict[str, Any],
- step: int,
- prefix: Optional[str] = '',
- step_metric: Optional[str] = None,
Log metrics to wandb.
- Parameters:
metrics β Dict of metrics to log
step β Global step value
prefix β Optional prefix for metric names
step_metric β Optional name of a field in metrics to use as step instead of the provided step value
- class nemo_rl.utils.logger.GpuMetricSnapshot[source]#
Bases:
typing.TypedDict
- step: int#
None
- metrics: Dict[str, Any]#
None
- class nemo_rl.utils.logger.RayGpuMonitorLogger(
- collection_interval: int | float,
- flush_interval: int | float,
- metric_prefix: str,
- step_metric: str,
- parent_logger: Optional[nemo_rl.utils.logger.Logger] = None,
Monitor GPU utilization across a Ray cluster and log metrics to a parent logger.
Initialization
Initialize the GPU monitor.
- Parameters:
collection_interval β Interval in seconds to collect GPU metrics
flush_interval β Interval in seconds to flush metrics to parent logger
step_metric β Name of the field to use as the step metric
parent_logger β Logger to receive the collected metrics
- _parse_gpu_metric(
- sample: prometheus_client.samples.Sample,
- node_idx: int,
Parse a GPU metric sample into a standardized format.
- Parameters:
sample β Prometheus metric sample
node_idx β Index of the node
- Returns:
Dictionary with metric name and value
- _parse_gpu_sku(
- sample: prometheus_client.samples.Sample,
- node_idx: int,
Parse a GPU metric sample into a standardized format.
- Parameters:
sample β Prometheus metric sample
node_idx β Index of the node
- Returns:
Dictionary with metric name and value
- _collect_gpu_sku() Dict[str, str] [source]#
Collect GPU SKU from all Ray nodes.
Note: This is an internal API and users are not expected to call this.
- Returns:
Dictionary of SKU types on all Ray nodes
- _collect_metrics() Dict[str, Any] [source]#
Collect GPU metrics from all Ray nodes.
- Returns:
Dictionary of collected metrics
- _collect(
- metrics: bool = False,
- sku: bool = False,
Collect GPU metrics from all Ray nodes.
- Returns:
Dictionary of collected metrics
- class nemo_rl.utils.logger.Logger(cfg: nemo_rl.utils.logger.LoggerConfig)[source]#
Bases:
nemo_rl.utils.logger.LoggerInterface
Main logger class that delegates to multiple backend loggers.
Initialization
Initialize the logger.
- Parameters:
cfg β
Config dict with the following keys:
wandb_enabled
tensorboard_enabled
wandb
tensorboard
monitor_gpus
gpu_collection_interval
gpu_flush_interval
- log_metrics(
- metrics: Dict[str, Any],
- step: int,
- prefix: Optional[str] = '',
- step_metric: Optional[str] = None,
Log metrics to all enabled backends.
- Parameters:
metrics β Dict of metrics to log
step β Global step value
prefix β Optional prefix for metric names
step_metric β Optional name of a field in metrics to use as step instead of the provided step value (currently only needed for wandb)
- log_hyperparams(params: Dict[str, Any]) None [source]#
Log hyperparameters to all enabled backends.
- Parameters:
params β Dict of hyperparameters to log
- log_batched_dict_as_jsonl(
- to_log: nemo_rl.distributed.batched_data_dict.BatchedDataDict | Dict[str, Any],
- filename: str,
Log a list of dictionaries to a JSONL file.
- Parameters:
to_log β BatchedDataDict to log
filename β Filename to log to (within the log directory)
- nemo_rl.utils.logger.flatten_dict(
- d: Dict[str, Any],
- sep: str = '.',
Flatten a nested dictionary.
Handles nested dictionaries and lists by creating keys with separators. For lists, the index is used as part of the key.
- Parameters:
d β Dictionary to flatten
sep β Separator to use between nested keys
- Returns:
Flattened dictionary with compound keys
.. rubric:: Examples
>>> from nemo_rl.utils.logger import flatten_dict >>> flatten_dict({"a": 1, "b": {"c": 2}}) {'a': 1, 'b.c': 2} >>> flatten_dict({"a": [1, 2], "b": {"c": [3, 4]}}) {'a.0': 1, 'a.1': 2, 'b.c.0': 3, 'b.c.1': 4} >>> flatten_dict({"a": [{"b": 1}, {"c": 2}]}) {'a.0.b': 1, 'a.1.c': 2}
- nemo_rl.utils.logger.configure_rich_logging(
- level: str = 'INFO',
- show_time: bool = True,
- show_path: bool = True,
Configure rich logging for more visually appealing log output.
- Parameters:
level β The logging level to use
show_time β Whether to show timestamps in logs
show_path β Whether to show file paths in logs
- nemo_rl.utils.logger.print_message_log_samples(
- message_logs: List[nemo_rl.data.interfaces.LLMMessageLogType],
- rewards: List[float],
- num_samples: int = 5,
- step: int = 0,
Visualization for message logs and rewards using a more visual approach with emoji indicators and horizontal layout.
- Parameters:
message_logs β List of message logs to sample from
rewards β List of rewards corresponding to each message log
num_samples β Number of samples to display (default: 5)
step β Current training step (for display purposes)