@@ -111,6 +111,15 @@ def __init__(self, config, learning_rate_schedule):
111111 if self .config .managed_mldiagnostics :
112112 ManagedMLDiagnostics (config ) # Initialize the MLRun instance.
113113
114+ if self .config .enable_wandb and jax .process_index () == 0 :
115+ import wandb # pylint: disable=import-outside-toplevel # pytype: disable=import-error # lazy import: wandb is an optional dependency
116+
117+ wandb .init (
118+ project = config .wandb_project_name ,
119+ name = config .wandb_run_name ,
120+ resume = "allow" ,
121+ ) # Initialize wandb logger.
122+
114123 def reset_eval_metrics (self ):
115124 """Resets the cumulative metrics dictionary for a new evaluation run."""
116125 self .cumulative_eval_metrics = {"scalar" : defaultdict (float )}
@@ -133,6 +142,9 @@ def write_metrics(self, metrics, step, metric_type="train"):
133142 if self .config .managed_mldiagnostics :
134143 self .write_metrics_to_managed_mldiagnostics (metrics , step )
135144
145+ if self .config .enable_wandb and jax .process_index () == 0 :
146+ self .write_metrics_to_wandb (metrics , step )
147+
136148 if metric_type == "train" :
137149 self ._maybe_abort_after_write_metrics (metrics )
138150
@@ -333,6 +345,18 @@ def write_metrics_to_managed_mldiagnostics(self, metrics, step):
333345 mapped_metric_name = _METRICS_TO_MANAGED .get (metric_name , metric_name )
334346 mldiag .metrics .record (mapped_metric_name , value , step = int (step ))
335347
348+ def write_metrics_to_wandb (self , metrics , step ):
349+ """Write metrics to weights and biases (wandb)."""
350+ import wandb # pylint: disable=import-outside-toplevel # pytype: disable=import-error # lazy import: wandb is an optional dependency
351+
352+ flat_metrics = {}
353+ for key , val in metrics .get ("scalar" , {}).items ():
354+ flat_metrics [key ] = float (val )
355+ for key , val in metrics .get ("scalars" , {}).items ():
356+ for subkey , subval in val .items ():
357+ flat_metrics [f"{ key } /{ subkey } " ] = float (subval )
358+ wandb .log (flat_metrics , step = step )
359+
336360 def write_setup_info_to_tensorboard (self , params ):
337361 """Writes setup information like train config params, num model params, and XLA flags to TensorBoard."""
338362 num_model_parameters = max_utils .calculate_num_params_from_pytree (params )
0 commit comments