[docs]@dataclassclassConsoleLoggerCallback(Callback):""" Logs progress and a subset of metrics to the console. .. important:: This callback gets added automatically if you don't explicitly configure it. If you want to override this callback you should subclass it. """log_interval:int=1""" How often, in steps, to log progress to the console. """metrics_log_interval:Optional[int]=None""" How often, in steps, to log metrics to the console. If not set, defaults to :data:`log_interval`. """metrics:List[str]=field(default_factory=lambda:["train/CE loss","train/PPL","train/Z loss","train/load balancing loss","train/router Z loss","train/block */load imbalance","gpu_memory/*","optim/total grad norm","optim/step skipped","optim/LR*","throughput/*","checkpoint/*",])""" Metrics to log to the console. Wildcards are supported. """defpost_step(self):ifself._should_log_metrics(self.step):# Will log to console from `self.log_metrics()`.returnifself.step%self.log_interval!=0:returnlog.info(self._get_progress_marker(self.step))deflog_metrics(self,step:int,metrics:Dict[str,float]):ifnotself._should_log_metrics(step):returnprefix=self._get_progress_marker(step,include_eta=True)log.info(f"{prefix}\n"+"\n".join([f" {name}={format_float(value)}"forname,valueinmetrics.items()ifany(fnmatch(name,pat)forpatinself.metrics)]))def_get_progress_marker(self,step:int,include_eta:bool=False)->str:ifinclude_etaand(eta:=self.trainer.training_progress.time_remaining)isnotNone:eta_str=format_timedelta(eta).replace(", ","")ifself.trainer.hard_stop:eta_str=f"{eta_str}(hard stop)"returnf"[step={step}/{self.trainer.max_stepsor'???'},epoch={self.trainer.epoch},eta={eta_str}]"else:returnf"[step={step}/{self.trainer.max_stepsor'???'},epoch={self.trainer.epoch}]"def_should_log_metrics(self,step:int)->bool:metrics_log_interval=self.metrics_log_intervalorself.log_intervalifstep==1or(step>1andstep%metrics_log_interval==0):returnTrueelse:returnFalse