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. |
|
MLflow logger backend. |
|
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: NotRequired[str]#
None
- name: NotRequired[str]#
None
- class nemo_rl.utils.logger.TensorboardConfig[source]#
Bases:
typing.TypedDict
- log_dir: NotRequired[str]#
None
- class nemo_rl.utils.logger.MLflowConfig[source]#
Bases:
typing.TypedDict
- experiment_name: str#
None
- run_name: str#
None
- tracking_uri: NotRequired[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
- mlflow_enabled: bool#
None
- wandb: nemo_rl.utils.logger.WandbConfig#
None
- tensorboard: nemo_rl.utils.logger.TensorboardConfig#
None
- mlflow: NotRequired[nemo_rl.utils.logger.MLflowConfig]#
None
- monitor_gpus: bool#
None
- gpu_monitoring: nemo_rl.utils.logger.GPUMonitoringConfig#
None
- num_val_samples_to_print: int#
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
- _log_diffs()[source]#
Log git diffs to wandb.
This function captures and logs two types of diffs:
Uncommitted changes (working tree diff against HEAD)
All changes (including uncommitted) against the main branch
Each diff is saved as a text file in a wandb artifact.
- _log_code()[source]#
Log code that is tracked by git to wandb.
This function gets a list of all files tracked by git in the project root and manually uploads them to the current wandb run as an artifact.
- 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_metric(
- sample: prometheus_client.samples.Sample,
- node_idx: int,
Parse a 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.MLflowLogger(
- cfg: nemo_rl.utils.logger.MLflowConfig,
- log_dir: Optional[str] = None,
Bases:
nemo_rl.utils.logger.LoggerInterface
MLflow logger backend.
Initialization
Initialize MLflow logger.
- Parameters:
cfg – MLflow configuration
log_dir – Optional log directory
- log_metrics(
- metrics: dict[str, Any],
- step: int,
- prefix: Optional[str] = '',
- step_metric: Optional[str] = None,
Log metrics to MLflow.
- 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 MLflow)
- log_hyperparams(params: Mapping[str, Any]) None [source]#
Log hyperparameters to MLflow.
- Parameters:
params – Dictionary of hyperparameters to log
- 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
mlflow_enabled
wandb
tensorboard
mlflow
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: Mapping[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[Any] | 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)
- log_plot_token_mult_prob_error(
- data: dict[str, Any],
- step: int,
- name: str,
Log a plot of log probability errors in samples.
This function logs & plots the per-token log-probabilities and errors over the sequence for the sample with the highest multiplicative probability error in the batch.
- Parameters:
log_data – Dictionary of log probability samples
step – Global step value
name – Name of the plot
- nemo_rl.utils.logger.flatten_dict(
- d: Mapping[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)