code: def _write_logs(
      self,
      trainer: pl.Trainer,
      pl_module: pl.LightningModule,
      type_path: str,
      save_generations=True,
  ) -> None:
      logger.info(
          f"***** {type_path} results at step {trainer.global_step:05d} *****"
      )
      metrics = trainer.callback_metrics
      trainer.logger.log_metrics(
          {
              k: v
              for k, v in metrics.items()
              if k not in ["log", "progress_bar", "preds"]
          }
      )
      # Log results
      od = Path(pl_module.hparams.output_dir)
      if type_path == "test":
          results_file = od / "test_results.txt"
          generations_file = od / "test_generations.txt"
      else:
          # this never gets hit. I prefer not to save intermediate generations, and results are in metrics.json
          # If people want this it will be easy enough to add back.
          results_file = (
              od / f"{type_path}_results/{trainer.global_step:05d}.txt"
          )
          generations_file = (
              od
              / f"{type_path}_generations/{trainer.global_step:05d}.txt"
          )
          results_file.parent.mkdir(exist_ok=True)
          generations_file.parent.mkdir(exist_ok=True)
      with open(results_file, "a+") as writer:
          for key in sorted(metrics):
              if key in ["log", "progress_bar", "preds"]:
                  continue
              val = metrics[key]
              if isinstance(val, torch.Tensor):
                  val = val.item()
              msg = f"{key}: {val:.6f}\n"
              writer.write(msg)
  
      if not save_generations:
          return
  
      if "preds" in metrics:
          content = "\n".join(metrics["preds"])
          generations_file.open("w+").write(content)
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/examples/research_projects/rag-end2end-retriever/callbacks_rag.py
imports: import logging
  from pathlib import Path
  import numpy
  import pytorch_lightning
  import torch
  from pytorch_lightning.callbacks import EarlyStopping, ModelCheckpoint
  from pytorch_lightning.utilities import rank_zero_only
  from utils_rag import save_json
label_desc: Use image node_id 2 for calling the Seq2SeqLoggingCallback obj's underlying member method code with example usage: obj._write_logs(trainer, pl_module, type_path, save_generations) without return types